Class OrderedMap<K,V>
java.lang.Object
org.javimmutable.collections.common.AbstractMap<K,V>
org.javimmutable.collections.inorder.OrderedMap<K,V>
- All Implemented Interfaces:
Serializable,Iterable<IMapEntry<K,,V>> ICollection<IMapEntry<K,,V>> IMap<K,,V> InvariantCheckable,IStreamable<IMapEntry<K,,V>> Mapped<K,,V> SplitableIterable<IMapEntry<K,V>>
IMap implementation that allows iteration over members in the order in which they
were inserted into the map. Maintains two parallel data structures, one for sorting and
the other for storing entries. Gets are approximately as fast as hash map gets but updates
are significantly slower.- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionOrderedMap<K, V> Sets the value associated with a specific key.static <K,V> IMapBuilder <K, V> builder()voidChecks invariants of implementing class.OrderedMap<K, V> Deletes the entry for the specified key (if any).OrderedMap<K, V> Search for a value within the map and return a Holder indicating if the value was found and, if it was found, the value itself.Search for an Entry within the map and return a Holder indicating if the Entry was found and, if it was found, the Entry itself.intgetValueOr(K key, V defaultValue) Return the value associated with key or defaultValue if no value is associated.iterator()Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator.keys()Creates an IStreamable to access all of the Map's keys.Creates a Builder with the same type signature as this Map.Returns a Collector that creates a set of the same type as this containing all of the collected values inserted over whatever starting values this already contained.static <K,V> OrderedMap <K, V> of()intsize()values()Creates an IStreamable to access all of the Map's values.Methods inherited from class org.javimmutable.collections.common.AbstractMap
assignAll, assignAll, equals, get, getMap, hashCode, insert, reject, select, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.javimmutable.collections.ICollection
isEmpty, isNonEmptyMethods inherited from interface org.javimmutable.collections.IMap
forEach, forEachThrows, insertAll, insertAll, reduce, reduceThrows, updateMethods inherited from interface org.javimmutable.collections.IStreamable
parallelStream, spliterator, streamMethods inherited from interface org.javimmutable.collections.SplitableIterable
forEachThrows, indexedForEach, indexedForEachThrows, reduce, reduceThrows
-
Field Details
-
EMPTY
-
-
Method Details
-
of
-
builder
-
mapBuilder
Description copied from interface:IMapCreates a Builder with the same type signature as this Map.- Specified by:
mapBuilderin interfaceIMap<K,V>
-
createMapCollector
-
mapCollector
Description copied from interface:IMapReturns a Collector that creates a set of the same type as this containing all of the collected values inserted over whatever starting values this already contained.- Specified by:
mapCollectorin interfaceIMap<K,V>
-
getValueOr
Description copied from interface:MappedReturn the value associated with key or defaultValue if no value is associated. Note that if defaultValue is an acceptable value to the container then this method will be ambiguous and find() should be used instead.- Specified by:
getValueOrin interfaceMapped<K,V> - Parameters:
key- identifies the value to retrievedefaultValue- value to return if no entry exists for key- Returns:
- value associated with key or defaultValue if no value is associated
-
find
Description copied from interface:IMapSearch for a value within the map and return a Holder indicating if the value was found and, if it was found, the value itself. Holder allows null values to be returned unambiguously. -
findEntry
Description copied from interface:IMapSearch for an Entry within the map and return a Holder indicating if the Entry was found and, if it was found, the Entry itself. -
assign
Description copied from interface:IMapSets the value associated with a specific key. Key must be non-null but value can be null. If the key already has a value in the map the old value is discarded and the new value is stored in its place. Returns a newIMapreflecting any changes. The original map is always left unchanged. -
delete
Description copied from interface:IMapDeletes the entry for the specified key (if any). Returns a new map if the value was deleted or the current map if the key was not contained in the map. -
size
public int size()- Specified by:
sizein interfaceICollection<K>- Returns:
- number of values in the collection
-
deleteAll
-
iterator
Description copied from interface:IStreamableOverridden here to require implementations to return a SplitableIterator rather than a basic Iterator. This is necessary to allow composition of new objects from methods like keys() and values().- Specified by:
iteratorin interfaceIStreamable<K>- Specified by:
iteratorin interfaceIterable<K>- Specified by:
iteratorin interfaceSplitableIterable<K>
-
keys
Description copied from interface:IMapCreates an IStreamable to access all of the Map's keys. -
values
Description copied from interface:IMapCreates an IStreamable to access all of the Map's values. -
getSpliteratorCharacteristics
public int getSpliteratorCharacteristics()- Specified by:
getSpliteratorCharacteristicsin interfaceIStreamable<K>- Overrides:
getSpliteratorCharacteristicsin classAbstractMap<K,V> - Returns:
- characteristics value used when creating Spliterators
-
checkInvariants
public void checkInvariants()Description copied from interface:InvariantCheckableChecks invariants of implementing class.- Specified by:
checkInvariantsin interfaceInvariantCheckable
-