All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sdsu.util.LabeledData

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

public class LabeledData
extends Properties
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 pairSeparatorChars,which defaults to ";". If the string representation of a key or value contains a special character it is quoted. Special characters include keyValueSeparatorChar, pairSeparatorChars, 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.

Author:
Roger Whitney (whitney@cs.sdsu.edu)
See Also:
Stringizer, SimpleTokenizer, TokenCharacters

Variable Index

 o NO_VALUE
String used for value in key-value pair when no value is available.

Constructor Index

 o LabeledData()
 o LabeledData(Properties)
Constructs a new, empty labeledData object with the specified default values.

Method Index

 o fromCommandLine(String[])
Constructs a labeled data table from command line arguments.
 o fromString(String)
Converts a string to a list.
 o getData(String)
Gets value with given label.
 o getData(String, String)
Gets value with given label.
 o load(InputStream)
Loads a list from an inputstream.
 o put(String, String)
Store a key/value pair in the hashtable lowercasing keys if necessary.
 o save(OutputStream, String)
Writes ascii representation of LabeledData to Outputstream
 o setEatEscapeChar(boolean)
 o setKeyValueSeparatorChar(char)
Set character used to key-value pairs in String representation of LabeledData
 o setLowerCaseKeys(boolean)
 o setPairSeparatorChars(String)
Set characters used to separate keys and values in String representation of LabeledData
 o setTokenCharacters(TokenCharacters)
Sets TokenCharacters used to convert LabeledData from/to strings/streams.
 o toString()
Converts LabeledData to a String.
 o toString(String)
Converts LabeledData to a String with given header information.

Variables

 o NO_VALUE
 public static final String NO_VALUE
String used for value in key-value pair when no value is available.

Constructors

 o LabeledData
 public LabeledData()
 o LabeledData
 public LabeledData(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.

Methods

 o put
 public Object put(String key,
                   String value)
Store a key/value pair in the hashtable lowercasing keys if necessary.

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

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

 o fromCommandLine
 public void fromCommandLine(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.
 o fromString
 public void fromString(String dataString) throws IOException
Converts a string to a list. Converts strings created by a list or vector Items in string are separated by separatorChar

 o load
 public void load(InputStream in) throws IOException
Loads a list from an inputstream. Data in stream must be in list format.

Overrides:
load in class Properties
 o toString
 public String toString()
Converts LabeledData to a String.

Overrides:
toString in class Hashtable
 o toString
 public String toString(String header)
Converts LabeledData to a String with given header information.

 o save
 public void save(OutputStream out,
                  String header)
Writes ascii representation of LabeledData to Outputstream

Overrides:
save in class Properties
 o setKeyValueSeparatorChar
 public void setKeyValueSeparatorChar(char keyValueSeparatorChar)
Set character used to key-value pairs in String representation of LabeledData

 o setPairSeparatorChars
 public void setPairSeparatorChars(String pairSeparatorChars)
Set characters used to separate keys and values in String representation of LabeledData

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

 o setLowerCaseKeys
 public void setLowerCaseKeys(boolean lowerCaseKeys)
 o setEatEscapeChar
 public void setEatEscapeChar(boolean eatEscapeChar)

All Packages  Class Hierarchy  This Package  Previous  Next  Index