sdsu.util
Class LabeledData

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
                    |
                    +--sdsu.util.LabeledData

public class LabeledData
extends java.util.Properties
implements Stringizable

This class is a hashtable with two additional features. First, it can parse command line arguments. Flags are indicated in command line via "-" before the flag. Supported syntax:
-flag=value
-flag value The string "flag" (without the '-' and without the "'s) is stored as key. The string "value" is the associated value in the hashtable. If -flag is the last argument or the argument after -flag starts with a '-', the string "NO_VALUE" is stored as value for the flag.
--flagChars Individual characters after the -- are treated as separate flags. The string "NO_VALUE" is stored as value for each flag.
-- ignore rest of the command line arguments.

Second, a LabeledData object can conver itself to a string and sort of "recreate" itself from that string. The original LabeledData object can contain any objects as keys and values. However, objects other than strings, numbers, DataPairs, and Lists may cause problems (the string representations of other objects may cause parsing error). A recreated LabeledData object will only contain string representations of the original keys and values. In a LabeledData object string representation (Losr) the key and values are separated by a keyValueSeparatorChar, which defaults to '='. In a Losr key-value pairs are separated by a pairSeparatorChar,which defaults to ';'. If the string representation of a key or value contains a special character it is quoted. Special characters include keyValueSeparatorChar, pairSeparatorChar, a comment character, and white space characters. See sdsu.util.TokenCharacters for default values. White space and comments can be added to a Losr for readability. Comments start with a comment character and continue upto and include the next '\n' character.
Version Info
1.1 Add support for Stringizable, metaData, changed exception thrown by fromString

Version:
1.1 30 August 1997
Author:
Roger Whitney (whitney@cs.sdsu.edu)
See Also:
Stringizer, SimpleTokenizer, TokenCharacters, Serialized Form

Field Summary
static java.lang.String NO_VALUE
          String used for value in key-value pair when no value is available.
 
Constructor Summary
LabeledData()
           
LabeledData(java.util.Properties defaultValues)
          Constructs a new, empty labeledData object with the specified default values.
 
Method Summary
 void fromCommandLine(java.lang.String[] arguments)
          Constructs a labeled data table from command line arguments.
 void fromString(java.lang.String dataString)
          Converts a string to a list.
 java.lang.String getData(java.lang.String label)
          Gets value with given label.
 java.lang.String getData(java.lang.String label, java.lang.String defaultValue)
          Gets value with given label.
 LabeledData getMetaData()
          Returns name-value pair of data used to parse a string version of a LabeledData object
 void load(java.io.InputStream in)
          Loads a LabeledData from an inputstream.
 void load(java.io.Reader in)
          Loads a LabeledData from an inputstream.
 void save(java.io.OutputStream out, java.lang.String header)
          Writes ascii representation of LabeledData to Outputstream
 void setKeyValueSeparatorChar(char keyValueSeparatorChar)
          Set character used to key-value pairs in String representation of LabeledData
 void setMetaData(LabeledData metaData)
          Set the current objects metadata to be that found in metaData string
 void setPairSeparatorChar(char pairSeparatorChar)
          Set character used to separate keys and values in String representation of LabeledData
 void setTokenCharacters(TokenCharacters newParseTable)
          Sets TokenCharacters used to convert LabeledData from/to strings/streams.
 java.lang.String toString()
          Converts LabeledData to a String.
 java.lang.String toString(java.lang.String header)
          Converts LabeledData to a String with given header information.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, propertyNames, setProperty, store
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_VALUE

public static final java.lang.String NO_VALUE
String used for value in key-value pair when no value is available.
Constructor Detail

LabeledData

public LabeledData()

LabeledData

public LabeledData(java.util.Properties defaultValues)
Constructs a new, empty labeledData object with the specified default values.
Parameters:
defaultValues - Properties object that is used for default values in new object.
Method Detail

getMetaData

public LabeledData getMetaData()
Returns name-value pair of data used to parse a string version of a LabeledData object
Specified by:
getMetaData in interface Stringizable

setMetaData

public void setMetaData(LabeledData metaData)
Set the current objects metadata to be that found in metaData string
Specified by:
setMetaData in interface Stringizable

getData

public java.lang.String getData(java.lang.String label)
Gets value with given label. If label does not exits, check defaults. Returns null if label is not found.

getData

public java.lang.String getData(java.lang.String label,
                                java.lang.String defaultValue)
Gets value with given label. If label does not exits, check defaults. Returns defaultValue if label is not found

fromCommandLine

public void fromCommandLine(java.lang.String[] arguments)
Constructs a labeled data table from command line arguments. Keys are the flags, values are strings associated with a flag.
Parameters:
arguments - String array passed to main.

fromString

public void fromString(java.lang.String dataString)
                throws ConversionException
Converts a string to a list. Converts strings created by a list or vector Items in string are separated by separatorChar
Specified by:
fromString in interface Stringizable

load

public void load(java.io.InputStream in)
          throws java.io.IOException
Loads a LabeledData from an inputstream. Data in stream must be in LabeledData format.
Overrides:
load in class java.util.Properties

load

public void load(java.io.Reader in)
          throws java.io.IOException
Loads a LabeledData from an inputstream. Data in stream must be in LabeledData format.

toString

public java.lang.String toString()
Converts LabeledData to a String.
Specified by:
toString in interface Stringizable
Overrides:
toString in class java.util.Hashtable

toString

public java.lang.String toString(java.lang.String header)
Converts LabeledData to a String with given header information.
Specified by:
toString in interface Stringizable

save

public void save(java.io.OutputStream out,
                 java.lang.String header)
Writes ascii representation of LabeledData to Outputstream
Overrides:
save in class java.util.Properties

setKeyValueSeparatorChar

public void setKeyValueSeparatorChar(char keyValueSeparatorChar)
Set character used to key-value pairs in String representation of LabeledData

setPairSeparatorChar

public void setPairSeparatorChar(char pairSeparatorChar)
Set character used to separate keys and values in String representation of LabeledData

setTokenCharacters

public void setTokenCharacters(TokenCharacters newParseTable)
Sets TokenCharacters used to convert LabeledData from/to strings/streams. Current values for pairSeparatorChar and keyValueSeparatorChar override separator settings in TokenCharacters object.