Refine search
public int nextInt(final int interval) { int next; do { next = mRandom.nextInt(interval); } while (next == mPrevious && interval > 1 && !mPreviousNumbers.contains(Integer.valueOf(next))); mPrevious = next; mHistoryOfNumbers.add(mPrevious); mPreviousNumbers.add(mPrevious); cleanUpHistory(); return next; }
public int nextInt(final int interval) { int next; do { next = mRandom.nextInt(interval); } while (next == mPrevious && interval > 1 && !mPreviousNumbers.contains(Integer.valueOf(next))); mPrevious = next; mHistoryOfNumbers.add(mPrevious); mPreviousNumbers.add(mPrevious); cleanUpHistory(); return next; }
public synchronized Collection<String> getSafe() { final long now = timer.nanoTime(); if(publicClone == null || now > groupDelayTimeout) { if (groupDelays.isEmpty()) { publicClone = new ArrayList<>(internalSet); groupDelayTimeout = Long.MAX_VALUE; } else { TreeSet<String> tmpClone = new TreeSet<>(internalSet); Iterator<Map.Entry<String, Long>> itr = groupDelays.entrySet().iterator(); while(itr.hasNext()) { Map.Entry<String, Long> entry = itr.next(); if (entry.getValue() > now) { if (!tmpClone.contains(entry.getKey())) { tmpClone.add(entry.getKey()); } } else { itr.remove(); } } publicClone = new ArrayList<>(tmpClone); groupDelayTimeout = calculateNextDelayForGroups(); } } return publicClone; } public Long getNextDelayForGroups() {
@Override public TagsArrayAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent,int viewType) { View v = LayoutInflater.from(parent.getContext()) .inflate(R.layout.tags_item_list_dialog, parent, false); ViewHolder vh = new ViewHolder(v.findViewById(R.id.tags_dialog_tag_item)); vh.mTagItemCheckedTextView.setOnClickListener(view -> { CheckedTextView ctv = (CheckedTextView) view; ctv.toggle(); String tag = ctv.getText().toString(); if (ctv.isChecked() && !mCurrentTags.contains(tag)) { mCurrentTags.add(tag); } else if (!ctv.isChecked() && mCurrentTags.contains(tag)) { mCurrentTags.remove(tag); } }); return vh; }
protected void reduce( ImmutableBytesWritable row, java.lang.Iterable<KeyValue> kvs, org.apache.hadoop.mapreduce.Reducer<ImmutableBytesWritable, KeyValue, ImmutableBytesWritable, KeyValue>.Context context) throws java.io.IOException, InterruptedException { TreeSet<KeyValue> map = new TreeSet<>(KeyValue.COMPARATOR); TreeSet<byte[]> qualifierSet = new TreeSet<>(Bytes.BYTES_COMPARATOR); for (KeyValue kv : kvs) { byte[] qualifier = CellUtil.cloneQualifier(kv); if (qualifierSet.contains(qualifier)) { throw new IllegalStateException("there is duplicate key:" + row); } qualifierSet.add(qualifier); try { map.add(kv.clone()); } catch (CloneNotSupportedException e) { throw new java.io.IOException(e); } } context.setStatus("Read " + map.getClass()); int index = 0; for (KeyValue kv : map) { context.write(row, kv); if (++index % 100 == 0) context.setStatus("Wrote " + index); } } }
/** * Parses the rules contained in the property file * * @param props */ protected void loadRules(Properties props) { TreeSet<ServiceAccessRule> result = new TreeSet<ServiceAccessRule>(); for (Map.Entry<Object, Object> entry : props.entrySet()) { String ruleKey = (String) entry.getKey(); String ruleValue = (String) entry.getValue(); ServiceAccessRule rule = parseServiceAccessRule(ruleKey, ruleValue); if (rule != null) { if (result.contains(rule)) LOGGER.warning( "Rule " + ruleKey + "." + ruleValue + " overwrites another rule on the same path"); result.add(rule); } } // make sure to add the "all access alloed" rule if the set if empty if (result.size() == 0) { result.add(new ServiceAccessRule(new ServiceAccessRule())); } rules = result; }
DataAccessRule rule = parseDataAccessRule(ruleKey, ruleValue); if (rule != null) { if (result.contains(rule)) LOGGER.warning( "Rule " + ruleValue + " overwrites another rule on the same path"); result.add(rule); result.add(new DataAccessRule(DataAccessRule.READ_ALL)); result.add(new DataAccessRule(DataAccessRule.WRITE_ALL));
public void validateNonce(ConsumerDetails consumerDetails, long timestamp, String nonce) { if (System.currentTimeMillis() / 1000 - timestamp > getValidityWindowSeconds()) { throw new CredentialsExpiredException("Expired timestamp."); } NonceEntry entry = new NonceEntry(consumerDetails.getConsumerKey(), timestamp, nonce); synchronized (NONCES) { if (NONCES.contains(entry)) { throw new NonceAlreadyUsedException("Nonce already used: " + nonce); } else { NONCES.add(entry); } cleanupNonces(); } }
public void addTag(String tag) { if (!TextUtils.isEmpty(tag)) { String feedbackText = ""; if (!mAllTags.contains(tag)) { mAllTags.add(tag); if (mNoTagsTextView.getVisibility() == View.VISIBLE) { mNoTagsTextView.setVisibility(View.GONE); } mTagsArrayAdapter.mTagsList.add(tag); mTagsArrayAdapter.sortData(); feedbackText = getString(R.string.tag_editor_add_feedback, tag, mPositiveText); } else { feedbackText = getString(R.string.tag_editor_add_feedback_existing, tag); } if (!mCurrentTags.contains(tag)) { mCurrentTags.add(tag); } mTagsArrayAdapter.notifyDataSetChanged(); // Show a snackbar to let the user know the tag was added successfully UIUtils.showSnackbar(getActivity(), feedbackText, false, -1, null, mDialog.getView().findViewById(R.id.tags_dialog_snackbar), null); } }
@Test public void uniqueNamesGenerated() { PlannerBenchmarkConfig config = new PlannerBenchmarkConfig(); SolverBenchmarkConfig sbc1 = new SolverBenchmarkConfig(); SolverBenchmarkConfig sbc2 = new SolverBenchmarkConfig(); SolverBenchmarkConfig sbc3 = new SolverBenchmarkConfig(); sbc3.setName("Config_1"); List<SolverBenchmarkConfig> configs = Arrays.asList(sbc1, sbc2, sbc3); config.setSolverBenchmarkConfigList(configs); config.generateSolverBenchmarkConfigNames(); assertEquals("Config_1", sbc3.getName()); TreeSet<String> names = new TreeSet<>(); for (SolverBenchmarkConfig sc : configs) { names.add(sc.getName()); } for (int i = 0; i < configs.size(); i++) { assertTrue(names.contains("Config_" + i)); } }
public static Map<String,KeywordExecutable> checkDuplicates( final Iterable<? extends KeywordExecutable> services) { TreeSet<String> blacklist = new TreeSet<>(); TreeMap<String,KeywordExecutable> results = new TreeMap<>(); for (KeywordExecutable service : services) { String keyword = service.keyword(); if (blacklist.contains(keyword)) { // subsequent times a duplicate is found, just warn and exclude it warnDuplicate(service); } else if (results.containsKey(keyword)) { // the first time a duplicate is found, blacklist it and warn blacklist.add(keyword); warnDuplicate(results.remove(keyword)); warnDuplicate(service); } else { // first observance of this keyword, so just add it to the list results.put(service.keyword(), service); } } return Collections.unmodifiableSortedMap(results); }