-
- Type Parameters:
K- the type for the keyT- the type for the values
- All Superinterfaces:
Collection<Pair<K,T>>,Foldable<Pair<K,T>>,java.lang.Iterable<Pair<K,T>>,java.io.Serializable,Streamable<Pair<K,T>>,Traversable<Pair<K,T>>,Value<Pair<K,T>>
public interface Map<K,T> extends Collection<Pair<K,T>>
This class represents a map implementation that is immutable. This means all operations that would change its contents result into a newMapbeing returned. The current instance is not modified.- Since:
- 0.0.3
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default booleancontainsKey(K key)Returns true if thisMapcontains the key provided.booleancontainsValue(T value)Verify if the presented value is contained within theMapvalue set.Map<K,T>filter(java.util.function.Predicate<Pair<K,T>> predicate)Filter out an element if it does not match the suppliedpredicate.Tget(K key)Get the value from theMapwith the corresponding key.Map<K,T>orElse(java.lang.Iterable<? extends Pair<K,T>> other)Returns eitherthisif it is non empty, otherwise will return the providedother.Map<K,T>orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends Pair<K,T>>> supplier)Returns eitherthisif it is non empty, otherwise the provided supplier is evaluated and returned.Map<K,T>put(K key, T value)Add a new entry to theMap.default Map<K,T>reject(java.util.function.Predicate<Pair<K,T>> predicate)Return a list that removes all elements that match thepredicateprovided.Map<K,T>remove(K key)Removes any element with the corresponding key from the map.Pair<? extends Map<K,T>,? extends Map<K,T>>split(java.util.function.Predicate<Pair<K,T>> predicate)The split operation is an execution that combines theCollection.reject(Predicate)and theCollection.filter(Predicate)methods into one.Map<K,T>tail()Build a new collection with all elements except for the head.java.util.Map<K,T>toJava()Convert the map to a regular Java map type.java.util.stream.Stream<T>valueStream()Build a stream of the values contained within thisMap.-
Methods inherited from interface com.jongsoft.lang.collection.Collection
containsAll, count, first, foldLeft, foldRight, get, head, isEmpty, isSingleValued, last, map, reduceLeft, size, summing
-
Methods inherited from interface com.jongsoft.lang.collection.Traversable
average, iterator, sum
-
-
-
-
Method Detail
-
put
Map<K,T> put(K key, T value)
Add a new entry to theMap.- Parameters:
key- the key for the entryvalue- the value for the entry- Returns:
- the new
Mapinstance with the added key, value pair - Throws:
java.lang.NullPointerException- in case the key isnull
-
remove
Map<K,T> remove(K key)
Removes any element with the corresponding key from the map.- Parameters:
key- the key indicating what needs to be removed- Returns:
- a new instance without the entry with the key
-
orElse
Map<K,T> orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends Pair<K,T>>> supplier)
Description copied from interface:TraversableReturns eitherthisif it is non empty, otherwise the provided supplier is evaluated and returned.- Specified by:
orElsein interfaceCollection<K>- Specified by:
orElsein interfaceTraversable<K>- Parameters:
supplier- the supplier to generate the other- Returns:
- this (@code Traversable} if non empty, otherwise other
-
orElse
Map<K,T> orElse(java.lang.Iterable<? extends Pair<K,T>> other)
Description copied from interface:TraversableReturns eitherthisif it is non empty, otherwise will return the providedother.- Specified by:
orElsein interfaceCollection<K>- Specified by:
orElsein interfaceTraversable<K>- Parameters:
other- the alternative- Returns:
- this
Traversableif non empty, orother
-
containsKey
default boolean containsKey(K key)
Returns true if thisMapcontains the key provided.- Parameters:
key- the key to look for- Returns:
- true if found, otherwise false
-
containsValue
boolean containsValue(T value)
Verify if the presented value is contained within theMapvalue set.- Parameters:
value- the value to look for- Returns:
- if the value is found or not
-
get
T get(K key)
Get the value from theMapwith the corresponding key. If the key is not contained in this instance thennullwill be returned.- Parameters:
key- the key to obtain the value for- Returns:
- the corresponding value, or
null
-
tail
Map<K,T> tail()
Description copied from interface:CollectionBuild a new collection with all elements except for the head. If there is only one element present then an empty collection will be returned. If the operation is called on an empty collection anNoSuchElementExceptionwill be thrown.- Specified by:
tailin interfaceCollection<K>- Returns:
- a collection containing the tail
-
valueStream
java.util.stream.Stream<T> valueStream()
Build a stream of the values contained within thisMap.- Returns:
- the stream with all the values
-
filter
Map<K,T> filter(java.util.function.Predicate<Pair<K,T>> predicate)
Description copied from interface:StreamableFilter out an element if it does not match the suppliedpredicate. This operation will iterate over all elements and return a new set containing only the elements where the predicate returnstruefor.- Specified by:
filterin interfaceCollection<K>- Specified by:
filterin interfaceStreamable<K>- Specified by:
filterin interfaceTraversable<K>- Parameters:
predicate- the predicate to apply to the contents of this- Returns:
- the filtered value
-
split
Pair<? extends Map<K,T>,? extends Map<K,T>> split(java.util.function.Predicate<Pair<K,T>> predicate)
Description copied from interface:CollectionThe split operation is an execution that combines theCollection.reject(Predicate)and theCollection.filter(Predicate)methods into one. Separating the values into 2 separate buckets. The first bucket will contain the same as theCollection.filter(Predicate)operation. The second bucket will contain the result of theCollection.reject(Predicate)operation.- Specified by:
splitin interfaceCollection<K>- Parameters:
predicate- the predicate to use- Returns:
- the two buckets of this operation
-
reject
default Map<K,T> reject(java.util.function.Predicate<Pair<K,T>> predicate)
Description copied from interface:TraversableReturn a list that removes all elements that match thepredicateprovided.- Specified by:
rejectin interfaceCollection<K>- Specified by:
rejectin interfaceTraversable<K>- Parameters:
predicate- the predicate to use- Returns:
- the elements that do not match the
predicate
-
-