Methods Summary |
---|
public void | clear()
keys.clear();
values.clear();
|
public boolean | containsKey(java.lang.Object o)Return true if o is contained as a Key in this Map.
return keys.contains(o);
|
public boolean | containsValue(java.lang.Object o)Return true if o is contained as a Value in this Map.
return keys.contains(o);
|
public java.util.Set | entrySet()Returns a set view of the mappings contained in this Map.
Each element in the returned set is a Map.Entry.
NOT guaranteed fully to implement the contract of entrySet
declared in java.util.Map.
if (keys.size() != values.size())
throw new IllegalStateException(
"InternalError: keys and values out of sync");
ArrayList al = new ArrayList();
for (int i=0; i<keys.size(); i++) {
al.add(new MyMapEntry(keys.get(i), values.get(i)));
}
return new MyMapSet(al);
|
public java.lang.Object | get(java.lang.Object k)Get the object value corresponding to key k.
int i = keys.indexOf(k);
if (i == -1)
return null;
return values.get(i);
|
public boolean | isEmpty()Return true if this map is empty.
return size() == 0;
|
public java.util.Set | keySet()
return new TreeSet(keys);
|
public java.lang.Object | put(java.lang.Object k, java.lang.Object v)Put the given pair (k, v) into this map, by maintaining "keys"
in sorted order.
for (int i=0; i < keys.size(); i++) {
Object old = keys.get(i);
/* Does the key already exist? */
if (((Comparable)k).compareTo(keys.get(i)) == 0) {
keys.set(i, v);
return old;
}
/* Did we just go past where to put it?
* i.e., keep keys in sorted order.
*/
if (((Comparable)k).compareTo(keys.get(i)) == +1) {
int where = i > 0 ? i -1 : 0;
keys.add(where, k);
values.add(where, v);
return null;
}
}
// Else it goes at the end.
keys.add(k);
values.add(v);
return null;
|
public void | putAll(java.util.Map oldMap)Put all the pairs from oldMap into this map
Iterator keysIter = oldMap.keySet().iterator();
while (keysIter.hasNext()) {
Object k = keysIter.next();
Object v = oldMap.get(k);
put(k, v);
}
|
public java.lang.Object | remove(java.lang.Object k)
int i = keys.indexOf(k);
if (i == -1)
return null;
Object old = values.get(i);
keys.remove(i);
values.remove(i);
return old;
|
public int | size()Return the number of mappings in this Map.
return keys.size();
|
public java.util.Collection | values()
return values;
|