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
- 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
-
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.
-
getMetaData()
- Returns name-value pair of data used to parse a string version
of a LabeledData object
-
load(InputStream)
- Loads a LabeledData from an inputstream.
-
load(Reader)
- Loads a LabeledData from an inputstream.
-
save(OutputStream, String)
- Writes ascii representation of LabeledData to Outputstream
-
setKeyValueSeparatorChar(char)
- Set character used to key-value pairs in String representation of LabeledData
-
setMetaData(LabeledData)
- Set the current objects metadata to be that found in metaData string
-
setPairSeparatorChar(char)
- Set character 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.
getMetaData
public LabeledData getMetaData()
- Returns name-value pair of data used to parse a string version
of a LabeledData object
setMetaData
public void setMetaData(LabeledData metaData)
- Set the current objects metadata to be that found in metaData string
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 ConversionException
- 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 LabeledData from an inputstream. Data in stream
must be in LabeledData format.
- Overrides:
- load in class Properties
load
public void load(Reader in) throws IOException
- Loads a LabeledData from an inputstream. Data in stream
must be in LabeledData format.
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
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.
All Packages Class Hierarchy This Package Previous Next Index