talx x1.0.5

talx.util
Class StringValueMap

java.lang.Object
  extended bytalx.util.StringValueMap
All Implemented Interfaces:
java.io.Serializable

public class StringValueMap
extends java.lang.Object
implements java.io.Serializable

Maps key strings to serializable values. This class is immutable so that it can safely be broadcast without fear of modification.
The complexity for get and put is O(log n) where n is the number of keys. The complexity for getPairs is linear in the number of keys.
Although this map is thread-safe, multiple threads calling the put method will change the complexity for put from O(log n) to O(n^2).

See Also:
Serialized Form

Nested Class Summary
static class StringValueMap.Pair
          Holder class for key-value pairs.
 
Field Summary
static java.lang.String ARRAY_END_TOKEN
           
static java.lang.String ARRAY_LIST_TOKEN
           
static java.lang.String ARRAY_START_TOKEN
           
static java.lang.String END_TOKEN
           
static java.lang.String LIST_TOKEN
           
static java.lang.String PAIR_END_TOKEN
           
static java.lang.String PAIR_MAP_TOKEN
           
static java.lang.String PAIR_START_TOKEN
           
static java.lang.String START_TOKEN
           
 
Constructor Summary
StringValueMap()
          Creates a StringValueMap with no mappings.
StringValueMap(StringValueMap.Pair[] mappings)
          Creates a StringValueMap with the given pairs.
 
Method Summary
static StringValueMap fromString(java.lang.String source)
          Translates the results of the toString method back to a StringValueMap.
 java.io.Serializable get(java.lang.String key)
          Returns the value associated with the key.
 StringValueMap.Pair[] getPairs()
          Returns the entire set of key-value pairs.
 StringValueMap put(java.lang.String key, java.io.Serializable value)
          Returns a new StringValueMap that associates the value with the key.
 java.lang.String toString()
          Creates a machine parseable string that represents this map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

START_TOKEN

public static final java.lang.String START_TOKEN
See Also:
Constant Field Values

END_TOKEN

public static final java.lang.String END_TOKEN
See Also:
Constant Field Values

LIST_TOKEN

public static final java.lang.String LIST_TOKEN
See Also:
Constant Field Values

PAIR_START_TOKEN

public static final java.lang.String PAIR_START_TOKEN
See Also:
Constant Field Values

PAIR_END_TOKEN

public static final java.lang.String PAIR_END_TOKEN
See Also:
Constant Field Values

PAIR_MAP_TOKEN

public static final java.lang.String PAIR_MAP_TOKEN
See Also:
Constant Field Values

ARRAY_START_TOKEN

public static final java.lang.String ARRAY_START_TOKEN
See Also:
Constant Field Values

ARRAY_END_TOKEN

public static final java.lang.String ARRAY_END_TOKEN
See Also:
Constant Field Values

ARRAY_LIST_TOKEN

public static final java.lang.String ARRAY_LIST_TOKEN
See Also:
Constant Field Values
Constructor Detail

StringValueMap

public StringValueMap()
Creates a StringValueMap with no mappings.


StringValueMap

public StringValueMap(StringValueMap.Pair[] mappings)
Creates a StringValueMap with the given pairs.

Method Detail

fromString

public static StringValueMap fromString(java.lang.String source)
Translates the results of the toString method back to a StringValueMap. Any keys that were not String objects, arrays or StringValueMap objects will be added as the corresponding String representation. StringValueMaps that appear as values are recursively reconstructed. Arrays of objects are reconstructed as arrays of String representations.

Returns:
the reconstructed StringValueMap or null if source cannot be parsed.

put

public StringValueMap put(java.lang.String key,
                          java.io.Serializable value)
Returns a new StringValueMap that associates the value with the key.


get

public java.io.Serializable get(java.lang.String key)
Returns the value associated with the key.


getPairs

public StringValueMap.Pair[] getPairs()
Returns the entire set of key-value pairs.


toString

public java.lang.String toString()
Creates a machine parseable string that represents this map. The result of this method is highly human-unreadable. It is intended to be used as a partial substitute for serialization. This produces output according to the following grammar:
 S   ::=  START_TOKEN B END_TOKEN
 B   ::=  ε | L
 L   ::=  P | L LIST_TOKEN P
 P   ::=  PAIR_START_TOKEN K PAIR_MAP_TOKEN V PAIR_END_TOKEN
 V   ::=  S | A | P | K | null
 A   ::=  ARRAY_START_TOKEN ε ARRAY_END_TOKEN | ARRAY_START_TOKEN C ARRAY_END_TOKEN
 C   ::=  V | C ARRAY_LIST_TOKEN V
 K   ::=  arbitrary string of characters
 
Obviously, the K production makes the grammar undecidable. So, the fromString method must assume that none of the string constants appear in the K production.


talx x1.0.5

© 2001-2005 University of Oregon.
Eugene OR 97403, U.S.A. All Rights Reserved.