Top Description Inners Fields Constructors Methods
com.google.protobuf

pack-priv Class SmallSortedMap<K extends java.lang.Comparable<K>, V>

extends AbstractMap<K extends Comparable<K>, V>
Class Inheritance
Imports
java.util.AbstractMap, .AbstractSet, .ArrayList, .Collections, .Iterator, .List, .Map, .NoSuchElementException, .Set, .SortedMap, .TreeMap

A custom map implementation from FieldDescriptor to Object optimized to minimize the number of memory allocations for instances with a small number of mappings. The implementation stores the first k mappings in an array for a configurable value of k, allowing direct access to the corresponding Entrys without the need to create an Iterator. The remaining entries are stored in an overflow map. Iteration over the entries in the map should be done as follows:
for (int i = 0; i < fieldMap.getNumArrayEntries(); i++) {
  process(fieldMap.getArrayEntryAt(i));
}
for (Map.Entry<K, V> entry : fieldMap.getOverflowEntries()) {
  process(entry);
}
The resulting iteration is in order of ascending field tag number. The object returned by entrySet() adheres to the same contract but is less efficient as it necessarily involves creating an object for iteration.

The tradeoff for this memory efficiency is that the worst case running time of the put() operation is O(k + lg n), which happens when entries are added in descending order. k should be chosen such that it covers enough common cases without adversely affecting larger maps. In practice, the worst case scenario does not happen for extensions because extension fields are serialized and deserialized in order of ascending tag number, but the worst case scenario can happen for DynamicMessages.

The running time for all other operations is similar to that of TreeMap.

Instances are not thread-safe until makeImmutable() is called, after which any modifying operation will result in an UnsupportedOperationException.

Author
[email protected] Darick Tong

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
SmallSortedMap.EmptySet

Helper class that holds immutable instances of an Iterable/Iterator that we return when the overflow entries is empty.

private class
SmallSortedMap.Entry

Entry implementation that implements Comparable in order to support binary search within the entry array.

private class
SmallSortedMap.EntryIterator

Iterator implementation that switches from the entry array to the overflow entries appropriately.

private class
SmallSortedMap.EntrySet

Stateless view of the entries in the field map.

Field Summary

Modifier and TypeField and Description
private List<SmallSortedMap<K, V>.Entry>
private boolean
private volatile SmallSortedMap<K, V>.EntrySet
private final int
private Map<K, V>

Constructor Summary

AccessConstructor and Description
private
SmallSortedMap(int arraySize)

Method Summary

Modifier and TypeMethod and Description
private int

Returns:

The returned integer position follows the same semantics as the value returned by java.util.Arrays#binarySearch().
binarySearchInArray
(K
The key to find in the entry array.
key
)

private void
public void
clear()

Overrides java.util.AbstractMap.clear.

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).
public boolean
containsKey(Object
key whose presence in this map is to be tested
o
)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

The implementation throws a ClassCastException if o is not an object of type K.
private void
ensureEntryArrayMutable()

Lazily creates the entry list.

public Set<Map.Entry<K, V>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Similar to the AbstractMap implementation of keySet() and values(), the entry set is created the first time this method is called, and returned in response to all subsequent calls.
public boolean
equals(Object
object to be compared for equality with this map
o
)

Overrides java.util.AbstractMap.equals.

Implements java.util.Map.equals.

Compares the specified object with this map for equality.
public V
get(Object
the key whose associated value is to be returned
o
)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

The implementation throws a ClassCastException if o is not an object of type K.
public Map.Entry<K, V>

Returns:

The array entry at the given index.
getArrayEntryAt
(int index)

public int

Returns:

The number of entries in the entry array.
getNumArrayEntries
()

public int

Returns:

There number of overflow entries.
getNumOverflowEntries
()

public Iterable<Map.Entry<K, V>>

Returns:

An iterable over the overflow entries.
getOverflowEntries
()

private SortedMap<K, V>

Returns:

a SortedMap to which overflow entries mappings can be added or removed.
getOverflowEntriesMutable
()

public int
hashCode()

Overrides java.util.AbstractMap.hashCode.

Implements java.util.Map.hashCode.

Returns the hash code value for this map.
public boolean

Returns:

Whether makeImmutable() has been called.
isImmutable
()

public void
makeImmutable()

Make this map immutable from this point forward.

pack-priv static <FieldDescriptorType extends FieldSet.FieldDescriptorLite<FieldDescriptorType>> SmallSortedMap<FieldDescriptorType, Object>
newFieldMap(int
The size of the entry array containing the lexicographically smallest mappings.
arraySize
)

Creates a new instance for mapping FieldDescriptors to their values.

pack-priv static <K extends Comparable<K>, V> SmallSortedMap<K, V>
newInstanceForTest(int
The size of the entry array containing the lexicographically smallest mappings.
arraySize
)

Creates a new instance for testing.

public V
put(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).
public V
remove(Object
key whose mapping is to be removed from the map
o
)

Overrides java.util.AbstractMap.remove.

Implements java.util.Map.remove.

The implementation throws a ClassCastException if o is not an object of type K.
private V
removeArrayEntryAt(int index)

public int
size()

Overrides java.util.AbstractMap.size.

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.
Inherited from java.util.AbstractMap:
clonecontainsValueisEmptykeySetputAlltoStringvalues

Field Detail

entryListback to summary
private List<SmallSortedMap<K, V>.Entry> entryList
isImmutableback to summary
private boolean isImmutable
lazyEntrySetback to summary
private volatile SmallSortedMap<K, V>.EntrySet lazyEntrySet
maxArraySizeback to summary
private final int maxArraySize
overflowEntriesback to summary
private Map<K, V> overflowEntries

Constructor Detail

SmallSortedMapback to summary
private SmallSortedMap(int arraySize)

Method Detail

binarySearchInArrayback to summary
private int binarySearchInArray(K key)
Parameters
key:K

The key to find in the entry array.

Returns:int

The returned integer position follows the same semantics as the value returned by java.util.Arrays#binarySearch().

checkMutableback to summary
private void checkMutable()
Exceptions
UnsupportedOperationException:
if makeImmutable() has has been called.
clearback to summary
public void clear()

Overrides java.util.AbstractMap.clear.

Implements java.util.Map.clear.

Doc from java.util.AbstractMap.clear.

Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.

Annotations
@Override
containsKeyback to summary
public boolean containsKey(Object o)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

Doc from java.util.AbstractMap.containsKey.

The implementation throws a ClassCastException if o is not an object of type K.

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that Objects.equals(key, k). (There can be at most one such mapping.)

Parameters
o:Object

Doc from java.util.Map.containsKey.

key whose presence in this map is to be tested

Returns:boolean

Doc from java.util.Map.containsKey.

true if this map contains a mapping for the specified key

Annotations
@Override
ensureEntryArrayMutableback to summary
private void ensureEntryArrayMutable()

Lazily creates the entry list. Any code that adds to the list must first call this method.

entrySetback to summary
public Set<Map.Entry<K, V>> entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Similar to the AbstractMap implementation of keySet() and values(), the entry set is created the first time this method is called, and returned in response to all subsequent calls.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Set<Map.Entry<K, V>>

a set view of the mappings contained in this map

Annotations
@Override
equalsback to summary
public boolean equals(Object o)

Overrides java.util.AbstractMap.equals.

Implements java.util.Map.equals.

Doc from java.util.AbstractMap.equals.

Compares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent the same mappings. More formally, two maps m1 and m2 represent the same mappings if m1.entrySet().equals(m2.entrySet()). This ensures that the equals method works properly across different implementations of the Map interface.

Parameters
o:Object

object to be compared for equality with this map

Returns:boolean

true if the specified object is equal to this map

Annotations
@Override
getback to summary
public V get(Object o)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Doc from java.util.AbstractMap.get.

The implementation throws a ClassCastException if o is not an object of type K.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Parameters
o:Object

Doc from java.util.Map.get.

the key whose associated value is to be returned

Returns:V

Doc from java.util.Map.get.

the value to which the specified key is mapped, or null if this map contains no mapping for the key

Annotations
@Override
getArrayEntryAtback to summary
public Map.Entry<K, V> getArrayEntryAt(int index)
Returns:Map.Entry<K, V>

The array entry at the given index.

getNumArrayEntriesback to summary
public int getNumArrayEntries()
Returns:int

The number of entries in the entry array.

getNumOverflowEntriesback to summary
public int getNumOverflowEntries()
Returns:int

There number of overflow entries.

getOverflowEntriesback to summary
public Iterable<Map.Entry<K, V>> getOverflowEntries()
Returns:Iterable<Map.Entry<K, V>>

An iterable over the overflow entries.

getOverflowEntriesMutableback to summary
private SortedMap<K, V> getOverflowEntriesMutable()
Returns:SortedMap<K, V>

a SortedMap to which overflow entries mappings can be added or removed.

Annotations
@SuppressWarnings:unchecked
Exceptions
UnsupportedOperationException:
if makeImmutable() has been called.
hashCodeback to summary
public int hashCode()

Overrides java.util.AbstractMap.hashCode.

Implements java.util.Map.hashCode.

Doc from java.util.AbstractMap.hashCode.

Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map's entrySet() view. This ensures that m1.equals(m2) implies that m1.hashCode()==m2.hashCode() for any two maps m1 and m2, as required by the general contract of Object#hashCode.

Returns:int

the hash code value for this map

Annotations
@Override
isImmutableback to summary
public boolean isImmutable()
Returns:boolean

Whether makeImmutable() has been called.

makeImmutableback to summary
public void makeImmutable()

Make this map immutable from this point forward.

newFieldMapback to summary
pack-priv static <FieldDescriptorType extends FieldSet.FieldDescriptorLite<FieldDescriptorType>> SmallSortedMap<FieldDescriptorType, Object> newFieldMap(int arraySize)

Creates a new instance for mapping FieldDescriptors to their values. The makeImmutable() implementation will convert the List values of any repeated fields to unmodifiable lists.

Parameters
arraySize:int

The size of the entry array containing the lexicographically smallest mappings.

newInstanceForTestback to summary
pack-priv static <K extends Comparable<K>, V> SmallSortedMap<K, V> newInstanceForTest(int arraySize)

Creates a new instance for testing.

Parameters
arraySize:int

The size of the entry array containing the lexicographically smallest mappings.

putback to summary
public V put(K key, V value)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Doc from java.util.AbstractMap.put.

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Parameters
key:K

Doc from java.util.Map.put.

key with which the specified value is to be associated

value:V

Doc from java.util.Map.put.

value to be associated with the specified key

Returns:V

Doc from java.util.Map.put.

the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key, if the implementation supports null values.)

Annotations
@Override
removeback to summary
public V remove(Object o)

Overrides java.util.AbstractMap.remove.

Implements java.util.Map.remove.

Doc from java.util.AbstractMap.remove.

The implementation throws a ClassCastException if o is not an object of type K.

Removes the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from key k to value v such that Objects.equals(key, k), that mapping is removed. (The map can contain at most one such mapping.)

Returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.

If this map permits null values, then a return value of null does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to null.

The map will not contain a mapping for the specified key once the call returns.

Parameters
o:Object

Doc from java.util.Map.remove.

key whose mapping is to be removed from the map

Returns:V

Doc from java.util.Map.remove.

the previous value associated with key, or null if there was no mapping for key.

Annotations
@Override
removeArrayEntryAtback to summary
private V removeArrayEntryAt(int index)
sizeback to summary
public int size()

Overrides java.util.AbstractMap.size.

Implements java.util.Map.size.

Doc from java.util.AbstractMap.size.

Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

Doc from java.util.Map.size.

the number of key-value mappings in this map

Annotations
@Override
com.google.protobuf back to summary

private Class SmallSortedMap.EmptySet

extends Object
Class Inheritance

Helper class that holds immutable instances of an Iterable/Iterator that we return when the overflow entries is empty. This eliminates the creation of an Iterator object when there is nothing to iterate over.

Field Summary

Modifier and TypeField and Description
private static final Iterable<Object>
private static final Iterator<Object>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static <T> Iterable<T>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ITERABLEback to summary
private static final Iterable<Object> ITERABLE
ITERATORback to summary
private static final Iterator<Object> ITERATOR

Constructor Detail

EmptySetback to summary
private EmptySet()

Method Detail

iterableback to summary
pack-priv static <T> Iterable<T> iterable()
Annotations
@SuppressWarnings:unchecked
com.google.protobuf back to summary

private Class SmallSortedMap.Entry

extends Object
implements Map.Entry<K extends Comparable<K>, V>, Comparable<SmallSortedMap<K extends Comparable<K>, V>.Entry>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable, java.util.Map.Entry

Entry implementation that implements Comparable in order to support binary search within the entry array. Also checks mutability in setValue().

Field Summary

Modifier and TypeField and Description
private final K
private V

Constructor Summary

AccessConstructor and Description
pack-priv
Entry(Map.Entry<K, V> copy)

pack-priv
Entry(K key, V value)

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(SmallSortedMap<K, V>.Entry
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public boolean
equals(Object
object to be compared for equality with this map entry
o
)

Overrides java.lang.Object.equals.

Implements java.util.Map.Entry.equals.

Compares the specified object with this entry for equality.
private boolean
equals(Object o1, Object o2)

equals() that handles null values.

public K
getKey()

Implements java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.
public V
getValue()

Implements java.util.Map.Entry.getValue.

Returns the value corresponding to this entry.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.Entry.hashCode.

Returns the hash code value for this map entry.
public V
setValue(V
new value to be stored in this entry
newValue
)

Implements java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation).
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

keyback to summary
private final K key
valueback to summary
private V value

Constructor Detail

Entryback to summary
pack-priv Entry(Map.Entry<K, V> copy)
Entryback to summary
pack-priv Entry(K key, V value)

Method Detail

compareToback to summary
public int compareTo(SmallSortedMap<K, V>.Entry other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
other:SmallSortedMap<K, V>.Entry

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Implements java.util.Map.Entry.equals.

Doc from java.util.Map.Entry.equals.

Compares the specified object with this entry for equality. Returns true if the given object is also a map entry and the two entries represent the same mapping. More formally, two entries e1 and e2 represent the same mapping if

    (e1.getKey()==null ?
     e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &&
    (e1.getValue()==null ?
     e2.getValue()==null : e1.getValue().equals(e2.getValue()))
This ensures that the equals method works properly across different implementations of the Map.Entry interface.
Parameters
o:Object

object to be compared for equality with this map entry

Returns:boolean

true if the specified object is equal to this map entry

Annotations
@Override
equalsback to summary
private boolean equals(Object o1, Object o2)

equals() that handles null values.

getKeyback to summary
public K getKey()

Implements java.util.Map.Entry.getKey.

Doc from java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.

Returns:K

the key corresponding to this entry

Annotations
@Override
getValueback to summary
public V getValue()

Implements java.util.Map.Entry.getValue.

Doc from java.util.Map.Entry.getValue.

Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove operation), the results of this call are undefined.

Returns:V

the value corresponding to this entry

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.Entry.hashCode.

Doc from java.util.Map.Entry.hashCode.

Returns the hash code value for this map entry. The hash code of a map entry e is defined to be:

    (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
    (e.getValue()==null ? 0 : e.getValue().hashCode())
This ensures that e1.equals(e2) implies that e1.hashCode()==e2.hashCode() for any two Entries e1 and e2, as required by the general contract of Object.hashCode.
Returns:int

the hash code value for this map entry

Annotations
@Override
setValueback to summary
public V setValue(V newValue)

Implements java.util.Map.Entry.setValue.

Doc from java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's remove operation).

Parameters
newValue:V

new value to be stored in this entry

Returns:V

old value corresponding to the entry

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.google.protobuf back to summary

private Class SmallSortedMap.EntryIterator

extends Object
implements Iterator<Map.Entry<K extends Comparable<K>, V>>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Iterator implementation that switches from the entry array to the overflow entries appropriately.

Field Summary

Modifier and TypeField and Description
private Iterator<Map.Entry<K, V>>
private boolean
private int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private Iterator<Map.Entry<K, V>>
getOverflowIterator()

It is important to create the overflow iterator only after the array entries have been iterated over because the overflow entry set changes when the client calls remove() on the array entries, which invalidates any existing iterators.

public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public Map.Entry<K, V>
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lazyOverflowIteratorback to summary
private Iterator<Map.Entry<K, V>> lazyOverflowIterator
nextCalledBeforeRemoveback to summary
private boolean nextCalledBeforeRemove
posback to summary
private int pos

Constructor Detail

EntryIteratorback to summary
private EntryIterator()

Method Detail

getOverflowIteratorback to summary
private Iterator<Map.Entry<K, V>> getOverflowIterator()

It is important to create the overflow iterator only after the array entries have been iterated over because the overflow entry set changes when the client calls remove() on the array entries, which invalidates any existing iterators.

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public Map.Entry<K, V> next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Map.Entry<K, V>

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override
com.google.protobuf back to summary

private Class SmallSortedMap.EntrySet

extends AbstractSet<Map.Entry<K extends Comparable<K>, V>>
Class Inheritance

Stateless view of the entries in the field map.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
add(Map.Entry<K, V>
element to be added to this set
entry
)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Adds the specified element to this set if it is not already present (optional operation).
public void
clear()

Overrides java.util.AbstractCollection.clear.

Implements java.util.Set.clear, java.util.Collection.clear.

Removes all of the elements from this set (optional operation).
public boolean
contains(Object
element whose presence in this set is to be tested
o
)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Throws a ClassCastException if o is not of the expected type.
public Iterator<Map.Entry<K, V>>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this set.
public boolean
remove(Object
object to be removed from this set, if present
o
)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Set.remove, java.util.Collection.remove.

Throws a ClassCastException if o is not of the expected type.
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Returns the number of elements in this set (its cardinality).
Inherited from java.util.AbstractSet:
equalshashCoderemoveAll

Constructor Detail

EntrySetback to summary
private EntrySet()

Method Detail

addback to summary
public boolean add(Map.Entry<K, V> entry)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Doc from java.util.Set.add.

Adds the specified element to this set if it is not already present (optional operation). More formally, adds the specified element e to this set if the set contains no element e2 such that Objects.equals(e, e2). If this set already contains the element, the call leaves the set unchanged and returns false. In combination with the restriction on constructors, this ensures that sets never contain duplicate elements.

The stipulation above does not imply that sets must accept all elements; sets may refuse to add any particular element, including null, and throw an exception, as described in the specification for Collection.add. Individual set implementations should clearly document any restrictions on the elements that they may contain.

Parameters
entry:Map.Entry<K, V>

element to be added to this set

Returns:boolean

true if this set did not already contain the specified element

Annotations
@Override
clearback to summary
public void clear()

Overrides java.util.AbstractCollection.clear.

Implements java.util.Set.clear, java.util.Collection.clear.

Doc from java.util.Set.clear.

Removes all of the elements from this set (optional operation). The set will be empty after this call returns.

Annotations
@Override
containsback to summary
public boolean contains(Object o)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Doc from java.util.Set.contains.

Throws a ClassCastException if o is not of the expected type.

Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that Objects.equals(o, e).

Parameters
o:Object

element whose presence in this set is to be tested

Returns:boolean

true if this set contains the specified element

Annotations
@Override
iteratorback to summary
public Iterator<Map.Entry<K, V>> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Doc from java.util.Set.iterator.

Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).

Returns:Iterator<Map.Entry<K, V>>

an iterator over the elements in this set

Annotations
@Override
removeback to summary
public boolean remove(Object o)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Set.remove, java.util.Collection.remove.

Doc from java.util.Set.remove.

Throws a ClassCastException if o is not of the expected type.

Removes the specified element from this set if it is present (optional operation). More formally, removes an element e such that Objects.equals(o, e), if this set contains such an element. Returns true if this set contained the element (or equivalently, if this set changed as a result of the call). (This set will not contain the element once the call returns.)

Parameters
o:Object

object to be removed from this set, if present

Returns:boolean

true if this set contained the specified element

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Doc from java.util.Set.size.

Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this set (its cardinality)

Annotations
@Override