Package org.optaplanner.core.impl.util
Class FieldBasedScalingMap<K,V>
- java.lang.Object
-
- org.optaplanner.core.impl.util.FieldBasedScalingMap<K,V>
-
- All Implemented Interfaces:
Map<K,V>
public final class FieldBasedScalingMap<K,V> extends Object implements Map<K,V>
Uses a givenMap
as storage unless it is the first and only entry, in which case it uses fields. This helps avoid the overhead of creating and accessing a hash map if we only have 1 entry. This implementation is not thread-safe, regardless of the underlyingMap
. Iteration order of elements is specified by the underlyingMap
.
-
-
Constructor Summary
Constructors Constructor Description FieldBasedScalingMap(Supplier<Map<K,V>> mapSupplier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<K,V>>
entrySet()
As defined byMap.entrySet()
.void
forEach(BiConsumer<? super K,? super V> action)
V
get(Object key)
boolean
isEmpty()
Set<K>
keySet()
As defined byMap.keySet()
.V
put(K key, V value)
void
putAll(Map<? extends K,? extends V> m)
V
remove(Object key)
int
size()
String
toString()
Collection<V>
values()
As defined byMap.values()
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
keySet
public Set<K> keySet()
As defined byMap.keySet()
. May throw an exception if the iterator is used to remove an element while the map is based on a field.
-
values
public Collection<V> values()
As defined byMap.values()
. May throw an exception if the iterator is used to remove an element while the map is based on a field.
-
entrySet
public Set<Map.Entry<K,V>> entrySet()
As defined byMap.entrySet()
. May throw an exception if the iterator is used to remove an element while the map is based on a field.
-
forEach
public void forEach(BiConsumer<? super K,? super V> action)
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<K,V>
-
-