Package org.eclipse.emf.common.util
Class BasicEMap<K,V>
java.lang.Object
org.eclipse.emf.common.util.BasicEMap<K,V>
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Map.Entry<K,,V>> Collection<Map.Entry<K,,V>> List<Map.Entry<K,,V>> SequencedCollection<Map.Entry<K,,V>> EList<Map.Entry<K,,V>> EMap<K,V>
A highly extensible map implementation.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classAn iterator over the map entry data.protected classAn iterator over the map key data.protected classAn iterator over the map value data.protected classstatic interfaceAn extended implementation interface for caching hash values and for updating an entry that may be manufactured as a uninitialized instance by a factory.protected classA simple and obvious entry implementation.protected static classAn implementation class to hold the views.Nested classes/interfaces inherited from interface org.eclipse.emf.common.util.EMap
EMap.InternalMapView<K,V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected EList<BasicEMap.Entry<K, V>> The underlying list of entries.protected BasicEList<BasicEMap.Entry<K,V>>[] The array of entry lists into which the hash codes are indexed.protected intThe modification indicator used to ensure iterator integrity.protected intThe size of the map.protected BasicEMap.View<K, V> The various alternative views of the map. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDelegates todelegateEList.booleanDelegates todelegateEList.booleanaddAll(int index, Collection<? extends Map.Entry<K, V>> collection) Delegates todelegateEList.booleanaddAll(Collection<? extends Map.Entry<K, V>> collection) Delegates todelegateEList.voidclear()Delegates todelegateEList.clone()Returns a shallow copy of this map.booleanDelegates todelegateEList.booleancontainsAll(Collection<?> collection) Delegates todelegateEList.booleancontainsKey(Object key) Returns whether the key is associated with a value.booleancontainsValue(Object value) Returns whether the value is associated with a key.protected voiddidAdd(BasicEMap.Entry<K, V> entry) Called to indicate that the entry has been added.protected voiddidClear(BasicEList<BasicEMap.Entry<K, V>>[] oldEntryData) Called to indicate that the map has been cleared.protected voiddidModify(BasicEMap.Entry<K, V> entry, V oldValue) Called to indicate that the entry has an updated value.protected voiddidRemove(BasicEMap.Entry<K, V> entry) Called to indicate that the entry has been removed.protected voiddoClear()Clears the map.protected voiddoMove(BasicEMap.Entry<K, V> entry) Increments the modification count.protected voiddoPut(BasicEMap.Entry<K, V> entry) Adds the new entry to the map.protected voiddoRemove(BasicEMap.Entry<K, V> entry) Removes the entry from the map.protected voidEnsures that the entry data is created and is populated with contents of the delegate list.protected BasicEMap.Entry<K, V> entryForKey(int index, int hash, Object key) Called to return the entry given the index, the hash, and the key.protected intentryIndexForKey(int index, int hash, Object key) Called to return the entry list index given the index, the hash, and the key.entrySet()Returns a set view of the entries.booleanget(int index) Delegates todelegateEList.Returns the value associated with the key.protected booleangrow(int minimumCapacity) Grows the capacity of the map to ensure that no additional growth is needed until the size exceeds the specified minimum capacity.inthashCode()protected intCalled to return the hash code of the key.protected intindexOf(int hash) Called to return the entry data index corresponding to the hash code.intDelegates todelegateEList.intindexOfKey(Object key) Returns the index in the list of the entry with the given key, or-1, if there is no such entry.protected voidInitializes thedelegateEList.booleanisEmpty()Returns whether the map has zero size.iterator()Delegates todelegateEList.keySet()Returns a set view of the keys of the entries.intlastIndexOf(Object object) Delegates todelegateEList.Delegates todelegateEList.listIterator(int index) Delegates todelegateEList.map()Returns a map view.move(int targetIndex, int sourceIndex) Delegates todelegateEList.voidDelegates todelegateEList.protected BasicEMap.Entry<K, V> Returns a new entry.protected BasicEList<BasicEMap.Entry<K,V>>[] newEntryData(int capacity) Returns new allocated entry data storage.protected BasicEList<BasicEMap.Entry<K, V>> newList()Returns a new allocated list of entries.Associates the key with the value and returns the value previously associated with the key, ornull.voidPuts eachMap.Entryof the given map into this one.voidPuts eachMap.Entryof the given map into this one.protected VputEntry(BasicEMap.Entry<K, V> entry, V value) Sets the value of the entry, and returns the former value.remove(int index) Delegates todelegateEList.booleanDelegates todelegateEList.booleanremoveAll(Collection<?> collection) Delegates todelegateEList.protected VremoveEntry(int index, int entryIndex) Removes the fully indexed entry from the map and returns it's value.Disassociates the key from its value, and returns the value formerly associated with the key.protected VResolves the value associated with the key and returns the result.booleanretainAll(Collection<?> collection) Delegates todelegateEList.Delegates todelegateEList.intsize()Returns the number of entries in the map.subList(int start, int end) Delegates todelegateEList.Object[]toArray()Delegates todelegateEList.<T> T[]toArray(T[] array) Delegates todelegateEList.toString()Delegates todelegateEList.protected booleanReturns whetherequalsrather than==should be used to compare keys.protected booleanReturns whetherequalsrather than==should be used to compare values.protected voidvalidateKey(K key) Validates a new key.protected voidvalidateValue(V value) Validates a new key.values()Returns a collection view the values of the entries.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, replaceAll, reversed, sort, spliterator
-
Field Details
-
delegateEList
The underlying list of entries. -
size
protected transient int sizeThe size of the map. -
entryData
The array of entry lists into which the hash codes are indexed. -
modCount
protected transient int modCountThe modification indicator used to ensure iterator integrity. -
view
The various alternative views of the map.
-
-
Constructor Details
-
BasicEMap
public BasicEMap()Creates an empty instance. -
BasicEMap
public BasicEMap(int initialCapacity) Creates an empty instance with the given capacity.- Parameters:
initialCapacity- the initial capacity of the map before it must grow.- Throws:
IllegalArgumentException- if theinitialCapacityis negative.
-
BasicEMap
Creates an instance that is a copy of the map.- Parameters:
map- the initial contents of the map.
-
-
Method Details
-
initializeDelegateEList
protected void initializeDelegateEList()Initializes thedelegateEList. This implementation illustrates the precise pattern that is used to delegate a list implementation's callback methods to the map implementation. -
newEntryData
Returns new allocated entry data storage. Clients may override this to create typed storage, but it's not likely. The cost of type checking via a typed array is negligible.- Parameters:
capacity- the capacity of storage needed.- Returns:
- new entry data storage.
-
ensureEntryDataExists
protected void ensureEntryDataExists()Ensures that the entry data is created and is populated with contents of the delegate list. -
newList
Returns a new allocated list of entries. Clients may override this to create typed storage. The cost of type checking via a typed array is negligible. The type must be kept in synch withnewEntry.- Returns:
- a new list of entries.
- See Also:
-
newEntry
Returns a new entry. The key isvalidatedand the value isvalidated. Clients may override this to create typed storage. The type must be kept in synch withnewEntry.- Parameters:
hash- the cached hash code of the key.key- the key.value- the value.- Returns:
- a new entry.
- See Also:
-
putEntry
Sets the value of the entry, and returns the former value. The value isvalidated.- Parameters:
entry- the entry.value- the value.- Returns:
- the former value, or
null.
-
useEqualsForKey
protected boolean useEqualsForKey()Returns whetherequalsrather than==should be used to compare keys. The default is to returntruebut clients can optimize performance by returningfalse. The performance difference is highly significant.- Returns:
- whether
equalsrather than==should be used to compare keys.
-
useEqualsForValue
protected boolean useEqualsForValue()Returns whetherequalsrather than==should be used to compare values. The default is to returntruebut clients can optimize performance by returningfalse. The performance difference is highly significant.- Returns:
- whether
equalsrather than==should be used to compare values.
-
resolve
Resolves the value associated with the key and returns the result. This implementation simply returns thevalue; clients can use this to transform objects as they are fetched.- Parameters:
key- the key of an entry.value- the value of an entry.- Returns:
- the resolved value.
-
validateKey
Validates a new key. This implementation does nothing, but clients may throw runtime exceptions in order to handle constraint violations.- Parameters:
key- the new key.- Throws:
IllegalArgumentException- if a constraint prevents the object from being added.
-
validateValue
Validates a new key. This implementation does nothing, but clients may throw runtime exceptions in order to handle constraint violations.- Parameters:
value- the new value.- Throws:
IllegalArgumentException- if a constraint prevents the object from being added.
-
didAdd
Called to indicate that the entry has been added. This implementation does nothing; clients can use this to monitor additions to the map.- Parameters:
entry- the added entry.
-
didModify
Called to indicate that the entry has an updated value. This implementation does nothing; clients can use this to monitor value changes in the map.- Parameters:
entry- the new entry.
-
didRemove
Called to indicate that the entry has been removed. This implementation does nothing; clients can use this to monitor removals from the map.- Parameters:
entry- the removed entry.
-
didClear
Called to indicate that the map has been cleared. This implementation does callsdidRemovefor each entry; clients can use this to monitor clearing of the map.- Parameters:
oldEntryData- the removed entries.
-
size
public int size()Returns the number of entries in the map. -
isEmpty
public boolean isEmpty()Returns whether the map has zero size. -
indexOfKey
Description copied from interface:EMapReturns the index in the list of the entry with the given key, or-1, if there is no such entry.- Specified by:
indexOfKeyin interfaceEMap<K,V> - Parameters:
key- a key.- Returns:
- the index of the entry with the given key.
-
containsKey
Description copied from interface:EMapReturns whether the key is associated with a value.- Specified by:
containsKeyin interfaceEMap<K,V> - Parameters:
key- a key associated with a value.- Returns:
- whether the key is associated with a value.
-
containsValue
Description copied from interface:EMapReturns whether the value is associated with a key.- Specified by:
containsValuein interfaceEMap<K,V> - Parameters:
value- a value associated with a key.- Returns:
- whether the value is associated with a key.
-
get
Description copied from interface:EMapReturns the value associated with the key. The key, the value, or both may benull. -
put
Description copied from interface:EMapAssociates the key with the value and returns the value previously associated with the key, ornull. The key, the value, or both may benull. Either the existing entry is updated, or a new entry is added to the end of the list. -
doPut
Adds the new entry to the map.- Parameters:
entry- the new entry.
-
removeKey
Description copied from interface:EMapDisassociates the key from its value, and returns the value formerly associated with the key. An entry is removed from the list, if the key is found. -
doRemove
Removes the entry from the map.- Parameters:
entry- an entry in the map.
-
removeEntry
Removes the fully indexed entry from the map and returns it's value.- Parameters:
index- the index in the entry dataentryIndex- the index in the list of entries.- Returns:
- the value of the entry.
-
putAll
Description copied from interface:EMapPuts eachMap.Entryof the given map into this one. -
putAll
Description copied from interface:EMapPuts eachMap.Entryof the given map into this one. -
doClear
protected void doClear()Clears the map. -
doMove
Increments the modification count. -
clone
Returns a shallow copy of this map. -
map
Description copied from interface:EMapReturns a map view. -
keySet
Description copied from interface:EMapReturns a set view of the keys of the entries. -
values
Description copied from interface:EMapReturns a collection view the values of the entries. -
entrySet
Description copied from interface:EMapReturns a set view of the entries. -
hashOf
Called to return the hash code of the key.- Parameters:
key- the key.- Returns:
- the hash code of the object.
-
indexOf
protected int indexOf(int hash) Called to return the entry data index corresponding to the hash code.- Parameters:
hash- the hash code.- Returns:
- the index corresponding to the hash code.
-
entryForKey
Called to return the entry given the index, the hash, and the key.- Parameters:
index- the entry data index of the key.hash- the hash code of the key.key- the key.- Returns:
- the entry.
-
entryIndexForKey
Called to return the entry list index given the index, the hash, and the key.- Parameters:
index- the entry data index of the key.hash- the hash code of the key.key- the key.- Returns:
- the entry list index.
-
grow
protected boolean grow(int minimumCapacity) Grows the capacity of the map to ensure that no additional growth is needed until the size exceeds the specified minimum capacity. -
contains
Delegates todelegateEList. -
containsAll
Delegates todelegateEList.- Specified by:
containsAllin interfaceCollection<K>- Specified by:
containsAllin interfaceList<K>
-
indexOf
Delegates todelegateEList. -
lastIndexOf
Delegates todelegateEList.- Specified by:
lastIndexOfin interfaceList<K>
-
toArray
Delegates todelegateEList. -
toArray
public <T> T[] toArray(T[] array) Delegates todelegateEList. -
get
Delegates todelegateEList. -
set
Delegates todelegateEList. -
add
Delegates todelegateEList. -
add
Delegates todelegateEList. -
addAll
Delegates todelegateEList. -
addAll
Delegates todelegateEList. -
remove
Delegates todelegateEList. -
removeAll
Delegates todelegateEList. -
remove
Delegates todelegateEList. -
retainAll
Delegates todelegateEList. -
clear
public void clear()Delegates todelegateEList. -
move
Delegates todelegateEList. -
move
Delegates todelegateEList. -
iterator
Delegates todelegateEList. -
listIterator
Delegates todelegateEList.- Specified by:
listIteratorin interfaceList<K>
-
listIterator
Delegates todelegateEList.- Specified by:
listIteratorin interfaceList<K>
-
subList
Delegates todelegateEList. -
hashCode
public int hashCode() -
equals
-
toString
Delegates todelegateEList.
-