|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.emf.compare.util.EMFCompareMap<K,V>
K
- Specifies the keys' class for this Map.V
- Specifies the values' class for this Map.public class EMFCompareMap<K,V>
Implementation of a map that stores its content using an hash table.
This implementation ensures the capacity of this Map is a prime number at all time.
Field Summary | |
---|---|
protected static int |
DEFAULT_INITIAL_CAPACITY
Default value used as the initial capacity for a Map. |
protected static float |
DEFAULT_LOAD_FACTOR
The load factor used when none specified in constructor |
protected int |
freeSlots
Current number of free buckets this Map holds. |
protected K[] |
keys
Keys of this Map's entries. |
protected float |
loadFactor
Load factor of this Map. |
protected static float |
MINIMUM_LOAD_FACTOR
Minimal allowed load factor for the map. |
protected int |
nextPrimeIndex
Index of the next prime in the primes list. |
protected static java.lang.Object |
NULL_KEY
Object used as key for the null key. |
protected static java.lang.Object |
REMOVED_ENTRY
Object used as key for the "removed" entries of this Map. |
protected int |
threshold
Threshold for resizing. |
protected int |
usedSlots
Current number of non-empty slots. |
protected V[] |
values
Values contained within this Map. |
Constructor Summary | |
---|---|
EMFCompareMap()
Constructs an empty EMFCompareMap with the default initial capacity (31) and the default
load factor (0.75). |
|
EMFCompareMap(int initialCapacity)
Constructs an empty EMFCompareMap with the specified initial capacity and the default load
factor (0.75). |
|
EMFCompareMap(int initialCapacity,
float theLoadFactor)
Constructs an empty EMFCompareMap with the specified initial capacity and load factor.This
class will automatically use as the Map's initial
capacity if initialCapacity is lower. |
|
EMFCompareMap(java.util.Map<K,V> map)
Construcs a EMFCompareMap populated by the entries of map . |
Method Summary | |
---|---|
protected int |
capacity()
Returns the current capacity of the Map. |
protected void |
changeCapacity(int newCapacity)
Modifies the capacity of this Map. |
protected void |
checkCapacity(int desiredSlots)
Ensures the map has sufficient empty slots to hold desiredSlots additional elements and
resizes it if needed. |
void |
clear()
Removes all mappings from this Map. |
java.lang.Object |
clone()
Returns a copy of this Map containing all its elements. |
boolean |
containsKey(java.lang.Object key)
Returns True if the Map contains a mapping for the specified key. |
boolean |
containsValue(java.lang.Object value)
Checks for a mapping to the specified value in the Map. |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
|
protected boolean |
equal(java.lang.Object obj1,
java.lang.Object obj2)
Returns True if the two object are equal. |
boolean |
equals(java.lang.Object another)
|
V |
get(java.lang.Object key)
Retrieves the value to which the specified key is mapped. |
protected int |
getNearestPrime(int number)
Finds the nearest pseudo-prime greater than number . |
int |
hashCode()
|
protected int |
indexOf(java.lang.Object key)
Determines the index of the specified key in the keys array. |
protected int |
insertionIndexFor(K key)
Returns the index at which key can be inserted. |
boolean |
isEmpty()
|
java.util.Set<K> |
keySet()
|
protected void |
postInsert(boolean usedFreeSlot)
Called after an insert to update the used and free slots information and rehash the map if needed. |
V |
put(K key,
V value)
Associates the specified key with the specified value in the Map. |
void |
putAll(java.util.Map<? extends K,? extends V> map)
|
V |
remove(java.lang.Object key)
Removes the mapping for this key from this Map if present. |
protected java.util.Map.Entry<K,V> |
removeEntry(java.lang.Object e)
Removes the specified entry from this Map. |
protected void |
removeEntryForIndex(int index)
Removes the mapping at index from this Map. |
protected void |
resize(int newCapacity)
Rehashes the content of this Map into a new Array with a larger capacity. |
int |
size()
|
java.lang.String |
toString()
Returns a String representation of this Map. |
java.util.Collection<V> |
values()
|
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final int DEFAULT_INITIAL_CAPACITY
protected static final float DEFAULT_LOAD_FACTOR
protected static final float MINIMUM_LOAD_FACTOR
protected static final java.lang.Object NULL_KEY
null
key.
protected static final java.lang.Object REMOVED_ENTRY
protected int freeSlots
protected transient K[] keys
protected float loadFactor
protected int nextPrimeIndex
protected int threshold
protected transient int usedSlots
protected transient V[] values
Constructor Detail |
---|
public EMFCompareMap()
EMFCompareMap
with the default initial capacity (31) and the default
load factor (0.75).
public EMFCompareMap(int initialCapacity)
EMFCompareMap
with the specified initial capacity and the default load
factor (0.75). This class will automatically use
as the
Map's initial capacity if initialCapacity
is lower.
initialCapacity
- Initial capacity of the Map.public EMFCompareMap(int initialCapacity, float theLoadFactor)
EMFCompareMap
with the specified initial capacity and load factor.This
class will automatically use
as the Map's initial
capacity if initialCapacity
is lower.
initialCapacity
- Initial capacity of the Map.theLoadFactor
- Load factor to apply to this Map.public EMFCompareMap(java.util.Map<K,V> map)
EMFCompareMap
populated by the entries of map
.
map
- The map whose mappings are to be placed in this map.Method Detail |
---|
public void clear()
clear
in interface java.util.Map<K,V>
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean containsKey(java.lang.Object key)
True
if the Map contains a mapping for the specified key.
containsKey
in interface java.util.Map<K,V>
key
- The key whose presence in this Map is to be tested.
True
if the Map contains a mapping for key
, False
otherwise.public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<K,V>
value
- Value whose presence is to be tested.
True
if the Map contains a mapping to value
, False
otherwise.public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
entrySet
in interface java.util.Map<K,V>
Map.entrySet()
public boolean equals(java.lang.Object another)
equals
in interface java.util.Map<K,V>
equals
in class java.lang.Object
Object.equals(java.lang.Object)
public V get(java.lang.Object key)
get
in interface java.util.Map<K,V>
key
- The key whose associated value is to be returned.
key
, null
if none.public int hashCode()
hashCode
in interface java.util.Map<K,V>
hashCode
in class java.lang.Object
Object.hashCode()
public boolean isEmpty()
isEmpty
in interface java.util.Map<K,V>
Map.isEmpty()
public java.util.Set<K> keySet()
keySet
in interface java.util.Map<K,V>
Map.keySet()
public V put(K key, V value)
put
in interface java.util.Map<K,V>
key
- Key with which the value will be associated.value
- Value to associate with the key.
key
. Null
if there were none or
null
was associated.Map.put(java.lang.Object, java.lang.Object)
public void putAll(java.util.Map<? extends K,? extends V> map)
putAll
in interface java.util.Map<K,V>
Map.putAll(java.util.Map)
public V remove(java.lang.Object key)
remove
in interface java.util.Map<K,V>
key
- Key whose mapping is to be removed.
key
.public int size()
size
in interface java.util.Map<K,V>
Map.size()
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.Collection<V> values()
values
in interface java.util.Map<K,V>
Map.values()
protected int capacity()
protected void changeCapacity(int newCapacity)
newCapacity
- Capacity from which to compute the maximum capacity and the new number of free slots.protected void checkCapacity(int desiredSlots)
desiredSlots
additional elements and
resizes it if needed.
desiredSlots
- Desired number of additional elements.protected boolean equal(java.lang.Object obj1, java.lang.Object obj2)
True
if the two object are equal.
obj1
- First of the objects to compare.obj2
- Second of the objects to compare.
True
if the two object are equal, False
otherwise.protected int getNearestPrime(int number)
number
. Based on Rabin-Miller primality test.
number
- Number we will use as a starting point to find a greater prime.
number
protected int indexOf(java.lang.Object key)
keys
array.
key
- Key whose index is to be fetched.
-1
if inexistant.protected int insertionIndexFor(K key)
key
can be inserted. If such a key already exists, returns its
negative value minus 1.
key
- Key to be inserted.
key
can be inserted. If such a key already exists, returns its
negative value minus 1.protected void postInsert(boolean usedFreeSlot)
usedFreeSlot
- Indicates whether the insert used up a free slot.protected java.util.Map.Entry<K,V> removeEntry(java.lang.Object e)
e
- Entry to be removed from the Map.
protected void removeEntryForIndex(int index)
index
from this Map.
index
- Index of the mapping to be removed.protected void resize(int newCapacity)
newCapacity
- New capacity of the Map.
|
Copyright 2006 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |