|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.dhmp.util.AbstractMap
org.dhmp.util.HashMap
org.dhmp.util.LinkedHashMap
org.dhmp.util.LinkedHashMultiMap
Nested Class Summary | |
protected class |
LinkedHashMultiMap.EntrySet
Create an AbstractSet with custom implementations of those methods that can be overridden easily and efficiently. |
Field Summary | |
static int |
ACCESS_ORDER
|
static int |
INSERTION_ORDER
|
static int |
REVERSE_ACCESS_ORDER
|
Constructor Summary | |
LinkedHashMultiMap()
Construct a new insertion-ordered LinkedHashMultiMap with the default capacity (11) and the default load factor (0.75). |
|
LinkedHashMultiMap(int initialCapacity)
Construct a new insertion-ordered LinkedHashMultiMap with a specific inital capacity and default load factor of 0.75. |
|
LinkedHashMultiMap(int initialCapacity,
float loadFactor)
Construct a new insertion-orderd LinkedHashMultiMap with a specific inital capacity and load factor. |
|
LinkedHashMultiMap(int initialCapacity,
float loadFactor,
boolean accessOrder)
Construct a new LinkedHashMultiMap with a specific inital capacity, load factor, and ordering mode. |
|
LinkedHashMultiMap(int initialCapacity,
float loadFactor,
int accessFormat)
Construct a new LinkedHashMultiMap with a specific inital capacity, load factor, and ordering mode. |
|
LinkedHashMultiMap(java.util.Map m)
Construct a new insertion-ordered LinkedHashMultiMap from the given Map, with initial capacity the greater of the size of m or
the default of 11.
|
Method Summary | |
java.lang.Object |
add(java.lang.Object key,
java.lang.Object value)
Puts the supplied value into the Map, mapped by the supplied key. |
void |
clear()
Clears the Map so it has no keys. |
java.lang.Object |
clone()
Returns a shallow clone of this HashMap. |
boolean |
containsKey(java.lang.Object key)
Returns true if the supplied object equals() a key
in this HashMap. |
boolean |
containsValue(java.lang.Object value)
Returns true if this LinkedHashMultiMap contains a value o , such that
o.equals(value) . |
java.util.Set |
entrySet()
Returns a "set view" of this LinkedHashMultiMap's entries. |
boolean |
equals(java.lang.Object o)
Compares the specified object with this map for equality. |
org.dhmp.util.HashMap.HashEntry |
fetchEntry(java.lang.Object key)
Return the value in this Map associated with the supplied key, or null if the key maps to nothing.
|
int |
fullSize()
Returns the number of key-value mappings currently in this Map, including repetitive keys. |
java.lang.Object |
get()
Return the first value in this Map. |
java.lang.Object |
get(java.lang.Object key)
Return the value in this Map associated with the supplied key, or null if the key maps to nothing. |
org.dhmp.util.HashMap.HashEntry |
getEntry()
Return the first entry in this Map. |
org.dhmp.util.HashMap.HashEntry |
getEntry(java.lang.Object key)
Return the value in this Map associated with the supplied key, or null if the key maps to nothing. |
protected int |
getState()
|
int |
hashCode()
Returns the hash code for this map. |
boolean |
isEmpty()
Returns true if there are no key-value mappings currently in this Map. |
java.util.Set |
keySet()
Returns a "set view" of this LinkedHashMultiMap's keys. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Puts the supplied value into the Map, mapped by the supplied key. |
void |
putAll(java.util.Map m)
Copies all elements of the given map into this hashtable. |
java.lang.Object |
remove(java.lang.Object key)
Removes a single entry from the LinkedHashMultiMap and returns the value which is mapped by the supplied key. |
java.lang.Object |
removeAll(java.lang.Object key)
Removes all entries from the LinkedHashMultiMap and returns the oldest value which is mapped by the supplied key. |
protected boolean |
removeEldestEntry(java.util.Map.Entry eldest)
Returns true if this map should remove the eldest entry.
|
java.lang.Object |
removeEntry(org.dhmp.util.LinkedHashMultiMap.Entry target)
Removes a single entry from the LinkedHashMultiMap and returns the value which is mapped by the supplied key. |
protected int |
setState(int state)
|
int |
size()
Returns the number of kay-value mappings currently in this Map. |
java.lang.String |
toString()
Returns a String representation of this map. |
java.util.Collection |
values()
Returns a "collection view" (or "bag view") of this HashMap's values. |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
equals, hashCode |
Field Detail |
public static final int INSERTION_ORDER
public static final int ACCESS_ORDER
public static final int REVERSE_ACCESS_ORDER
Constructor Detail |
public LinkedHashMultiMap()
public LinkedHashMultiMap(java.util.Map m)
m
or
the default of 11.
Every element in Map m will be put into this new HashMap, in the order of m's iterator.
m
- a Map whose key / value pairs will be put into
the new HashMap. NOTE: key / value pairs
are not cloned in this constructor.
java.lang.NullPointerException
- if m is nullpublic LinkedHashMultiMap(int initialCapacity)
initialCapacity
- the initial capacity of this HashMap (>= 0)
java.lang.IllegalArgumentException
- if (initialCapacity < 0)public LinkedHashMultiMap(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacity (>= 0)loadFactor
- the load factor (> 0, not NaN)
java.lang.IllegalArgumentException
- if (initialCapacity < 0) ||
! (loadFactor > 0.0)public LinkedHashMultiMap(int initialCapacity, float loadFactor, boolean accessOrder)
initialCapacity
- the initial capacity (>=0)loadFactor
- the load factor (>0, not NaN)accessOrder
- true for access-order, false for insertion-order
java.lang.IllegalArgumentException
- if (initialCapacity < 0) ||
! (loadFactor > 0.0)public LinkedHashMultiMap(int initialCapacity, float loadFactor, int accessFormat)
initialCapacity
- the initial capacity (>=0)loadFactor
- the load factor (>0, not NaN)accessFormat
- ACCESS_ORDER, INSERTION_ORDER or REVERSE_ACCESS_ORDER
java.lang.IllegalArgumentException
- if (initialCapacity < 0) ||
! (loadFactor > 0.0)Method Detail |
public int fullSize()
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
equals()
this key. NOTE: Since the prior value could also be null, you must
first use containsKey if you want to see if you are replacing the
key's mapping.
key
- the key used to locate the valuevalue
- the value to be stored in the HashMap
add(Object, Object)
,
get(Object)
,
Object.equals(Object)
public java.lang.Object add(java.lang.Object key, java.lang.Object value)
equals()
this key. NOTE: Since the prior value could also be null, you must
first use containsKey if you want to see if you are replacing the
key's mapping.
key
- the key used to locate the valuevalue
- the value to be stored in the HashMap
add(Object, Object)
,
get(Object)
,
Object.equals(Object)
public java.lang.Object get(java.lang.Object key)
null
if the key maps to nothing. If this is an
access-ordered Map and the key is found, this performs structural
modification, moving the key to the newest end of the list. NOTE:
Since the value could also be null, you must use containsKey to
see if this key actually maps to something.
If this is an reverse-access-order, it returns the end of the list value
for the key.
key
- the key for which to fetch an associated value
add(Object, Object)
,
put(Object, Object)
,
HashMap.containsKey(Object)
public java.lang.Object get()
public org.dhmp.util.HashMap.HashEntry getEntry(java.lang.Object key)
null
if the key maps to nothing. If this is an
access-ordered Map and the key is found, this performs structural
modification, moving the key to the newest end of the list. NOTE:
Since the value could also be null, you must use containsKey to
see if this key actually maps to something.
If this is an reverse-access-order, it returns the end of the list value
for the key.
key
- the key for which to fetch an associated value
add(Object, Object)
,
put(Object, Object)
,
HashMap.containsKey(Object)
public org.dhmp.util.HashMap.HashEntry getEntry()
public org.dhmp.util.HashMap.HashEntry fetchEntry(java.lang.Object key)
null
if the key maps to nothing.
It differs from getEntry because no structural modification is performed.
If this is an reverse-access-order, it returns the end of the list value
for the key.
key
- the key for which to fetch an associated value
getEntry(Object)
public java.util.Set entrySet()
Note that the iterators for all three views, from keySet(), entrySet(), and values(), traverse the HashMap in the same sequence.
keySet()
,
HashMap.values()
public java.util.Set keySet()
HashMap.values()
,
entrySet()
public java.lang.Object removeEntry(org.dhmp.util.LinkedHashMultiMap.Entry target)
null
is returned. NOTE: Since the value
could also be null, you must use containsKey to see if you are
actually removing a mapping.
target
- the entry to be removed
public java.lang.Object remove(java.lang.Object key)
null
is returned. NOTE: Since the value
could also be null, you must use containsKey to see if you are
actually removing a mapping.
key
- the key used to locate the value to remove
public java.lang.Object removeAll(java.lang.Object key)
null
is returned. NOTE: Since the value
could also be null, you must use containsKey to see if you are
actually removing a mapping.
key
- the key used to locate the value to remove
public void clear()
public boolean containsValue(java.lang.Object value)
o
, such that
o.equals(value)
.
value
- the value to search for in this HashMap
HashMap.containsKey(Object)
public java.lang.String toString()
getKey() + "=" + getValue()
), separated by a comma and
space (", "), and surrounded by braces ('{' and '}'). This implementation
uses a StringBuffer and iterates over the entrySet to build the String.
Note that this can fail with an exception if underlying keys or
values complete abruptly in toString().
protected int getState()
protected int setState(int state)
protected boolean removeEldestEntry(java.util.Map.Entry eldest)
true
if this map should remove the eldest entry.
This method is invoked by all calls to put
and
putAll
which place a new entry in the map, providing
the implementer an opportunity to remove the eldest entry any time
a new one is added. This can be used to save memory usage of the
hashtable, as well as emulating a cache, by deleting stale entries.
For example, to keep the Map limited to 100 entries, override as follows:
private static final int MAX_ENTRIES = 100; protected boolean removeEldestEntry(Map.Entry eldest) { return size() > MAX_ENTRIES; }
Typically, this method does not modify the map, but just uses the
return value as an indication to put
whether to proceed.
However, if you override it to modify the map, you must return false
(indicating that put
should leave the modified map alone),
or you face unspecified behavior. Remember that in access-order mode,
even calling get
is a structural modification, but using
the collections views (such as keySet
) is not.
This method is called after the eldest entry has been inserted, so
if put
was called on a previously empty map, the eldest
entry is the one you just put in! The default implementation just
returns false
, so that this map always behaves like
a normal one with unbounded growth.
eldest
- the eldest element which would be removed if this
returns true. For an access-order map, this is the least
recently accessed; for an insertion-order map, this is the
earliest element inserted.
eldest
should be removedpublic int size()
size
in interface java.util.Map
Set.size()
public boolean isEmpty()
isEmpty
in interface java.util.Map
size() == 0
AbstractMap.size()
public boolean containsKey(java.lang.Object key)
equals()
a key
in this HashMap.
containsKey
in interface java.util.Map
key
- the key to search for in this HashMap
HashMap.containsValue(Object)
public void putAll(java.util.Map m)
putAll
in interface java.util.Map
m
- the map to be hashed into thisAbstractMap.put(Object, Object)
public java.lang.Object clone()
Cloneable
,
Object.clone()
public java.util.Collection values()
values
in interface java.util.Map
HashMap.keySet()
,
HashMap.entrySet()
public boolean equals(java.lang.Object o)
true
if the other object is a Map with the same mappings,
that is,o instanceof Map && entrySet().equals(((Map) o).entrySet();
equals
in interface java.util.Map
o
- the object to be compared
Set.equals(Object)
public int hashCode()
hashCode
in interface java.util.Map
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |