Package eu.simuline.util
Class ListMap<K,V>
- java.lang.Object
-
- eu.simuline.util.ListMap<K,V>
-
- Type Parameters:
K- the class of keys for this map.V- the class of values for this map.
- All Implemented Interfaces:
java.util.Map<K,V>,java.util.SortedMap<K,V>
public final class ListMap<K,V> extends java.lang.Object implements java.util.SortedMap<K,V>ASortedMapwith ordering given by the ordering by which the keys are added. This is theMapcorresponding withListSet.Did not use
AbstractMap, e.g. becausekeySet()shall return more than just aSet.- Version:
- 1.0
- Author:
- Ernst Reissner
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classListMap.EntriesRepresents the set of entries of the enclosing map given byentrySet().private classListMap.EntriesIteratorClass of iterator of classListMap.Entries.private classListMap.EntryClass of entries of the encylosing map. **** I wonder whether there is no generic implementation forMap.Entry.private classListMap.KeysRepresents the key set of the enclosing map given bykeySet().private classListMap.KeysIteratorClass of iterator of classListMap.Keys.private classListMap.ValuesRepresents the values collection of the enclosing map given byvalues().private classListMap.ValuesIteratorClass of iterator of classListMap.Values.private classListMap.XIteratorCommon superclass of iterators on key set, value collection and entries set providing all methods butIterator.next().
-
Field Summary
Fields Modifier and Type Field Description private java.util.SortedSet<java.util.Map.Entry<K,V>>entrySetThe set of entries of this map returned byentrySet().private ListSet<K>keysThe set of keys of thisListMap.private java.util.SortedSet<K>keysSetThe set of keys of this map returned bykeySet().private java.util.List<V>valuesThe values of this map.private java.util.Collection<V>valuesCollThe collection of values of this map returned byvalues().
-
Constructor Summary
Constructors Modifier Constructor Description ListMap()Creates an empty list map with key set 'ordered as added' as described byListSet.sortedAsAdded().privateListMap(ListSet<K> keys, java.util.List<V> values)Creates a list map defined by the given keys and valueskeysandvalues.ListMap(java.util.Map<K,V> map)Creates an list map with the same key-value pairs asmapand with ordering 'as added'.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()java.util.Comparator<? super K>comparator()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object val)java.util.SortedSet<java.util.Map.Entry<K,V>>entrySet()booleanequals(java.lang.Object obj)KfirstKey()Vget(java.lang.Object key)inthashCode()ListMap<K,V>headMap(K toKey)booleanisEmpty()java.util.SortedSet<K>keySet()KlastKey()static voidmain(java.lang.String[] args)private static <K,V>
ListSet<K>map2keys(java.util.Map<K,V> map)Returns the key set ofmapas aListSetwith ordering 'ordered as added' as given byListSet.sortedAsAdded().private static <K,V>
java.util.List<V>map2values(java.util.Map<K,V> map)Returns the value collection ofmapas aListwith ordering given by the iteration on the key set ofmap.Vput(K key, V value)voidputAll(java.util.Map<? extends K,? extends V> other)Vremove(java.lang.Object key)private booleanremoveIdx(int idx)intsize()(package private) ListMap<K,V>subMap(int fromIdx, int toIdx)ListMap<K,V>subMap(K fromKey, K toKey)ListMap<K,V>tailMap(K fromKey)java.lang.StringtoString()java.util.Collection<V>values()
-
-
-
Field Detail
-
values
private final java.util.List<V> values
The values of this map. The according keys are inkeys.
-
valuesColl
private final java.util.Collection<V> valuesColl
The collection of values of this map returned byvalues(). Note that eachListMaphas a single values collection.
-
keysSet
private final java.util.SortedSet<K> keysSet
The set of keys of this map returned bykeySet(). Note that eachListMaphas a single key set.
-
entrySet
private final java.util.SortedSet<java.util.Map.Entry<K,V>> entrySet
The set of entries of this map returned byentrySet(). Note that eachListMaphas a single entry set.
-
-
Constructor Detail
-
ListMap
public ListMap()
Creates an empty list map with key set 'ordered as added' as described byListSet.sortedAsAdded().
-
ListMap
public ListMap(java.util.Map<K,V> map)
Creates an list map with the same key-value pairs asmapand with ordering 'as added'. If no additional keys are added, this reflects the ordering given by iterating through the key set ofmap.- See Also:
map2keys(Map),map2values(Map)
-
ListMap
private ListMap(ListSet<K> keys, java.util.List<V> values)
Creates a list map defined by the given keys and valueskeysandvalues. A key and a value correspond iff their index coincides. Thuskeysandvaluesmust have the same size. Note that the entries ofkeysdiffer pairwise, whereas this is not necessary forvalues.- Parameters:
keys- the set of keys as aListSet.values- the collection of according values as aListwith the same size askeys.- Throws:
java.lang.IllegalArgumentException- ifkeysandvaluesdiffer in size.
-
-
Method Detail
-
map2keys
private static <K,V> ListSet<K> map2keys(java.util.Map<K,V> map)
Returns the key set ofmapas aListSetwith ordering 'ordered as added' as given byListSet.sortedAsAdded(). This ordering reflects the ordering given by the iteration on the key set ofmap.
-
map2values
private static <K,V> java.util.List<V> map2values(java.util.Map<K,V> map)
Returns the value collection ofmapas aListwith ordering given by the iteration on the key set ofmap. Note that there is no documentation **** that this ordering is the same as the one of the value collectionmap#values(). ****
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(java.lang.Object val)
-
keySet
public java.util.SortedSet<K> keySet()
-
removeIdx
private boolean removeIdx(int idx)
-
comparator
public java.util.Comparator<? super K> comparator()
-
values
public java.util.Collection<V> values()
-
equals
public boolean equals(java.lang.Object obj)
-
hashCode
public int hashCode()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
main
public static void main(java.lang.String[] args)
-
-