com.arsdigita.util
Class SequentialMap

java.lang.Object
  extended byjava.util.AbstractMap
      extended bycom.arsdigita.util.SequentialMap
All Implemented Interfaces:
Map
Direct Known Subclasses:
SequentialMap

public class SequentialMap
extends AbstractMap
implements Map

A map that keeps its entries in a fixed sequence. All iterators returned by this class, for example by entrySet().iterator(), are guaranteed to return the entries in the order in which they were put in the map. This implementation allows null for both the key or the associated value for a map entry.

Almost all of the map operations, for example get or containsKey require time linear in the size of the map, making this map only suitable for small map sizes.

Version:
$Revision: #8 $ $Date: 2004/04/07 $
Author:
David Lutterkort

Nested Class Summary
 
Nested classes inherited from class java.util.Map
Map.Entry
 
Field Summary
static String versionId
           
 
Constructor Summary
SequentialMap()
           Creates an empty SequentialMap.
 
Method Summary
 void clear()
           Removes all mappings from this map.
 boolean containsKey(Object key)
           Returns true if this map contains a mapping for the specified key.
 boolean containsValue(Object value)
           Return true if the map maps one or more keys to the specified value.
 Set entrySet()
           Returns a set view of the mappings contained in this map.
 Object get(int index)
           Returns the value which is stored at the specified sequential position in the map.
 Object get(Object key)
           Returns the value to which this map maps the specified key.
 Object getKey(int index)
           Returns the key which is stored at the specified sequential position in the map.
 int indexOf(Object key)
           Index of the entry with the given key.
 Object put(Object key, Object value)
          Associates the specified value with the specified key in this map.
 Object remove(Object key)
           Removes the mapping for this key from this map if present.
 int size()
           Return the number of entries in the map.
 Object update(Object key, Object value)
           Update an existing key-value pair.
 
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, isEmpty, keySet, putAll, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode, isEmpty, keySet, putAll, values
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

SequentialMap

public SequentialMap()

Creates an empty SequentialMap.

Method Detail

size

public int size()

Return the number of entries in the map.

Specified by:
size in interface Map
Returns:
int the number of entries.

indexOf

public int indexOf(Object key)

Index of the entry with the given key. key may be null.

Requires time linear in the size of the map.

Parameters:
key - the key to find.
Returns:
int the index with key key or -1 if no such entry exists.

containsValue

public boolean containsValue(Object value)

Return true if the map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that (value==null ? v==null : value.equals(v)).

Requires time linear in the size of the map

Specified by:
containsValue in interface Map
Parameters:
value - value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to the specified value.

containsKey

public boolean containsKey(Object key)

Returns true if this map contains a mapping for the specified key.

Requires time linear in the size of the map.

Specified by:
containsKey in interface Map
Parameters:
key - key whose presence in this map is to be tested.
Returns:
boolean true if this map contains a mapping for the specified key.

get

public Object get(Object key)

Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Requires time linear in the size of the map.

Specified by:
get in interface Map
Parameters:
key - key whose associated value is to be returned.
Returns:
Object the value to which this map maps the specified key, or null if the map contains no mapping for this key.

get

public Object get(int index)

Returns the value which is stored at the specified sequential position in the map. May throw an IndexOutOfBoundsException if (index < 0 || index >= size()).

Requires constant time.

Parameters:
index - The index of the element to return.
Returns:
Object The element at the specified index.

getKey

public Object getKey(int index)

Returns the key which is stored at the specified sequential position in the map. May throw an IndexOutOfBoundsException if (index < 0 || index >= size()).

Requires constant time.

Parameters:
index - The index of the element to return.
Returns:
Object The key of the element at the specified index.

put

public Object put(Object key,
                  Object value)
Associates the specified value with the specified key in this map. The new entry is appended at the end of the map. If an entry with the same key already exists, it is removed first. To change the value of an existing key-value pair without changing the position of the key, use update.

Requires time linear in the size of the map

Specified by:
put in interface Map
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
Object The previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key.
See Also:
update

update

public Object update(Object key,
                     Object value)

Update an existing key-value pair. If an entry with key key already exists, it is replaced with the new association without changing the place in which the key appears in the sequence of keys. If no such entry exists, it is appended at the end.

Requires time linear in the size of the map.

Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
Object The previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key.
See Also:
put

remove

public Object remove(Object key)

Removes the mapping for this key from this map if present.

Specified by:
remove in interface Map
Parameters:
key - key whose mapping is to be removed from the map.
Returns:
Object The previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key.

clear

public void clear()

Removes all mappings from this map.

Specified by:
clear in interface Map

entrySet

public Set entrySet()

Returns a set view of the mappings contained in this map. Each element in the returned set is a Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Specified by:
entrySet in interface Map
Returns:
Set A set view of the mappings contained in this map.


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC