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

How to use
Collection
in
java.util

Best Java code snippets using java.util.Collection (Showing top 20 results out of 282,249)

Refine searchRefine arrow

  • Stream
  • Collectors
  • Optional
origin: google/guava

private ClusterException(Collection<? extends Throwable> exceptions) {
 super(
   exceptions.size() + " exceptions were thrown. The first exception is listed as a cause.",
   exceptions.iterator().next());
 ArrayList<Throwable> temp = new ArrayList<>();
 temp.addAll(exceptions);
 this.exceptions = Collections.unmodifiableCollection(temp);
}
origin: ReactiveX/RxJava

@Override
public void onNext(T t) {
  synchronized (this) {
    U b = buffer;
    if (b != null) {
      b.add(t);
    }
  }
}
origin: google/guava

@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testClear() {
 collection.clear();
 assertTrue("After clear(), a collection should be empty.", collection.isEmpty());
 assertEquals(0, collection.size());
 assertFalse(collection.iterator().hasNext());
}
origin: google/guava

/** Used during deserialization only. */
final void setMap(Map<K, Collection<V>> map) {
 this.map = map;
 totalSize = 0;
 for (Collection<V> values : map.values()) {
  checkArgument(!values.isEmpty());
  totalSize += values.size();
 }
}
origin: spring-projects/spring-framework

@Override
public Collection<List<String>> values() {
  return this.headers.getHeaderNames().stream()
      .map(this.headers::get)
      .collect(Collectors.toList());
}
origin: prestodb/presto

public List<Symbol> getOriginalDistinctAggregateArgs()
{
  return aggregations.values().stream()
      .filter(aggregation -> aggregation.getMask().isPresent())
      .map(Aggregation::getCall)
      .flatMap(function -> function.getArguments().stream())
      .distinct()
      .map(Symbol::from)
      .collect(Collectors.toList());
}
origin: spring-projects/spring-framework

@Override
public Set<String> keySet() {
  return this.headers.getHeaderNames().stream()
      .map(HttpString::toString)
      .collect(Collectors.toSet());
}
origin: prestodb/presto

  public static boolean dependsOn(WindowNode parent, WindowNode child)
  {
    return parent.getPartitionBy().stream().anyMatch(child.getCreatedSymbols()::contains)
        || (parent.getOrderingScheme().isPresent() && parent.getOrderingScheme().get().getOrderBy().stream().anyMatch(child.getCreatedSymbols()::contains))
        || parent.getWindowFunctions().values().stream()
        .map(WindowNode.Function::getFunctionCall)
        .map(SymbolsExtractor::extractUnique)
        .flatMap(Collection::stream)
        .anyMatch(child.getCreatedSymbols()::contains);
  }
}
origin: google/guava

 private void assertCollectionSize(Collection<?> collection, int size) {
  assertEquals(size, collection.size());
  if (size > 0) {
   assertFalse(collection.isEmpty());
  } else {
   assertTrue(collection.isEmpty());
  }
  assertEquals(size, Iterables.size(collection));
  assertEquals(size, Iterators.size(collection.iterator()));
 }
}
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: apache/incubator-druid

@Nullable
MonitorEntry getRunningTaskMonitorEntry(String subTaskSpecId)
{
 return runningTasks.values()
           .stream()
           .filter(monitorEntry -> monitorEntry.spec.getId().equals(subTaskSpecId))
           .findFirst()
           .orElse(null);
}
origin: spring-projects/spring-framework

@Override
protected void applyCookies() {
  getCookies().values().stream().flatMap(Collection::stream)
      .map(cookie -> new DefaultCookie(cookie.getName(), cookie.getValue()))
      .forEach(this.request::addCookie);
}
origin: apache/flink

private static int getNumberOfSlotsPerTaskManager(final String host, final int port) throws Exception {
  final TaskManagersInfo taskManagersInfo = restClient.sendRequest(
    host,
    port,
    TaskManagersHeaders.getInstance()).get();
  return taskManagersInfo.getTaskManagerInfos()
    .stream()
    .map(TaskManagerInfo::getNumberSlots)
    .findFirst()
    .orElse(0);
}
origin: prestodb/presto

private static boolean noFilters(AggregationNode aggregation)
{
  return aggregation.getAggregations()
      .values().stream()
      .map(Aggregation::getCall)
      .noneMatch(call -> call.getFilter().isPresent());
}
origin: spring-projects/spring-framework

private void applyCookiesIfNecessary() {
  if (this.headers.get(HttpHeaders.COOKIE) == null) {
    this.cookies.values().stream().flatMap(Collection::stream)
        .forEach(cookie -> this.headers.add(HttpHeaders.COOKIE, cookie.toString()));
  }
}
origin: neo4j/neo4j

public void forEach( BiConsumer<String,URI> consumer )
{
  entries.stream().collect( Collectors.groupingBy( e -> e.key ) )
      .forEach( ( key, list ) -> list.stream()
          .max( Comparator.comparing( e -> e.precedence ) )
          .ifPresent( e -> consumer.accept( key, e.uri ) ) );
}
origin: google/guava

@CollectionSize.Require(absent = CollectionSize.ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testEquals_containingNull() {
 Collection<E> elements = getSampleElements(getNumElements() - 1);
 elements.add(null);
 collection = getSubjectGenerator().create(elements.toArray());
 assertTrue(
   "A Set should equal any other Set containing the same elements,"
     + " even if some elements are null.",
   getSet().equals(MinimalSet.from(elements)));
}
origin: google/guava

@CollectionFeature.Require({SUPPORTS_ADD, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
@CollectionSize.Require(absent = ZERO)
public void testAddConcurrentWithIteration() {
 try {
  Iterator<E> iterator = collection.iterator();
  assertTrue(collection.add(e3()));
  iterator.next();
  fail("Expected ConcurrentModificationException");
 } catch (ConcurrentModificationException expected) {
  // success
 }
}
origin: google/guava

public void testUnhashableMixedValues() {
 SampleElements<UnhashableObject> unhashables = new Unhashables();
 Multimap<Integer, Object> multimap =
   ImmutableMultimap.<Integer, Object>of(
     0, unhashables.e0(), 2, "hey you", 0, unhashables.e1());
 assertEquals(2, multimap.get(0).size());
 assertTrue(multimap.get(0).contains(unhashables.e0()));
 assertTrue(multimap.get(0).contains(unhashables.e1()));
 assertTrue(multimap.get(2).contains("hey you"));
}
origin: google/guava

/** An implementation of {@link Multiset#addAll}. */
static <E> boolean addAllImpl(Multiset<E> self, Collection<? extends E> elements) {
 checkNotNull(self);
 checkNotNull(elements);
 if (elements instanceof Multiset) {
  return addAllImpl(self, cast(elements));
 } else if (elements.isEmpty()) {
  return false;
 } else {
  return Iterators.addAll(self, elements.iterator());
 }
}
java.utilCollection

Javadoc

Collection is the root of the collection hierarchy. It defines operations on data collections and the behavior that they will have in all implementations of Collections. All direct or indirect implementations of Collection should implement at least two constructors. One with no parameters which creates an empty collection and one with a parameter of type Collection. This second constructor can be used to create a collection of different type as the initial collection but with the same elements. Implementations of Collectioncannot be forced to implement these two constructors but at least all implementations under java.util do. Methods that change the content of a collection throw an UnsupportedOperationException if the underlying collection does not support that operation, though it's not mandatory to throw such an Exceptionin cases where the requested operation would not change the collection. In these cases it's up to the implementation whether it throws an UnsupportedOperationException or not. Methods marked with (optional) can throw an UnsupportedOperationException if the underlying collection doesn't support that method.

Most used methods

  • 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.
  • contains
  • toArray
  • stream
  • addAll
  • forEach
  • remove
  • clear
  • removeAll
  • clear,
  • removeAll,
  • containsAll,
  • equals,
  • hashCode,
  • retainAll,
  • removeIf,
  • parallelStream,
  • spliterator,
  • <init>

Popular in Java

  • Parsing JSON documents to java classes using gson
  • requestLocationUpdates (LocationManager)
  • getContentResolver (Context)
  • runOnUiThread (Activity)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • 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