edu.neu.ccs.quick
Class StringObjectMap

java.lang.Object
  extended byedu.neu.ccs.quick.StringObjectMap

public final class StringObjectMap
extends Object

StringObjectMap encapsulates a structure that maintains a collection of String and Object pairs in such a way that the original order of pair entry is preserved and it is efficient to map a string to an object and vice versa.

Since:
2.3
Version:
2.3

Field Summary
private  QuickHashMap objectToStringMap
          The object to string map.
private  QuickVector pairList
          The vector of string-object pairs in order.
private  QuickTreeMap stringToObjectMap
          The string to object map.
 
Constructor Summary
StringObjectMap()
          The default constructor.
StringObjectMap(Object[][] pairs)
          The constructor with an array of string-object pairs as a 2-dimensional array of Object.
StringObjectMap(StringObjectPair[] pairs)
          The constructor with an array of StringObjectPairs.
 
Method Summary
 boolean addPair(int index, String string, Object object)
          Adds the given String and Object pair to the StringObjectMap at the given index.
 boolean addPair(int index, StringObjectPair pair)
          Adds the given StringObjectPair pair to the StringObjectMap at the given index.
 boolean addPair(String string, Object object)
          Adds the given String and Object pair to the StringObjectMap.
 boolean addPair(StringObjectPair pair)
          Adds the given StringObjectPair pair to the StringObjectMap.
 void addPairs(Object[][] array)
          Adds an array of string-object pairs to the map.
 void addPairs(StringObjectPair[] pairs)
          Adds an array of StringObjectPair pairs to the map.
 void clear()
          Clear the map of all strings and objects.
 boolean containsObject(Object object)
          Returns true if this map contains the Object.
 boolean containsString(String string)
          Returns true if this map contains the String.
 Object getObject(int index)
          Returns the Object at the given index in order of entry into the map; or null if the index is out of bounds.
 Object getObject(String string)
          Returns the Object associated with the given String or null if no association is found.
 Object[] getObjects()
          Returns as an array the Objects in this map in order of entry into the map.
 StringObjectPair getPair(int index)
          Returns the StringObjectPair pair at the given index in order of entry into the map; or null if the index is out of bounds.
 Object[] getSortedObjects()
          Returns as an array the Objects in this map sorted in order of their corresponding strings order.
 StringObjectPair[] getSortedStringObjectPairs()
          Returns as an array the StringObjectPair pairs in this map sorted in order of their corresponding strings order.
 String[] getSortedStrings()
          Returns as an array the Strings in this map in sorted order.
 String getString(int index)
          Returns the String at the given index in order of entry into the map; or null if the index is out of bounds.
 String getString(Object object)
          Returns the String associated with the given Object or null if no association is found.
 StringObjectPair[] getStringObjectPairs()
          Returns as an array the StringObjectPair pairs in this map in order of entry into the map.
 String[] getStrings()
          Returns as an array the Strings in this map in order of entry into the map.
 StringObjectPair remove(int index)
          Removes and returns the pair corresponding to the given index in order of entry in the map provided that the index is in bounds; otherwise returns null.
 StringObjectPair removeByObject(Object object)
          Removes and returns a pair corresponding to the given Object object provided that the object is in the map; otherwise returns null.
 StringObjectPair removeByString(String string)
          Removes and returns a pair corresponding to the given String string provided that the string is in the map; otherwise returns null.
 void setPairs(Object[][] array)
          Clears the map and adds an array of string-object pairs to the map.
 void setPairs(StringObjectPair[] pairs)
          Clears the map and adds an array of StringObjectPair pairs to the map.
 int size()
          Returns the number of string-object pairs in this map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stringToObjectMap

private QuickTreeMap stringToObjectMap
The string to object map.


objectToStringMap

private QuickHashMap objectToStringMap
The object to string map.


pairList

private QuickVector pairList
The vector of string-object pairs in order.

Constructor Detail

StringObjectMap

public StringObjectMap()
The default constructor.

See Also:
StringObjectMap(Object[][]), StringObjectMap(StringObjectPair[])

StringObjectMap

public StringObjectMap(Object[][] pairs)

The constructor with an array of string-object pairs as a 2-dimensional array of Object.

Parameters:
pairs - the array of string-object pairs
See Also:
StringObjectMap(), StringObjectMap(StringObjectPair[])

StringObjectMap

public StringObjectMap(StringObjectPair[] pairs)

The constructor with an array of StringObjectPairs.

Parameters:
pairs - the array of string-object pairs
See Also:
StringObjectMap(), StringObjectMap(StringObjectPair[])
Method Detail

addPair

public boolean addPair(String string,
                       Object object)

Adds the given String and Object pair to the StringObjectMap.

The string and object must both be non-null or else does nothing.

Neither the string nor the object can already appear in the corresponding slot of this map. Does nothing if such a duplication is detected.

Parameters:
string - the string to enter into the map
object - the associated object to enter into the map
Returns:
whether or not the operation was successful
See Also:
addPair(StringObjectPair), addPair(int, String, Object), addPair(int, StringObjectPair)

addPair

public boolean addPair(StringObjectPair pair)

Adds the given StringObjectPair pair to the StringObjectMap.

If the pair is null then does nothing.

Neither the string nor the object in this pair can already appear in the corresponding slot of this map. Does nothing if such a duplication is detected.

Parameters:
pair - the string-object pair to enter into the map
Returns:
whether or not the operation was successful
See Also:
addPair(String, Object), addPair(int, String, Object), addPair(int, StringObjectPair)

addPair

public boolean addPair(int index,
                       String string,
                       Object object)

Adds the given String and Object pair to the StringObjectMap at the given index.

The string and object must both be non-null or else does nothing.

Neither the string nor the object can already appear in the corresponding slot of this map. Does nothing if such a duplication is detected.

Does nothing if (index < 0) or if (index > size()).

Parameters:
index - the insert position
string - the string to enter into the map
object - the associated object to enter into the map
Returns:
whether or not the operation was successful
See Also:
addPair(String, Object), addPair(StringObjectPair), addPair(int, StringObjectPair)

addPair

public boolean addPair(int index,
                       StringObjectPair pair)

Adds the given StringObjectPair pair to the StringObjectMap at the given index.

If the pair is null then does nothing.

Neither the string nor the object in this pair can already appear in the corresponding slot of this map. Does nothing if such a duplication is detected.

Does nothing if (index < 0) or if (index > size()).

Parameters:
index - the insert position
pair - the string-object pair to enter into the map
Returns:
whether or not the operation was successful
See Also:
addPair(String, Object), addPair(StringObjectPair), addPair(int, String, Object)

addPairs

public void addPairs(Object[][] array)

Adds an array of string-object pairs to the map.

Parameters:
array - the array of string-object pairs
See Also:
addPairs(StringObjectPair[])

addPairs

public void addPairs(StringObjectPair[] pairs)

Adds an array of StringObjectPair pairs to the map.

Parameters:
pairs - the array of string-object pairs
See Also:
addPairs(Object[][])

setPairs

public void setPairs(Object[][] array)

Clears the map and adds an array of string-object pairs to the map.

If array is null, then only clears.

Parameters:
array - the array of string-object pairs

setPairs

public void setPairs(StringObjectPair[] pairs)

Clears the map and adds an array of StringObjectPair pairs to the map.

If pairs is null, then only clears.

Parameters:
pairs - the array of string-object pairs

remove

public StringObjectPair remove(int index)

Removes and returns the pair corresponding to the given index in order of entry in the map provided that the index is in bounds; otherwise returns null.

Parameters:
index - the index of the pair
Returns:
the pair at the given index or null
See Also:
removeByString(String), removeByObject(Object)

removeByString

public StringObjectPair removeByString(String string)

Removes and returns a pair corresponding to the given String string provided that the string is in the map; otherwise returns null.

Parameters:
string - the string association to remove
Returns:
a pair equal to the one associated to the string or null
See Also:
remove(int), removeByObject(Object)

removeByObject

public StringObjectPair removeByObject(Object object)

Removes and returns a pair corresponding to the given Object object provided that the object is in the map; otherwise returns null.

Parameters:
object - the object association to remove
Returns:
a pair equal to the one associated to the object or null
See Also:
remove(int), removeByString(String)

clear

public void clear()
Clear the map of all strings and objects.


size

public int size()
Returns the number of string-object pairs in this map.

Returns:
the number of string-object pairs

getString

public String getString(Object object)

Returns the String associated with the given Object or null if no association is found.

Parameters:
object - the object to associate with a string
Returns:
the associated string or null
See Also:
getObject(String), getPair(int), getString(int), getObject(int)

getObject

public Object getObject(String string)

Returns the Object associated with the given String or null if no association is found.

Parameters:
string - the string to associate with an object
Returns:
the associated object or null
See Also:
getString(Object), getPair(int), getString(int), getObject(int)

getPair

public StringObjectPair getPair(int index)

Returns the StringObjectPair pair at the given index in order of entry into the map; or null if the index is out of bounds.

If the index is in bounds, this method is equivalent to getStringObjectPairs()[index] but is more efficient since no array is constructed.

Parameters:
index - the index of the pair
Returns:
the associated pair or null
See Also:
getString(Object), getObject(String), getString(int), getObject(int)

getString

public String getString(int index)

Returns the String at the given index in order of entry into the map; or null if the index is out of bounds.

If the index is in bounds, this method is equivalent to getStrings()[index] but is more efficient since no array is constructed.

Parameters:
index - the index of the string
Returns:
the associated string or null
See Also:
getString(Object), getObject(String), getPair(int), getObject(int)

getObject

public Object getObject(int index)

Returns the Object at the given index in order of entry into the map; or null if the index is out of bounds.

If the index is in bounds, this method is equivalent to getObjects()[index] but is more efficient since no array is constructed.

Parameters:
index - the index of the object
Returns:
the associated object or null
See Also:
getString(Object), getObject(String), getPair(int), getString(int)

getStringObjectPairs

public StringObjectPair[] getStringObjectPairs()

Returns as an array the StringObjectPair pairs in this map in order of entry into the map.

Returns:
the array of string-object pairs in this map
See Also:
getStrings(), getObjects(), getSortedStringObjectPairs(), getSortedStrings(), getSortedObjects()

getStrings

public String[] getStrings()

Returns as an array the Strings in this map in order of entry into the map.

Returns:
the array of strings in this map
See Also:
getStringObjectPairs(), getObjects(), getSortedStringObjectPairs(), getSortedStrings(), getSortedObjects()

getObjects

public Object[] getObjects()

Returns as an array the Objects in this map in order of entry into the map.

Returns:
the array of objects in this map
See Also:
getStringObjectPairs(), getStrings(), getSortedStringObjectPairs(), getSortedStrings(), getSortedObjects()

getSortedStringObjectPairs

public StringObjectPair[] getSortedStringObjectPairs()

Returns as an array the StringObjectPair pairs in this map sorted in order of their corresponding strings order.

Returns:
the array of sorted string-object pairs in this map
See Also:
getStringObjectPairs(), getStrings(), getObjects(), getSortedStrings(), getSortedObjects()

getSortedStrings

public String[] getSortedStrings()

Returns as an array the Strings in this map in sorted order.

Returns:
the sorted array of strings in this map
See Also:
getStringObjectPairs(), getStrings(), getObjects(), getSortedStringObjectPairs(), getSortedObjects()

getSortedObjects

public Object[] getSortedObjects()

Returns as an array the Objects in this map sorted in order of their corresponding strings order.

Returns:
the sorted array of strings in this map
See Also:
getStringObjectPairs(), getStrings(), getObjects(), getSortedStringObjectPairs(), getSortedStrings()

containsString

public boolean containsString(String string)
Returns true if this map contains the String.

Parameters:
string - the string to test
Returns:
whether or not the string is in the map
See Also:
containsObject(Object)

containsObject

public boolean containsObject(Object object)
Returns true if this map contains the Object.

Parameters:
object - the object to test
Returns:
whether or not the object is in the map
See Also:
containsString(String)