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

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

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

Set.contains介绍

[英]Searches this set for the specified object.
[中]在该集合中搜索指定的对象。

代码示例

代码示例来源:origin: google/guava

@Override
public int size() {
 int size = set1.size();
 for (E e : set2) {
  if (!set1.contains(e)) {
   size++;
  }
 }
 return size;
}

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

protected boolean isMatch(Method method, String beanKey) {
  if (this.methodMappings != null) {
    Set<String> methodNames = this.methodMappings.get(beanKey);
    if (methodNames != null) {
      return methodNames.contains(method.getName());
    }
  }
  return (this.managedMethods != null && this.managedMethods.contains(method.getName()));
}

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

private static List<TypeElement> staticTypesIn(Iterable<? extends Element> elements) {
  List<TypeElement> list = new ArrayList<>();
  for (Element element : elements) {
    if (TYPE_KINDS.contains(element.getKind()) && element.getModifiers().contains(Modifier.STATIC)) {
      list.add(TypeElement.class.cast(element));
    }
  }
  return list;
}

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

@Test
public void testCircularCollectionBeansStartingWithSet() {
  this.beanFactory.getBean("circularSet");
  TestBean bean = (TestBean) this.beanFactory.getBean("circularCollectionBeansBean");
  List list = bean.getSomeList();
  assertFalse(Proxy.isProxyClass(list.getClass()));
  assertEquals(1, list.size());
  assertEquals(bean, list.get(0));
  Set set = bean.getSomeSet();
  assertTrue(Proxy.isProxyClass(set.getClass()));
  assertEquals(1, set.size());
  assertTrue(set.contains(bean));
  Map map = bean.getSomeMap();
  assertFalse(Proxy.isProxyClass(map.getClass()));
  assertEquals(1, map.size());
  assertEquals(bean, map.get("foo"));
}

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

private void ensureInitializerInvoked(GoPluginDescriptor pluginDescriptor, GoPlugin plugin, String extensionType) {
  synchronized (initializedPluginsWithTheirExtensionTypes) {
    if (initializedPluginsWithTheirExtensionTypes.get(pluginDescriptor) == null) {
      initializedPluginsWithTheirExtensionTypes.put(pluginDescriptor, new HashSet<>());
    }
    Set<String> initializedExtensions = initializedPluginsWithTheirExtensionTypes.get(pluginDescriptor);
    if (initializedExtensions == null || initializedExtensions.contains(extensionType)) {
      return;
    }
    initializedPluginsWithTheirExtensionTypes.get(pluginDescriptor).add(extensionType);
    PluginAwareDefaultGoApplicationAccessor accessor = new PluginAwareDefaultGoApplicationAccessor(pluginDescriptor, requestProcesRegistry);
    plugin.initializeGoApplicationAccessor(accessor);
  }
}

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

public static List<String> getRepeat(List<String> list) {
  List<String> rtn = new ArrayList<String>();
  Set<String> idSet = new HashSet<String>();
  for (String id : list) {
    if (idSet.contains(id)) {
      rtn.add(id);
    } else {
      idSet.add(id);
    }
  }
  return rtn;
}

代码示例来源:origin: skylot/jadx

public List<LoopInfo> getAllLoopsForBlock(BlockNode block) {
  if (loops.isEmpty()) {
    return Collections.emptyList();
  }
  List<LoopInfo> list = new ArrayList<>(loops.size());
  for (LoopInfo loop : loops) {
    if (loop.getLoopBlocks().contains(block)) {
      list.add(loop);
    }
  }
  return list;
}

代码示例来源:origin: org.assertj/assertj-core

private static boolean noNonMatchingModifier(Set<String> expectedMethodNames, Map<String, Integer> methodsModifier,
                       Map<String, String> nonMatchingModifiers, int modifier) {
 for (String method : methodsModifier.keySet()) {
  if (expectedMethodNames.contains(method) && (methodsModifier.get(method) & modifier) == 0) {
   nonMatchingModifiers.put(method, Modifier.toString(methodsModifier.get(method)));
  }
 }
 return nonMatchingModifiers.isEmpty();
}

代码示例来源:origin: thinkaurelius/titan

private void cleanup() {
  if (deleted==null || deleted.isEmpty()) return;
  Set<InternalRelation> deletedSet = new HashSet<InternalRelation>(deleted);
  deleted=null;
  List<InternalRelation> newadded = new ArrayList<InternalRelation>(added.size()-deletedSet.size()/2);
  for (InternalRelation r : added) {
    if (!deletedSet.contains(r)) newadded.add(r);
  }
  added=newadded;
}

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

@Implementation(minSdk = JELLY_BEAN_MR2)
protected Account[] getAccountsByTypeForPackage(String type, String packageName) {
 List<Account> result = new ArrayList<>();
 Account[] accountsByType = getAccountsByType(type);
 for (Account account : accountsByType) {
  if (packageVisibileAccounts.containsKey(account) && packageVisibileAccounts.get(account).contains(packageName)) {
   result.add(account);
  }
 }
 return result.toArray(new Account[result.size()]);
}

代码示例来源:origin: skylot/jadx

/**
 * @return true if this value is duplicated
 */
public boolean put(Object value, FieldNode fld) {
  FieldNode prev = values.put(value, fld);
  if (prev != null) {
    values.remove(value);
    duplicates.add(value);
    return true;
  }
  if (duplicates.contains(value)) {
    values.remove(value);
    return true;
  }
  return false;
}

代码示例来源:origin: stanfordnlp/CoreNLP

private static List<Sieve.MentionData> eliminateDuplicates(List<Sieve.MentionData> mentionCandidates)
{
 List<Sieve.MentionData> newList = new ArrayList<>();
 Set<String> seenText = new HashSet<>();
 for(int i = 0; i < mentionCandidates.size(); i++)
 {
  Sieve.MentionData mentionCandidate = mentionCandidates.get(i);
  String text = mentionCandidate.text;
  if(!seenText.contains(text) || mentionCandidate.type.equals("Pronoun"))
   newList.add(mentionCandidate);
  seenText.add(text);
 }
 return newList;
}

代码示例来源:origin: org.testng/testng

private static List<ITestNGMethod> retrieve(Set<String> tracker, Map<String, List<ITestNGMethod>> map, String group) {
 if (tracker.contains(group)) {
  return Collections.EMPTY_LIST;
 }
 tracker.add(group);
 return map.get(group);
}

代码示例来源:origin: eclipse-vertx/vert.x

public DefaultCommandLine addRawValue(Option option, String value) {
 if (!acceptMoreValues(option) && !option.isFlag()) {
  throw new CLIException("The option " + option.getName() + " does not accept value or has " +
    "already been set");
 }
 if (! option.getChoices().isEmpty()  && ! option.getChoices().contains(value)) {
  throw new InvalidValueException(option, value);
 }
 List<String> list = optionValues.get(option);
 if (list == null) {
  list = new ArrayList<>();
  optionValues.put(option, list);
 }
 list.add(value);
 return this;
}

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

@Test
public void replaceUriTemplateParamsTemplateWithParamMatchNamePreEncoding() throws JspException {
  List<Param> params = new LinkedList<>();
  Set<String> usedParams = new HashSet<>();
  Param param = new Param();
  param.setName("n me");
  param.setValue("value");
  params.add(param);
  String uri = tag.replaceUriTemplateParams("url/{n me}", params, usedParams);
  assertEquals("url/value", uri);
  assertEquals(1, usedParams.size());
  assertTrue(usedParams.contains("n me"));
}

代码示例来源:origin: google/guava

static char[] randomChars(Random rand, int size) {
 Set<Character> chars = new HashSet<>(size);
 for (int i = 0; i < size; i++) {
  char c;
  while (true) {
   c = (char) rand.nextInt(Character.MAX_VALUE - Character.MIN_VALUE + 1);
   if (!chars.contains(c)) {
    break;
   }
  }
  chars.add(c);
 }
 char[] retValue = new char[chars.size()];
 int i = 0;
 for (char c : chars) {
  retValue[i++] = c;
 }
 Arrays.sort(retValue);
 return retValue;
}

代码示例来源:origin: stanfordnlp/CoreNLP

private static <T, S> void exploreStates(List<DFSAState<T, S>> toVisit, Set<DFSAState<T, S>> visited) {
 while (!toVisit.isEmpty()) {
  DFSAState<T, S> state = toVisit.get(toVisit.size() - 1);
  toVisit.remove(toVisit.size() - 1);
  if (!visited.contains(state)) {
   toVisit.addAll(state.successorStates());
   visited.add(state);
  }
 }
}

代码示例来源:origin: thinkaurelius/titan

private void verifyVerticesRetrieval(long[] vids, List<TitanVertex> vs) {
  assertEquals(vids.length, vs.size());
  Set<Long> vset = new HashSet<>(vs.size());
  vs.forEach(v -> vset.add((Long) v.id()));
  for (int i = 0; i < vids.length; i++) {
    assertTrue(vset.contains(vids[i]));
  }
}

代码示例来源:origin: prestodb/presto

public void noMoreSplits(PlanNodeId planNodeId)
{
  if (noMoreSplits.contains(planNodeId)) {
    return;
  }
  noMoreSplits.add(planNodeId);
  if (noMoreSplits.size() < sourceStartOrder.size()) {
    return;
  }
  checkState(noMoreSplits.size() == sourceStartOrder.size());
  checkState(noMoreSplits.containsAll(sourceStartOrder));
  status.setNoMoreLifespans();
}

代码示例来源:origin: google/guava

private static Set<Feature<?>> computeValuesCollectionFeatures(Set<Feature<?>> mapFeatures) {
 Set<Feature<?>> valuesCollectionFeatures = computeCommonDerivedCollectionFeatures(mapFeatures);
 if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUE_QUERIES)) {
  valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
 }
 if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) {
  valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
 }
 return valuesCollectionFeatures;
}

相关文章