Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright (C) 2008 The Guava Authors
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 import java.util.Set;
Optional features of classes derived from Collection.

George van den Driessche
 // Enum values use constructors with generic varargs.
 public enum CollectionFeature implements Feature<Collection> {
The collection must not throw NullPointerException on calls such as contains(null) or remove(null), but instead must return a simple false.

Indicates that a collection disallows certain elements (other than null, whose validity as an element is indicated by the presence or absence of ALLOWS_NULL_VALUES). From the documentation for java.util.Collection:
"Some collection implementations have restrictions on the elements that they may contain. For example, some implementations prohibit null elements, and some have restrictions on the types of their elements."

Indicates that a collection has a well-defined ordering of its elements. The ordering may depend on the element values, such as a java.util.SortedSet, or on the insertion ordering, such as a java.util.LinkedHashSet. All list tests and sorted-collection tests automatically specify this feature.

Indicates that a collection has a different java.lang.Object.toString() representation than most collections. If not specified, the collection tests will examine the value returned by java.lang.Object.toString().

Indicates that the constructor or factory method of a collection, usually an immutable set, throws an java.lang.IllegalArgumentException when presented with duplicate elements instead of collapsing them to a single element or including duplicate instances in the collection.

Features supported by general-purpose collections - everything but RESTRICTS_ELEMENTS.

See also:
java.util.Collection the definition of general-purpose collections.

Features supported by collections where only removal is allowed.

For documenting collections that support no optional features, such as java.util.Collections.emptySet()
  private final Set<Feature<? super Collection>> implied;
  CollectionFeature(Feature<? super Collection> ... implied) {
    this. = Helpers.copyToSet(implied);
  public Set<Feature<? super Collection>> getImpliedFeatures() {
    return ;
  public @interface Require {
    CollectionFeature[] value() default {};
    CollectionFeature[] absent() default {};
New to GrepCode? Check out our FAQ X