and
Map
.
This class implements Map
, but it does not implement
List
, because both of these interfaces have a method
remove(Object)
, but in List
the method
returns boolean
while in Map
the method
returns Object
. Thus, this class can officially only
implement one of the interfaces. Choosing to implement Map
simplifies the implementation, since we can then also omit the
*All
methods from the List
interface.
Methods derived from the List
interface operate on the
keys only within the Map
.
For methods derived from the Map
interface that return
a Collection
, an Iterator
over that
Collection
will not traverse the keys in any particular
order.
In general, when you want the contents in the order in which they were
inserted, you need to use one of the List
methods. To
get to the values, use one of the Map
methods. To get
the list of values in the order in which they were inserted, you will
need to iterate over the ordered keys, and obtain the values through
the get()
method.
The implementation uses an ArrayList
to back the
List
interface and a HashMap
to back the
Map
interface.
Nested classes inherited from class java.util.Map |
java.util.Map.Entry |
Field Summary |
protected java.util.List |
_list
|
protected java.util.Map |
_map
|
Method Summary |
void |
add(int index,
java.lang.Object element)
|
boolean |
add(java.lang.Object o)
|
void |
clear()
|
boolean |
contains(java.lang.Object o)
|
boolean |
containsKey(java.lang.Object key)
|
boolean |
containsValue(java.lang.Object value)
|
java.util.Set |
entrySet()
|
java.lang.Object |
get(int index)
|
java.lang.Object |
get(java.lang.Object key)
|
int |
indexOf(java.lang.Object o)
|
boolean |
isEmpty()
|
java.util.Iterator |
iterator()
|
java.util.Set |
keySet()
The keys are not returned in any particular order. |
int |
lastIndexOf(java.lang.Object o)
|
java.util.ListIterator |
listIterator()
|
java.util.ListIterator |
listIterator(int index)
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
If the ListMap already contained the key, then
the key is moved to the end of the ordered list, and the value
in the map is replaced. |
void |
putAll(java.util.Map t)
|
java.lang.Object |
remove(int index)
|
java.lang.Object |
remove(java.lang.Object key)
Method from java.util.Map . |
java.lang.Object |
set(int index,
java.lang.Object element)
|
int |
size()
|
java.util.List |
subList(int fromIndex,
int toIndex)
|
java.lang.Object[] |
toArray()
|
java.lang.Object[] |
toArray(java.lang.Object[] a)
|
java.util.Collection |
values()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Map |
equals, hashCode |
_list
protected java.util.List _list
_map
protected java.util.Map _map
ListMap
public ListMap()
ListMap
public ListMap(int initialCapacity)
ListMap
public ListMap(int initialCapacity,
int loadFactor)
clear
public void clear()
- Specified by:
clear
in interface java.util.Map
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interface java.util.Map
size
public int size()
- Specified by:
size
in interface java.util.Map
remove
public java.lang.Object remove(java.lang.Object key)
- Method from
java.util.Map
. The same method from
java.util.List
cannot be implemented because it has
a different return type.
- Specified by:
remove
in interface java.util.Map
add
public void add(int index,
java.lang.Object element)
add
public boolean add(java.lang.Object o)
contains
public boolean contains(java.lang.Object o)
get
public java.lang.Object get(int index)
indexOf
public int indexOf(java.lang.Object o)
iterator
public java.util.Iterator iterator()
lastIndexOf
public int lastIndexOf(java.lang.Object o)
listIterator
public java.util.ListIterator listIterator()
listIterator
public java.util.ListIterator listIterator(int index)
remove
public java.lang.Object remove(int index)
set
public java.lang.Object set(int index,
java.lang.Object element)
subList
public java.util.List subList(int fromIndex,
int toIndex)
toArray
public java.lang.Object[] toArray()
toArray
public java.lang.Object[] toArray(java.lang.Object[] a)
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKey
in interface java.util.Map
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValue
in interface java.util.Map
entrySet
public java.util.Set entrySet()
- Specified by:
entrySet
in interface java.util.Map
get
public java.lang.Object get(java.lang.Object key)
- Specified by:
get
in interface java.util.Map
keySet
public java.util.Set keySet()
- The keys are not returned in any particular order. To get the keys in
the order in which they were inserted, call
iterator()
.
- Specified by:
keySet
in interface java.util.Map
put
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
- If the
ListMap
already contained the key, then
the key is moved to the end of the ordered list, and the value
in the map is replaced.
- Specified by:
put
in interface java.util.Map
putAll
public void putAll(java.util.Map t)
- Specified by:
putAll
in interface java.util.Map
values
public java.util.Collection values()
- Specified by:
values
in interface java.util.Map
Copyright ©1997, 2003, Oracle. All rights reserved.