|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Dictionary | +--java.util.Hashtable | +--java.util.Properties | +--sdsu.util.LabeledData
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
Stringizer
,
SimpleTokenizer
,
TokenCharacters
, Serialized FormField 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 |
public static final java.lang.String NO_VALUE
Constructor Detail |
public LabeledData()
public LabeledData(java.util.Properties defaultValues)
defaultValues
- Properties object that is used for default values in new object.Method Detail |
public LabeledData getMetaData()
public void setMetaData(LabeledData metaData)
public java.lang.String getData(java.lang.String label)
public java.lang.String getData(java.lang.String label, java.lang.String defaultValue)
public void fromCommandLine(java.lang.String[] arguments)
arguments
- String array passed to main.public void fromString(java.lang.String dataString) throws ConversionException
public void load(java.io.InputStream in) throws java.io.IOException
public void load(java.io.Reader in) throws java.io.IOException
public java.lang.String toString()
public java.lang.String toString(java.lang.String header)
public void save(java.io.OutputStream out, java.lang.String header)
public void setKeyValueSeparatorChar(char keyValueSeparatorChar)
public void setPairSeparatorChar(char pairSeparatorChar)
public void setTokenCharacters(TokenCharacters newParseTable)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |