public class ParameterTable extends Hashtable
It extends java.util.Hashtable by providing a constructor to convert from a String [] of args in the forms of "key=value", where value can represent a string, integer, long, or boolean.
This class is used parsing command line and parameter file based args. It is typically used for command line type programs, and for constructing tests,
Modifier and Type | Field and Description |
---|---|
static String |
s_ExplicitEmptyStringIndicator |
Constructor and Description |
---|
ParameterTable()
Constructs a ParameterTable.
|
ParameterTable(String filename)
Constructs a ParameterTable, from the contents
of a file.
|
ParameterTable(String[] args)
Constructs a ParameterTable.
|
ParameterTable(String[] args,
Reader reader)
Constructs a ParameterTable from command-line arguments and
the contents of a Reader.
|
ParameterTable(String[] args,
String filenameParameter)
Constructs a ParameterTable.
|
ParameterTable(String[] args,
String filenameParameter,
String includePathParameter)
Constructs a ParameterTable.
|
Modifier and Type | Method and Description |
---|---|
void |
addValue(String name,
String svalue,
boolean isConcat,
boolean isSection,
boolean shouldOverwrite)
Add or overwrite an entry in the ParameterTable
|
static String |
getArgumentName(String arg)
Static method to return the name portion of the passed
name/value pair, of the form
|
static String |
getArgumentStringValue(String arg)
Static method to return the value portion of the passed
name/value pair.
|
Boolean |
getBoolean(String name)
Returns a Boolean object representing the first occurance of
the passed name in an name/value pair.
|
boolean |
getBoolean(String name,
boolean defaultValue)
Returns a boolean representing the first occurance of
the passed name in an name/value pair.
|
String |
getCurrentSection()
Return the nmae of the section currently in effect.
|
String[] |
getEntries(String[] omittedKeys) |
Integer |
getInteger(String name)
Returns an Integer object representing the first occurance of
the passed name in an name/value pair.
|
int |
getInteger(String name,
int defaultValue)
Returns an int representing the first occurance of
the passed name in an name/value pair.
|
String[] |
getKeys()
Return the keys that are represented by this ParameterTable,
in the order in which they were added.
|
Long |
getLong(String name)
Returns an Long object representing the first occurance of
the passed name in an name/value pair.
|
long |
getLong(String name,
long defaultValue)
Returns an long representing the first occurance of
the passed name in an name/value pair.
|
String[] |
getSectionEntries() |
String[] |
getSectionKeys()
Return the section keys that are represented by this ParameterTable,
in the order in which they were added.
|
String |
getString(String name)
Returns a String object representing the first occurance of
the passed name in an name/value pair.
|
String |
getString(String name,
String defaultValue)
Returns a String object representing the first occurance of
the passed name in an name/value pair.
|
String[] |
getStrings(String name)
Returns a Strings array object for a named parameter.
|
static String[] |
getStringsFromArrayToken(String token)
Get String array from a value of the form
"{value1, value2, value3}".
|
static String[] |
getStringsFromArrayToken(String token,
String delim)
Get String array from a value of the form
"{value1
|
String[] |
getTokenList(String tokenlist)
Parse string into tokens.
|
String[] |
getTokenList(String tokenlist,
int minArraySize)
Parse string into tokens.
|
protected void |
initParameterTable(String filename,
String[] includePaths)
Reads the parameter file and adds the name/value pairs
there to our hashtable.
|
static boolean |
isArgumentConcatenation(String arg)
Static method to return an indication of whether the name/value
pair was assigned with a concatenation operator, "+=".
|
static boolean |
isSectionKey(String arg)
Static method to return an indication of whether the name/value
pair is actually a section key, a square-bracketed id.
|
static String[] |
parseTokenList(String tokenlist)
Parse string into tokens.
|
static String[] |
parseTokenList(String tokenlist,
int minArraySize)
Parse string into tokens.
|
Hashtable |
promoteSection(String sectionName)
Promote the specified section, so that settings in the
section override any settings of the same name in the main
section.
|
Hashtable |
setSection(String sectionName)
Set the parameter section.
|
String |
toString()
Provide String representation of this object.
|
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, merge, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, size, values
public static final String s_ExplicitEmptyStringIndicator
public ParameterTable()
public ParameterTable(String[] args)
This constructor creates a new ParameterTable from a array of Strings in the format name=value.
args
- commandline arguments, in the form of name=valuepublic ParameterTable(String filename)
filename
- absolute or relative path to a file.public ParameterTable(String[] args, String filenameParameter)
The items in the ParameterTable can be obtained from either an array of name/value pairs or a file containing a set of name/value pairs, one per line.
For example, new ParameterTable(new String[] { "foo=1", "bar=2",
"myParameterFile=Test.def" }, "myParameterFile")
constructs a
ParameterTable containing values for foo
, bar
,
plus whatever name/value pairs are in the file Test.def
.
Items in the array of name/value pairs always override like-named parameters in the file.
args
- a set of name/value pairs, in the form
name=value
filenameParameter
- the name of the parameter whose value
is the name of a file containing a
set of name/value pairspublic ParameterTable(String[] args, String filenameParameter, String includePathParameter)
This constructor behaves as the above one, but allows specification of the includepath parameter.
args
- commandline arguments, in the form of name=valuefilenameParameter
- string used to denote a parameter file.includePathParameter
- string used to denote the include path parameterprotected void initParameterTable(String filename, String[] includePaths)
filename
- a FileReader class that is opened.includePaths
- the included pathspublic Hashtable setSection(String sectionName)
sectionName
- The section name.public String getCurrentSection()
public Hashtable promoteSection(String sectionName)
sectionName
- The section name.public String getString(String name)
name
- The parameter name in a name value pair.public String getString(String name, String defaultValue)
name
- The parameter name in a name value pair.defaultValue
- Value to reutn if name is not foundpublic String[] getStrings(String name)
name
- The parameter name in a name value pair.public Integer getInteger(String name)
name
- The parameter name in a name value pair.public int getInteger(String name, int defaultValue)
name
- The parameter name in a name value pair.defaultValue
- Default value if name is not found.public Long getLong(String name)
name
- The parameter name in a name value pair.public long getLong(String name, long defaultValue)
name
- The parameter name in a name value pair.defaultValue
- Default value if name is not found.public Boolean getBoolean(String name)
name
- The parameter name in a name value pair.public boolean getBoolean(String name, boolean defaultValue)
name
- The parameter name in a name value pair.defaultValue
- Default value if name is not found.public static String getArgumentName(String arg)
arg
- Name or name/value pair.public static boolean isArgumentConcatenation(String arg)
arg
- Name or name/value pair.public static boolean isSectionKey(String arg)
arg
- Name or name/value pair.public static String getArgumentStringValue(String arg)
arg
- Name or name/value pair.public void addValue(String name, String svalue, boolean isConcat, boolean isSection, boolean shouldOverwrite)
name
- Name of the entrysvalue
- Sting value of the entryisConcat
- True if the entry is an array entry.isSection
- True if the entry is a section entry.shouldOverwrite
- True if an existing entry is overwritten by this entry.public String[] getSectionEntries()
public String[] getKeys()
public String[] getSectionKeys()
public static String[] parseTokenList(String tokenlist)
Delegates to getTokenList
with a default ParameterTable
instance.
public static String[] parseTokenList(String tokenlist, int minArraySize)
Delegates to getTokenList
with a default ParameterTable
instance.
public String[] getTokenList(String tokenlist)
Return an array of tokens, some of which may be null. An empty token (e.g. "") is stored in the array as a null. A double quote (") is used to completely enclose any arbitrary token. Whitespace is used to separate any unquoted token. Quotes can appear enclosed in a quoted string by doubling them (e.g. "cat ""and"" dog" would get parsed to cat "and" dog).
public String[] getTokenList(String tokenlist, int minArraySize)
public String toString()
public static String[] getStringsFromArrayToken(String token)
A single comma is treated as the delimiter.
token
- the string tokenpublic static String[] getStringsFromArrayToken(String token, String delim)
NOTE: consecutive delimitters are recognized, both leading, trailing, and within the string. For example, getStringsFromArrayToken("{,, foo,, bar, zad,,, }", ",") will return an array of: [null, null, "foo", null, "bar", "zad", null, null, null].
token
- the string tokendelim
- the delimiterCopyright © 2023. All rights reserved.