Package org.goplanit.utils.wrapper
Interface MapWrapper<K,V>
-
- Type Parameters:
K
- key typeV
- value type
- All Superinterfaces:
Iterable<V>
- All Known Subinterfaces:
CentroidVertices
,ConjugateConnectoidEdges
,ConjugateConnectoidNodes
,ConjugateConnectoidSegments
,ConjugateDirectedEdges
,ConjugateDirectedVertices
,ConjugateEdges
,ConjugateEdgeSegments
,ConjugateLinks
,ConjugateLinkSegments
,ConjugateNodes
,ConjugateVertices
,ConnectoidEdges
,Connectoids<T>
,ConnectoidSegments
,DirectedConnectoids
,DirectedEdges
,DirectedVertices
,Edges
,EdgeSegments
,GraphEntities<E>
,Links<L>
,LinkSegments
,LongMapWrapper<V>
,MacroscopicLinks
,MacroscopicLinkSegments
,MacroscopicLinkSegmentTypes
,MacroscopicNetworkLayers
,ManagedDirectedPaths
,ManagedGraphEntities<E>
,ManagedIdEntities<E>
,Modes
,NetworkLayers<T>
,Nodes
,OdZones
,RoutedModeServices
,RoutedServicesLayers
,RoutedTripDepartures
,RoutedTrips<T>
,RoutedTripsFrequency
,RoutedTripsSchedule
,ServiceLegs
,ServiceLegSegments
,ServiceNetworkLayers
,ServiceNodes
,TopologicalLayers<T>
,TransferZoneGroups
,TransferZones
,UndirectedConnectoids
,UntypedDirectedGraphLayers<L>
,UntypedPhysicalNetworkLayers<L>
,Vertices
,Zones<Z>
- All Known Implementing Classes:
CentroidVerticesImpl
,ConjugateConnectoidEdgesImpl
,ConjugateConnectoidNodesImpl
,ConjugateConnectoidSegmentsImpl
,ConjugateLinkSegmentsImpl
,ConjugateLinksImpl
,ConjugateNodesImpl
,ConnectoidEdgesImpl
,ConnectoidSegmentsImpl
,ConnectoidsImpl
,DirectedConnectoidsImpl
,DirectedEdgesImpl
,DirectedVerticesImpl
,EdgeSegmentsImpl
,EdgesImpl
,GraphEntitiesImpl
,LinksImpl
,LongMapWrapperImpl
,MacroscopicLinkSegmentsImpl
,MacroscopicLinkSegmentTypesImpl
,MacroscopicLinksImpl
,MacroscopicNetworkLayersImpl
,ManagedDirectedPathsImpl
,ManagedGraphEntitiesImpl
,ManagedIdEntitiesImpl
,MapWrapperImpl
,ModesImpl
,NodesImpl
,OdZonesImpl
,ProjectDemands
,ProjectNetworks
,ProjectOdPathSets
,ProjectRoutedServices
,ProjectServiceNetworks
,ProjectZonings
,RoutedModeServicesImpl
,RoutedServicesLayersImpl
,RoutedTripDeparturesImpl
,RoutedTripsFrequencyImpl
,RoutedTripsImpl
,RoutedTripsScheduleImpl
,ServiceLegSegmentsImpl
,ServiceLegsImpl
,ServiceNetworkLayersImpl
,ServiceNodesImpl
,TimePeriods
,TopologicalLayersImpl
,TransferZoneGroupsImpl
,TransferZonesImpl
,TransportLayersImpl
,TravellerTypes
,UndirectedConnectoidsImpl
,UntypedPhysicalNetworkLayersImpl
,UserClasses
,VerticesImpl
,ZonesImpl
public interface MapWrapper<K,V> extends Iterable<V>
Wrap a map as a named class for a non-null key- Author:
- markr
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
addAll(Iterable<? extends V> iterable)
add all elements of iterablevoid
clear()
Clear all entries from mapboolean
containsValue(V value)
Check if value is already presentV
firstMatch(Predicate<V> valuePredicate)
Find first entry that matches the predicatestatic <KK,VV>
VVfirstMatch(MapWrapper<KK,VV> mapWrapper, Predicate<VV> valuePredicate)
Collect first match by iterating through map based on some predicatedefault <T extends V>
voidforEachIn(Collection<T> values, Consumer<T> consumer)
apply provided consumer to each element in values as long as that element is registered on this wrapperV
get(K key)
Collect entry from containerdefault V
getFirst()
collect the first entry based on the iterator's result, which is not necessarily the fist entry ordered by the key, it is just the first entry the iterator would provideK
getKeyByValue(V value)
collect the key used for the given valueboolean
isEmpty()
Verify if the map is emptyV
register(V value)
Register on the internal container (no null keys allowed which will trigger a warning and the value not to be registered)V
remove(V value)
Remove value from mapdefault void
removeAll(Collection<V> toBeRemoved)
Remove all entries in provided collection.void
removeIf(Predicate<V> condition)
Remove all values that satisfy the given conditionMapWrapper<K,V>
shallowClone()
Each map wrapper should be cloneable where the contents are references of the original where possible but the underlying map itself is newly createdint
size()
The number of registered entriesdefault Stream<V>
stream()
Create a stream from this iterabledefault <M extends Comparable>
Stream<V>streamSorted(Function<V,M> comparingFunction)
stream in a sorted manner to allow for a specific ordering other than the underlying key usedCollection<V>
toCollection()
Collect values as unmodifiable collectiondefault <K> Map<K,V>
toMap(Function<V,K> getCustomKey)
Convert to a map with a custom key obtained from entriesSet<V>
valuesAsNewSet()
Create a copy of the map's distinct values as a set-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
-
-
Method Detail
-
firstMatch
static <KK,VV> VV firstMatch(MapWrapper<KK,VV> mapWrapper, Predicate<VV> valuePredicate)
Collect first match by iterating through map based on some predicate- Type Parameters:
KK
- key typeVV
- value type- Parameters:
mapWrapper
- the wrapper to apply tovaluePredicate
- the filter to apply to obtain the first match- Returns:
- found match
-
register
V register(V value)
Register on the internal container (no null keys allowed which will trigger a warning and the value not to be registered)- Parameters:
value
- to register- Returns:
- old value if any
-
remove
V remove(V value)
Remove value from map- Parameters:
value
- to remove- Returns:
- removed entry if any
-
removeAll
default void removeAll(Collection<V> toBeRemoved)
Remove all entries in provided collection.- Parameters:
toBeRemoved
- the to be removed entries
-
removeIf
void removeIf(Predicate<V> condition)
Remove all values that satisfy the given condition- Parameters:
condition
- to remove
-
clear
void clear()
Clear all entries from map
-
size
int size()
The number of registered entries- Returns:
- number of entries
-
isEmpty
boolean isEmpty()
Verify if the map is empty- Returns:
- true when empty false otherwise
-
containsValue
boolean containsValue(V value)
Check if value is already present- Parameters:
value
- to verify- Returns:
- true if present, false otherwise
-
toCollection
Collection<V> toCollection()
Collect values as unmodifiable collection- Returns:
- collection
-
valuesAsNewSet
Set<V> valuesAsNewSet()
Create a copy of the map's distinct values as a set- Returns:
- copy of values as set
-
firstMatch
V firstMatch(Predicate<V> valuePredicate)
Find first entry that matches the predicate- Parameters:
valuePredicate
- that checks a property of the value and the first which matches is returned- Returns:
- the retrieved entry, or null if no traveler type was found
-
shallowClone
MapWrapper<K,V> shallowClone()
Each map wrapper should be cloneable where the contents are references of the original where possible but the underlying map itself is newly created- Returns:
- copy
-
getKeyByValue
K getKeyByValue(V value)
collect the key used for the given value- Parameters:
value
- to collect used key for- Returns:
- key
-
getFirst
default V getFirst()
collect the first entry based on the iterator's result, which is not necessarily the fist entry ordered by the key, it is just the first entry the iterator would provide- Returns:
- first iterable entry, null if empty
-
addAll
default void addAll(Iterable<? extends V> iterable)
add all elements of iterable- Parameters:
iterable
- to add elements of
-
forEachIn
default <T extends V> void forEachIn(Collection<T> values, Consumer<T> consumer)
apply provided consumer to each element in values as long as that element is registered on this wrapper- Type Parameters:
T
- type of values- Parameters:
values
- to apply consumer to when they are registered in this wrapperconsumer
- to apply
-
toMap
default <K> Map<K,V> toMap(Function<V,K> getCustomKey)
Convert to a map with a custom key obtained from entries- Type Parameters:
K
- type of key- Parameters:
getCustomKey
- function to extract key from entries- Returns:
- populated map
-
stream
default Stream<V> stream()
Create a stream from this iterable- Returns:
- stream of all entries (values)
-
streamSorted
default <M extends Comparable> Stream<V> streamSorted(Function<V,M> comparingFunction)
stream in a sorted manner to allow for a specific ordering other than the underlying key used- Type Parameters:
M
- type of comparable- Parameters:
comparingFunction
- to apply to sorted stream- Returns:
- stream of all entries (values) ordered by given comparing function
-
-