Package de.alpharogroup.collections.map
Class InsertionOrderMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<K,V>
-
- java.util.LinkedHashMap<K,V>
-
- de.alpharogroup.collections.map.InsertionOrderMap<K,V>
-
- Type Parameters:
K- the generic type of keys maintained by this mapV- the generic type of mapped values
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<K,V>
public class InsertionOrderMap<K,V> extends java.util.LinkedHashMap<K,V>The classInsertionOrderMapoverwrites the put-method from the LinkedHashMap. That inserts the value to the right order it was inserted in the Map. Note that the difference in the LinkedHashMap is the order does not change if we put the same key with a new value. In this class the order changes when we put a new value with the same key.- See Also:
LinkedHashMap, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description InsertionOrderMap()Constructs an empty insertion-orderedInsertionOrderMapinstance with a default capacity (16) and load factor (0.75).InsertionOrderMap(int initialCapacity)Constructs an empty insertion-orderedInsertionOrderMapinstance with the specified initial capacity and a default load factor (0.75).InsertionOrderMap(int initialCapacity, float loadFactor)Constructs an empty insertion-orderedInsertionOrderMapinstance with the specified initial capacity and load factor.InsertionOrderMap(int initialCapacity, float loadFactor, boolean accessOrder)Constructs an emptyInsertionOrderMapinstance with the specified initial capacity, load factor and ordering mode.InsertionOrderMap(java.util.Map<? extends K,? extends V> m)Constructs an insertion-orderedInsertionOrderMapinstance with the same mappings as the specified map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vput(K key, V value)Associates the specified value with the specified key in this map.-
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values
-
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, size
-
-
-
-
Constructor Detail
-
InsertionOrderMap
public InsertionOrderMap()
Constructs an empty insertion-orderedInsertionOrderMapinstance with a default capacity (16) and load factor (0.75).
-
InsertionOrderMap
public InsertionOrderMap(int initialCapacity)
Constructs an empty insertion-orderedInsertionOrderMapinstance with the specified initial capacity and a default load factor (0.75).- Parameters:
initialCapacity- the initial capacity.- Throws:
java.lang.IllegalArgumentException- if the initial capacity is negative.
-
InsertionOrderMap
public InsertionOrderMap(int initialCapacity, float loadFactor)Constructs an empty insertion-orderedInsertionOrderMapinstance with the specified initial capacity and load factor.- Parameters:
initialCapacity- the initial capacity.loadFactor- the load factor.- Throws:
java.lang.IllegalArgumentException- if the initial capacity is negative or the load factor is nonpositive.
-
InsertionOrderMap
public InsertionOrderMap(int initialCapacity, float loadFactor, boolean accessOrder)Constructs an emptyInsertionOrderMapinstance with the specified initial capacity, load factor and ordering mode.- Parameters:
initialCapacity- the initial capacity.loadFactor- the load factor.accessOrder- the ordering mode - true for access-order, false for insertion-order.- Throws:
java.lang.IllegalArgumentException- if the initial capacity is negative or the load factor is nonpositive.
-
InsertionOrderMap
public InsertionOrderMap(java.util.Map<? extends K,? extends V> m)
Constructs an insertion-orderedInsertionOrderMapinstance with the same mappings as the specified map. The InsertionOrderMap instance is created with a a default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified map.- Parameters:
m- the map whose mappings are to be placed in this map.- Throws:
java.lang.NullPointerException- if the specified map is null.
-
-
Method Detail
-
put
public V put(K key, V value)
Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is removed and then insert new with the same key and the new value. That inserts the value to the right order it was inserted in the Map. Note that the difference in the LinkedHashMap is the order does not change if we put the same key with a new value. In this class the order changes when we put a new value with the same key.- Specified by:
putin interfacejava.util.Map<K,V>- Overrides:
putin classjava.util.HashMap<K,V>- Parameters:
key- key with which the specified value is to be associated.value- value to be associated with the specified key.- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the HashMap previously associated null with the specified key.
-
-