Class AnnotationMirrorSet
- All Implemented Interfaces:
Iterable<AnnotationMirror>,Collection<AnnotationMirror>,Set<@KeyFor("this") AnnotationMirror>,DeepCopyable<AnnotationMirrorSet>
AnnotationUtils.areSame(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror) rather than equals.
For example, the specification for the contains(Object o) method says: "returns true if and
only if this collection contains at least one element e such that (o == null ? e == null :
o.equals(e))." The specification for contains(java.lang.Object) is "returns true if and
only if this collection contains at least one element e such that (o == null ? e == null :
AnnotationUtils.areSame(o, e))".
AnnotationMirror is an interface and not all implementing classes provide a correct equals method; therefore, the existing implementations of Set cannot be used.
Implementation note: the backing store is an ArrayList with linear scan using AnnotationUtils.areSame(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror) rather than a TreeSet with AnnotationUtils.compareAnnotationMirrors(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror). In practice these sets are very small (typically 1-3
elements, almost always fewer than 5) so a linear scan beats a sorted structure whose comparator
invocation and per-node allocation exceed the benefit of O(log n) lookup.
Unmodifiability is tracked by a boolean flag.
No longer implements NavigableSet; there is no point in asking for the "first" element in these sets - ask for the qualifier in a specific hierarchy.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.AnnotationMirrorSet(Collection<? extends AnnotationMirror> annos) Returns a newAnnotationMirrorSetthat contains the given annotation mirrors.Creates a newAnnotationMirrorSetthat containsvalue. -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(AnnotationMirror annotationMirror) booleanaddAll(Collection<? extends AnnotationMirror> c) voidclear()booleanbooleancontainsAll(Collection<?> c) deepCopy()Returns a deep copy of this.static AnnotationMirrorSetemptySet()Returns an unmodifiable empty set.booleanget(@org.checkerframework.checker.index.qual.IndexFor({"this"}) int index) Returns the element at the given index in this set's insertion order.inthashCode()booleanisEmpty()Iterator<@KeyFor("this") AnnotationMirror> iterator()Make this set unmodifiable.booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) static AnnotationMirrorSetsingleton(AnnotationMirror value) Returns a new unmodifiableAnnotationMirrorSetthat containsvalue.intsize()Object[]toArray()<@KeyForBottom T>
@Nullable T[]toString()static AnnotationMirrorSetunmodifiableSet(Collection<? extends AnnotationMirror> annos) Returns an unmodifiable AnnotationMirrorSet with the given elements.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
spliterator
-
Constructor Details
-
AnnotationMirrorSet
public AnnotationMirrorSet()Default constructor. -
AnnotationMirrorSet
Creates a newAnnotationMirrorSetthat containsvalue.- Parameters:
value- the AnnotationMirror to put in the set
-
AnnotationMirrorSet
Returns a newAnnotationMirrorSetthat contains the given annotation mirrors.- Parameters:
annos- the AnnotationMirrors to put in the set
-
-
Method Details
-
deepCopy
Description copied from interface:DeepCopyableReturns a deep copy of this. A deep copy is equal to the original, but side effects to either object are not visible in the other. A deep copy may share immutable state with the original.The run-time class of the result is identical to the run-time class of this. The deep copy is equal to
this(perequals()if the object's class does not use reference equality asObject.equals()does).- Specified by:
deepCopyin interfaceDeepCopyable<AnnotationMirrorSet>- Returns:
- a deep copy of this
-
makeUnmodifiable
Make this set unmodifiable. Idempotent.- Returns:
- this set
-
singleton
Returns a new unmodifiableAnnotationMirrorSetthat containsvalue.- Parameters:
value- the AnnotationMirror to put in the set- Returns:
- a new unmodifiable
AnnotationMirrorSetthat contains onlyvalue
-
unmodifiableSet
Returns an unmodifiable AnnotationMirrorSet with the given elements.- Parameters:
annos- the annotation mirrors that will constitute the new unmodifiable set- Returns:
- an unmodifiable AnnotationMirrorSet with the given elements
-
emptySet
Returns an unmodifiable empty set.- Returns:
- an unmodifiable empty set
-
size
public int size()- Specified by:
sizein interfaceCollection<AnnotationMirror>- Specified by:
sizein interfaceSet<@KeyFor("this") AnnotationMirror>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<AnnotationMirror>- Specified by:
isEmptyin interfaceSet<@KeyFor("this") AnnotationMirror>
-
contains
public boolean contains(@UnknownInitialization(AnnotationMirrorSet.class) AnnotationMirrorSet this, @Nullable Object o) - Specified by:
containsin interfaceCollection<AnnotationMirror>- Specified by:
containsin interfaceSet<@KeyFor("this") AnnotationMirror>
-
iterator
- Specified by:
iteratorin interfaceCollection<AnnotationMirror>- Specified by:
iteratorin interfaceIterable<AnnotationMirror>- Specified by:
iteratorin interfaceSet<@KeyFor("this") AnnotationMirror>
-
get
Returns the element at the given index in this set's insertion order. The backing store is anArrayList, so this set has a stable iteration order; this accessor lets hot callers iterate by index (in conjunction withsize()) without allocating anIteratoron every traversal. Iterating anAnnotationMirrorSetviaiterator()was the single largest source ofArrayList$Itrallocations in nullness-checking JFR traces.- Parameters:
index- the index, in[0, size())- Returns:
- the element at
index
-
toArray
- Specified by:
toArrayin interfaceCollection<AnnotationMirror>- Specified by:
toArrayin interfaceSet<@KeyFor("this") AnnotationMirror>
-
toArray
- Specified by:
toArrayin interfaceCollection<AnnotationMirror>- Specified by:
toArrayin interfaceSet<@KeyFor("this") AnnotationMirror>
-
add
public boolean add(@UnknownInitialization(AnnotationMirrorSet.class) AnnotationMirrorSet this, AnnotationMirror annotationMirror) - Specified by:
addin interfaceCollection<AnnotationMirror>- Specified by:
addin interfaceSet<@KeyFor("this") AnnotationMirror>
-
remove
- Specified by:
removein interfaceCollection<AnnotationMirror>- Specified by:
removein interfaceSet<@KeyFor("this") AnnotationMirror>
-
containsAll
- Specified by:
containsAllin interfaceCollection<AnnotationMirror>- Specified by:
containsAllin interfaceSet<@KeyFor("this") AnnotationMirror>
-
addAll
public boolean addAll(@UnknownInitialization(AnnotationMirrorSet.class) AnnotationMirrorSet this, Collection<? extends AnnotationMirror> c) - Specified by:
addAllin interfaceCollection<AnnotationMirror>- Specified by:
addAllin interfaceSet<@KeyFor("this") AnnotationMirror>
-
retainAll
- Specified by:
retainAllin interfaceCollection<AnnotationMirror>- Specified by:
retainAllin interfaceSet<@KeyFor("this") AnnotationMirror>
-
removeAll
- Specified by:
removeAllin interfaceCollection<AnnotationMirror>- Specified by:
removeAllin interfaceSet<@KeyFor("this") AnnotationMirror>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<AnnotationMirror>- Specified by:
clearin interfaceSet<@KeyFor("this") AnnotationMirror>
-
toString
-
equals
- Specified by:
equalsin interfaceCollection<AnnotationMirror>- Specified by:
equalsin interfaceSet<@KeyFor("this") AnnotationMirror>- Overrides:
equalsin classObject
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<AnnotationMirror>- Specified by:
hashCodein interfaceSet<@KeyFor("this") AnnotationMirror>- Overrides:
hashCodein classObject
-