Class TreeListMap<K,V>
java.lang.Object
org.javimmutable.collections.listmap.TreeListMap<K,V>
- All Implemented Interfaces:
Serializable
,Iterable<IMapEntry<K,
,IList<V>>> ICollection<IMapEntry<K,
,IList<V>>> IListMap<K,
,V> InvariantCheckable
,IStreamable<IMapEntry<K,
,IList<V>>> Mapped<K,
,IList<V>> SplitableIterable<IMapEntry<K,
IList<V>>>
IListMap
implementation that allows keys to be traversed in sorted order using a Comparator
of the natural ordering of the keys if they implement Comparable.- See Also:
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionSets the list associated with a specific key.void
Checks invariants of implementing class.protected void
Overridable by derived classes to create a compatible copy of the specified list.Implemented by derived classes to create a new instance of the appropriate class.Deletes the entry for the specified key (if any).IStreamable
<IMapEntry<K, IList<V>>> entries()
Creates an IStreamable to access all of the Map's entries.boolean
Return a Holder containing the value associated wth the key or an empty Holder if no value is associated with the key.Return the value associated with key or null if no value is associated.Return the list associated with key or an empty list if no list is associated.int
getValueOr
(K key, IList<V> defaultValue) Return the value associated with key or defaultValue if no value is associated.int
hashCode()
Add value to the list for the specified key.Add key/value entry to the map, replacing any existing entry with same key.Add all values to the container in some manner appropriate to the implementation.boolean
isEmpty()
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.static <K extends Comparable<K>,
V>
TreeListMap<K, V> of()
Constructs an empty list map whose keys are sorted in their natural ordering.static <K,
V> TreeListMap <K, V> of
(Comparator<K> comparator) Constructs an empty list map using the specified Comparator.int
size()
toString()
Creates an IStreamable to access all of the specified key's list.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.javimmutable.collections.ICollection
isNonEmpty
Methods inherited from interface org.javimmutable.collections.IListMap
deleteAll, deleteAll, forEach, forEachThrows, insertAll, insertAll, insertAll, listMapCollector, transform, transformIfPresent
Methods inherited from interface org.javimmutable.collections.IStreamable
parallelStream, spliterator, stream
Methods inherited from interface org.javimmutable.collections.SplitableIterable
forEachThrows, indexedForEach, indexedForEachThrows, reduce, reduceThrows
-
Field Details
-
emptyList
-
contents
-
-
Method Details
-
of
Constructs an empty list map whose keys are sorted in their natural ordering. The keys must implement Comparable. -
of
Constructs an empty list map using the specified Comparator. Note that the Comparator MUST BE IMMUTABLE. The Comparator will be retained and used throughout the life of the map and its offspring and will be aggressively shared so it is imperative that the Comparator be completely immutable. -
getComparator
-
checkInvariants
public void checkInvariants()Description copied from interface:InvariantCheckable
Checks invariants of implementing class.- Specified by:
checkInvariants
in interfaceInvariantCheckable
-
create
Implemented by derived classes to create a new instance of the appropriate class. -
getList
Description copied from interface:IListMap
Return the list associated with key or an empty list if no list is associated. -
assign
Description copied from interface:IListMap
Sets the list associated with a specific key. Key and value must be non-null. If the key already has a list in the map the old list is discarded and the new list is stored in its place. Returns a newIListMap
reflecting any changes. The original map is always left unchanged. -
insert
Description copied from interface:IListMap
Add value to the list for the specified key. Note that this can create duplicate values in the list. -
delete
Description copied from interface:IListMap
Deletes 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:
size
in interfaceICollection<K>
- Returns:
- number of values in the collection
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceICollection<K>
- Returns:
- true only if collection contains no values
-
keys
Description copied from interface:IListMap
Creates an IStreamable to access all of the Map's keys. -
values
Description copied from interface:IListMap
Creates an IStreamable to access all of the specified key's list. If no list exists for key an empty IStreamable is returned. -
entries
Description copied from interface:IListMap
Creates an IStreamable to access all of the Map's entries. -
insert
Description copied from interface:IListMap
Add key/value entry to the map, replacing any existing entry with same key.- Specified by:
insert
in interfaceICollection<K>
- Specified by:
insert
in interfaceIListMap<K,
V>
-
insertAll
@Nonnull public IListMap<K,V> insertAll(@Nonnull Iterator<? extends IMapEntry<K, IList<V>>> iterator) Description copied from interface:ICollection
Add all values to the container in some manner appropriate to the implementation.- Specified by:
insertAll
in interfaceICollection<K>
- Specified by:
insertAll
in interfaceIListMap<K,
V>
-
iterator
Description copied from interface:IStreamable
Overridden 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:
iterator
in interfaceIStreamable<K>
- Specified by:
iterator
in interfaceIterable<K>
- Specified by:
iterator
in interfaceSplitableIterable<K>
-
getSpliteratorCharacteristics
public int getSpliteratorCharacteristics()- Specified by:
getSpliteratorCharacteristics
in interfaceIStreamable<K>
- Returns:
- characteristics value used when creating Spliterators
-
get
Description copied from interface:Mapped
Return the value associated with key or null if no value is associated. Note that if null is an acceptable value to the container then this method will be ambiguous and find() should be used instead. -
getValueOr
Description copied from interface:Mapped
Return 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:
getValueOr
in 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:Mapped
Return a Holder containing the value associated wth the key or an empty Holder if no value is associated with the key. -
deleteAll
- Specified by:
deleteAll
in interfaceICollection<K>
- Specified by:
deleteAll
in interfaceIListMap<K,
V> - Returns:
- an equivalent collection with no values
-
hashCode
public int hashCode() -
equals
-
toString
-
checkListMapInvariants
protected void checkListMapInvariants() -
copyList
Overridable by derived classes to create a compatible copy of the specified list. Default implementation simply returns the original.
-