java.lang.Object
java.util.AbstractMap<K,V>
java.util.WeakHashMap<K,V>
io.github.palexdev.materialfx.bindings.BindingsMap<K,V>
- All Implemented Interfaces:
Map<K,V>
A special
WeakHashMap that allows to retrieve the keys ordered by insertion.
Writing a LinkedWeakHashMap would have been too much work and a very hard task.
For this reason this Map simply uses a LinkedList to store the keys (wrapped in WeakReferences) by
their insertion order.
WeakHashMap this list is cleared (all null references are removed) when
major operations occur, such as: put, putAll, combine.
Allows to retrieve the first and the last keys, and also a copy of the actual LinkedList.-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
ConstructorsConstructorDescriptionBindingsMap(int initialCapacity) BindingsMap(int initialCapacity, float loadFactor) BindingsMap(Map<? extends K, ? extends V> m) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the keysLinkedListand then calls the super method.voidcombine(BindingsMap<K, V> source) Allows to combine the givenBindingsMapto this one.Adds the given key to the keysLinkedList, performsclearReferences()and then calls the super method.final voidFor each entry adds the key to the keysLinkedList, then calls the super method.voidOverridden to callputAll(Map.Entry[]).Removes the given key from the keysLinkedListand then calls the super method.voidreplaceAll(BiFunction<? super K, ? super V, ? extends V> function) UNSUPPORTEDMethods inherited from class java.util.WeakHashMap
containsKey, containsValue, entrySet, forEach, get, isEmpty, keySet, size, valuesMethods inherited from class java.util.AbstractMap
clone, equals, hashCode, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace
-
Constructor Details
-
BindingsMap
public BindingsMap() -
BindingsMap
-
BindingsMap
public BindingsMap(int initialCapacity) -
BindingsMap
public BindingsMap(int initialCapacity, float loadFactor)
-
-
Method Details
-
combine
Allows to combine the givenBindingsMapto this one.This method exists to ensure that insertion order is kept with the
LinkedListbut most importantly ensures that there are no duplicates in the list by using aLinkedHashSet. -
put
Adds the given key to the keysLinkedList, performsclearReferences()and then calls the super method. -
putAll
Overridden to callputAll(Map.Entry[]). -
putAll
For each entry adds the key to the keysLinkedList, then calls the super method. At the end performsclearReferences(). -
remove
Removes the given key from the keysLinkedListand then calls the super method. -
clear
public void clear()Clears the keysLinkedListand then calls the super method. -
replaceAll
UNSUPPORTED- Specified by:
replaceAllin interfaceMap<K,V> - Overrides:
replaceAllin classWeakHashMap<K,V>
-
unmodifiableKeysList
- Returns:
- a copy of the
LinkedListcontaining the Map's keys ordered by insertion
-
getFirstKey
- Returns:
- the first inserted key
-
getLastKey
- Returns:
- the last inserted key
-