Tabnine Logo
Collection.contains
Code IndexAdd Tabnine to your IDE (free)

How to use
contains
method
in
java.util.Collection

Best Java code snippets using java.util.Collection.contains (Showing top 20 results out of 41,913)

Refine searchRefine arrow

  • Iterator.hasNext
  • Iterator.next
  • Collection.add
  • Collection.isEmpty
  • Collection.size
  • Nonnull.<init>
  • ConcurrentModificationException.<init>
  • Iterator.remove
  • Collection.iterator
origin: google/guava

@Override
public boolean removeAll(Collection<?> collection) {
 Iterator<Entry<K, V>> entryItr = unfiltered.entrySet().iterator();
 boolean result = false;
 while (entryItr.hasNext()) {
  Entry<K, V> entry = entryItr.next();
  if (predicate.apply(entry) && collection.contains(entry.getValue())) {
   entryItr.remove();
   result = true;
  }
 }
 return result;
}
origin: Atmosphere/atmosphere

@Override
public Broadcaster addBroadcasterListener(BroadcasterListener b) {
  if (!sharedListeners && !broadcasterListeners.contains(b)) {
    broadcasterListeners.add(b);
  }
  return this;
}
origin: apache/ignite

  @Override public boolean apply(T t) {
    return (!(c == null || c.isEmpty())) && c.contains(t);
  }
};
origin: apache/incubator-shardingsphere

@Override
public RoutingResult route() {
  Collection<RoutingResult> result = new ArrayList<>(logicTables.size());
  Collection<String> bindingTableNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
  for (String each : logicTables) {
    Optional<TableRule> tableRule = shardingRule.findTableRule(each);
    if (tableRule.isPresent()) {
      if (!bindingTableNames.contains(each)) {
        result.add(new StandardRoutingEngine(shardingRule, tableRule.get().getLogicTable(), shardingConditions).route());
  if (result.isEmpty()) {
    throw new ShardingException("Cannot find table rule and default data source with logic tables: '%s'", logicTables);
  if (1 == result.size()) {
    return result.iterator().next();
origin: google/guava

public void testValuesRemoveAll() {
 final Map<K, V> map;
 try {
  map = makePopulatedMap();
 } catch (UnsupportedOperationException e) {
  return;
 }
 Collection<V> valueCollection = map.values();
 Set<V> valuesToRemove = singleton(valueCollection.iterator().next());
 if (supportsRemove) {
  valueCollection.removeAll(valuesToRemove);
  for (V value : valuesToRemove) {
   assertFalse(valueCollection.contains(value));
  }
  for (V value : valueCollection) {
   assertFalse(valuesToRemove.contains(value));
  }
 } else {
  try {
   valueCollection.removeAll(valuesToRemove);
   fail("Expected UnsupportedOperationException.");
  } catch (UnsupportedOperationException expected) {
  }
 }
 assertInvariants(map);
}
origin: google/guava

assertEquals(map.size(), keySet.size());
assertEquals(keySet.size() == 0, keySet.isEmpty());
assertEquals(!keySet.isEmpty(), keySet.iterator().hasNext());
 assertTrue(map.containsKey(key));
 assertTrue(map.containsValue(value));
 assertTrue(valueCollection.contains(value));
 assertTrue(valueCollection.containsAll(Collections.singleton(value)));
 assertTrue(entrySet.contains(mapEntry(key, value)));
assertEquals(map.size(), valueCollection.size());
assertEquals(valueCollection.size() == 0, valueCollection.isEmpty());
assertEquals(!valueCollection.isEmpty(), valueCollection.iterator().hasNext());
for (V value : valueCollection) {
 assertTrue(map.containsValue(value));
assertEquals(!entrySet.isEmpty(), entrySet.iterator().hasNext());
assertEntrySetNotContainsString(entrySet);
origin: apache/incubator-shardingsphere

private List<ShardingValue> getShardingValuesFromShardingConditions(final Collection<String> shardingColumns, final ShardingCondition shardingCondition) {
  List<ShardingValue> result = new ArrayList<>(shardingColumns.size());
  for (ShardingValue each : shardingCondition.getShardingValues()) {
    Optional<BindingTableRule> bindingTableRule = shardingRule.findBindingTableRule(logicTableName);
    if ((logicTableName.equals(each.getLogicTableName()) || bindingTableRule.isPresent() && bindingTableRule.get().hasLogicTable(logicTableName)) 
        && shardingColumns.contains(each.getColumnName())) {
      result.add(each);
    }
  }
  return result;
}

origin: commons-collections/commons-collections

public void testIterator() {
  setUpTest();
  one.add("1");
  two.add("2");
  c.addComposited(one);
  c.addComposited(two);
  Iterator i = c.iterator();
  Object next = i.next();
  assertTrue(c.contains(next));
  assertTrue(one.contains(next));
  next = i.next();
  i.remove();
  assertTrue(!c.contains(next));
  assertTrue(!two.contains(next));
}

origin: apache/hive

private static Collection<String> catalogsToCache(RawStore rs) throws MetaException {
 Collection<String> confValue =
   MetastoreConf.getStringCollection(rs.getConf(), ConfVars.CATALOGS_TO_CACHE);
 if (confValue == null || confValue.isEmpty() ||
   (confValue.size() == 1 && confValue.contains(""))) {
  return rs.getCatalogs();
 } else {
  return confValue;
 }
}
origin: google/guava

public void testPermutationSetEmpty() {
 Collection<List<Integer>> permutationSet =
   Collections2.permutations(Collections.<Integer>emptyList());
 assertEquals(1, permutationSet.size());
 assertTrue(permutationSet.contains(Collections.<Integer>emptyList()));
 Iterator<List<Integer>> permutations = permutationSet.iterator();
 assertNextPermutation(Collections.<Integer>emptyList(), permutations);
 assertNoMorePermutations(permutations);
}
origin: commons-collections/commons-collections

public void testTransformedCollection() {
  Collection coll = TransformedCollection.decorate(new ArrayList(), STRING_TO_INTEGER_TRANSFORMER);
  assertEquals(0, coll.size());
  Object[] els = getFullElements();
  for (int i = 0; i < els.length; i++) {
    coll.add(els[i]);
    assertEquals(i + 1, coll.size());
    assertEquals(true, coll.contains(new Integer((String) els[i])));
    assertEquals(false, coll.contains(els[i]));
  }
  
  assertEquals(true, coll.remove(new Integer((String) els[0])));
}
origin: MovingBlocks/Terasology

@Test
public void testCollectionMethods() {
  Collection<Integer> buffer = CircularBuffer.create(4);
  buffer.addAll(ImmutableList.of(1, 2, 3, 4, 5, 6));
  buffer.add(4);
  assertTrue(buffer.contains(5));
  assertTrue(buffer.containsAll(ImmutableList.of(5, 4)));
}
origin: google/guava

static <K, V> boolean retainAllKeys(
  Map<K, V> map, Predicate<? super Entry<K, V>> entryPredicate, Collection<?> keyCollection) {
 Iterator<Entry<K, V>> entryItr = map.entrySet().iterator();
 boolean result = false;
 while (entryItr.hasNext()) {
  Entry<K, V> entry = entryItr.next();
  if (entryPredicate.apply(entry) && !keyCollection.contains(entry.getKey())) {
   entryItr.remove();
   result = true;
  }
 }
 return result;
}
origin: apache/storm

if (freeSlots.isEmpty()) {
  throw new IllegalStateException("Trying to assign to a full node " + nodeId);
if (executors.size() == 0) {
  LOG.warn("Trying to assign nothing from " + td.getId() + " to " + nodeId + " (Ignored)");
  target = getFreeSlots().iterator().next();
if (!freeSlots.contains(target)) {
  throw new IllegalStateException(
    "Trying to assign already used slot " + target.getPort() + " on node " + nodeId);
origin: google/guava

public void testValuesRetainAll() {
 final Map<K, V> map;
 try {
  map = makePopulatedMap();
 } catch (UnsupportedOperationException e) {
  return;
 }
 Collection<V> valueCollection = map.values();
 Set<V> valuesToRetain = singleton(valueCollection.iterator().next());
 if (supportsRemove) {
  valueCollection.retainAll(valuesToRetain);
  for (V value : valuesToRetain) {
   assertTrue(valueCollection.contains(value));
  }
  for (V value : valueCollection) {
   assertTrue(valuesToRetain.contains(value));
  }
 } else {
  try {
   valueCollection.retainAll(valuesToRetain);
   fail("Expected UnsupportedOperationException.");
  } catch (UnsupportedOperationException expected) {
  }
 }
 assertInvariants(map);
}
origin: spring-projects/spring-framework

@Override
protected void initServletContext(ServletContext servletContext) {
  Collection<ViewResolver> matchingBeans =
      BeanFactoryUtils.beansOfTypeIncludingAncestors(obtainApplicationContext(), ViewResolver.class).values();
  if (this.viewResolvers == null) {
    this.viewResolvers = new ArrayList<>(matchingBeans.size());
    for (ViewResolver viewResolver : matchingBeans) {
      if (this != viewResolver) {
        this.viewResolvers.add(viewResolver);
      }
    }
  }
  else {
    for (int i = 0; i < this.viewResolvers.size(); i++) {
      ViewResolver vr = this.viewResolvers.get(i);
      if (matchingBeans.contains(vr)) {
        continue;
      }
      String name = vr.getClass().getName() + i;
      obtainApplicationContext().getAutowireCapableBeanFactory().initializeBean(vr, name);
    }
  }
  AnnotationAwareOrderComparator.sort(this.viewResolvers);
  this.cnmFactoryBean.setServletContext(servletContext);
}
origin: bytedeco/javacpp

public void addClass(Class c) {
  if (!classes.contains(c)) {
    classes.add(c);
  }
}
origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testCallAsyncMultiple() throws Exception {
  Collection<ClosureTestCallable> jobs = F.asList(new ClosureTestCallable(), new ClosureTestCallable());
  IgniteFuture<Collection<Integer>> fut = callAsync(0, jobs, null);
  Collection<Integer> results = fut.get();
  assert !results.isEmpty() : "Collection of results is empty.";
  assert results.size() == jobs.size() :
    "Collection of results must be of size: " + jobs.size() + ".";
  for (int i = 1; i <= jobs.size(); i++)
    assert results.contains(i) : "Collection of results does not contain value: " + i;
}
origin: SonarSource/sonarqube

 public static boolean isFieldNeeded(String field, @Nullable Collection<String> fields) {
  return fields == null || fields.isEmpty() || fields.contains(field);
 }
}
origin: apache/ignite

/**
 * @param set Set.
 * @param size Expected size.
 */
private void assertSetContent(IgniteSet<Integer> set, int size) {
  Collection<Integer> data = new HashSet<>(size);
  for (Integer val : set)
    assertTrue(data.add(val));
  assertEquals(size, data.size());
  for (int val = 0; val < size; val++)
    assertTrue(data.contains(val));
}
java.utilCollectioncontains

Javadoc

Tests whether this Collection contains the specified object. Returns true if and only if at least one element elem in this Collection meets following requirement: (object==null ? elem==null : object.equals(elem)).

Popular methods of Collection

  • size
    Returns the number of elements in this collection. If this collection contains more than Integer.MAX
  • iterator
    Returns an iterator over the elements in this collection. There are no guarantees concerning the ord
  • add
  • isEmpty
    Returns true if this collection contains no elements.
  • toArray
  • stream
  • addAll
  • forEach
  • remove
  • clear
  • removeAll
  • containsAll
  • removeAll,
  • containsAll,
  • equals,
  • hashCode,
  • retainAll,
  • removeIf,
  • parallelStream,
  • spliterator,
  • <init>

Popular in Java

  • Making http requests using okhttp
  • getExternalFilesDir (Context)
  • getResourceAsStream (ClassLoader)
  • setScale (BigDecimal)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • JCheckBox (javax.swing)
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now