    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

##

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

##

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

##

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

##

NO_VALUE

     public static final String NO_VALUE

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

##

LabeledData

     public LabeledData()

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.

##

put

     public Object put(String key,
                       String value)

  Store a key/value pair in the hashtable lowercasing keys if necessary.

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.

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

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.

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

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

toString

     public String toString()

  Converts LabeledData to a String.

  Overrides:
    toString in class Hashtable

toString

     public String toString(String header)

  Converts LabeledData to a String with given header information.

save

     public void save(OutputStream out,
                      String header)

  Writes ascii representation of LabeledData to Outputstream

  Overrides:
    save in class Properties

setKeyValueSeparatorChar

     public void setKeyValueSeparatorChar(char keyValueSeparatorChar)

  Set character used to key-value pairs in String representation of LabeledData

setPairSeparatorChars

     public void setPairSeparatorChars(String pairSeparatorChars)

  Set characters 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 pairSeparatorChars and keyValueSeparatorChar override separator settings in TokenCharacters object.

setLowerCaseKeys

     public void setLowerCaseKeys(boolean lowerCaseKeys)

setEatEscapeChar

     public void setEatEscapeChar(boolean eatEscapeChar)

    All Packages  Class Hierarchy  This Package  Previous  Next  Index