java.util.TreeSet.contains()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中java.util.TreeSet.contains()方法的一些代码示例,展示了TreeSet.contains()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TreeSet.contains()方法的具体详情如下:
包路径:java.util.TreeSet
类名称:TreeSet
方法名:contains

TreeSet.contains介绍

[英]Searches this TreeSet for the specified object.
[中]搜索此树集以查找指定的对象。

代码示例

代码示例来源:origin: naman14/Timber

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;
}

代码示例来源:origin: Sable/soot

for (SwitchNode sn : switchNodeList) {
 body.addAll(sn.get_Body());
 if (sn.get_IndexSet().contains(defaultStr)) {
  sn.get_IndexSet().clear();
  sn.get_IndexSet().add(defaultStr);

代码示例来源:origin: ankidroid/Anki-Android

} else {
  for (String tag : mTagsArrayAdapter.mTagsList) {
    if (!mCurrentTags.contains(tag)) {
      mCurrentTags.add(tag);
      changed = true;

代码示例来源:origin: aa112901/remusic

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;
}

代码示例来源:origin: yigit/android-priority-jobqueue

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() {

代码示例来源:origin: apache/ignite

long idx = Long.parseLong(file.getName().substring(0, 16));
archiveIndices.add(idx);
if (!archiveIndices.contains(idx - 1))
  return F.t(idx, max);

代码示例来源:origin: robovm/robovm

set.add(name1 + "/" + name2 + "/" + name3);
      set.add(name1 + "/" + name2);                                
  set.add(name1);
if (set.contains(alias.getValue())) {
  set.add(alias.getKey());

代码示例来源:origin: ankidroid/Anki-Android

@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;
}

代码示例来源:origin: apache/kylin

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);
    }
  }
}

代码示例来源:origin: geoserver/geoserver

/**
 * 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;
}

代码示例来源:origin: geoserver/geoserver

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));

代码示例来源:origin: spring-projects/spring-security-oauth

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();
  }
}

代码示例来源:origin: geoserver/geoserver

provided.add(new Version(v));
Version version = (Version) v.next();
if (provided.contains(version)) {
  negotiated = version;
  break;

代码示例来源:origin: ankidroid/Anki-Android

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);
  }
}

代码示例来源:origin: geoserver/geoserver

provided.add(new Version(v));
  checkVersionNumber(v, null);
  accepted.add(new Version(v));
  Version version = (Version) v.next();
  if (!provided.contains(version)) {
    v.remove();
} else {
  for (String v : acceptedList) {
    accepted.add(new Version(v));

代码示例来源:origin: apache/maven

if ( !vertices.contains( vertex ) )
  vertices.add( vertex );

代码示例来源:origin: kiegroup/optaplanner

@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));
  }
}

代码示例来源:origin: com.vividsolutions/jts

public void filter(Coordinate coord) {
  if (!treeSet.contains(coord)) {
   list.add(coord);
   treeSet.add(coord);
  }
 }
}

代码示例来源:origin: neo4j/neo4j

doubleValue = new NodeValueTuple( node.getId(), propValue, pripValue );
while ( singlePropValues.contains( singleValue ) || doublePropValues.contains( doubleValue ) );
singlePropValues.add( singleValue );
doublePropValues.add( doubleValue );

代码示例来源:origin: apache/accumulo

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);
}

相关文章