public class KeyValue
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
KeyValue.Type |
| Modifier and Type | Field and Description |
|---|---|
static KeyValue |
INVALID
Represents an invalid
KeyValue given when a searched for child does not exist. |
| Constructor and Description |
|---|
KeyValue()
Initializes a new instance of the
KeyValue class. |
KeyValue(java.lang.String name)
Initializes a new instance of the
KeyValue class. |
KeyValue(java.lang.String name,
java.lang.String value)
Initializes a new instance of the
KeyValue class. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
asBoolean()
Attempts to convert and return the value of this instance as a boolean.
|
boolean |
asBoolean(boolean defaultValue)
Attempts to convert and return the value of this instance as a boolean.
|
byte |
asByte()
Attempts to convert and return the value of this instance as a byte.
|
byte |
asByte(byte defaultValue)
Attempts to convert and return the value of this instance as a byte.
|
<T extends java.lang.Enum<T>> |
asEnum(java.lang.Class<T> enumClass,
java.util.EnumSet<T> defaultValue)
Attempts to convert and return the value of this instance as an enum.
|
<T extends java.lang.Enum<T>> |
asEnum(java.lang.Class<T> enumClass,
T defaultValue)
Attempts to convert and return the value of this instance as an enum.
|
float |
asFloat()
Attempts to convert and return the value of this instance as a float.
|
float |
asFloat(float defaultValue)
Attempts to convert and return the value of this instance as a float.
|
int |
asInteger()
Attempts to convert and return the value of this instance as an integer.
|
int |
asInteger(int defaultValue)
Attempts to convert and return the value of this instance as an integer.
|
long |
asLong()
Attempts to convert and return the value of this instance as a long.
|
long |
asLong(long defaultValue)
Attempts to convert and return the value of this instance as a long.
|
short |
asShort()
Attempts to convert and return the value of this instance as a short.
|
short |
asShort(short defaultValue)
Attempts to convert and return the value of this instance as a short.
|
java.lang.String |
asString()
Returns the value of this instance as a string.
|
KeyValue |
get(java.lang.String key)
Gets the child
KeyValue with the specified key. |
java.util.List<KeyValue> |
getChildren() |
java.lang.String |
getName() |
java.lang.String |
getValue() |
static KeyValue |
loadAsText(java.lang.String path)
Attempts to load the given filename as a text
KeyValue. |
static KeyValue |
loadFromString(java.lang.String input)
Attempts to create an instance of
KeyValue from the given input text. |
boolean |
readAsText(java.io.InputStream is) |
boolean |
readFileAsText(java.lang.String filename)
Opens and reads the given filename as text.
|
void |
saveToFile(java.io.File path,
boolean binary)
Saves this instance to file.
|
void |
saveToStream(java.io.OutputStream os,
boolean binary) |
void |
set(java.lang.String key,
KeyValue value)
Sets the child
KeyValue with the specified key. |
void |
setName(java.lang.String name) |
void |
setValue(java.lang.String value) |
java.lang.String |
toString() |
static KeyValue |
tryLoadAsBinary(java.lang.String path)
Attempts to load the given filename as a binary
KeyValue. |
boolean |
tryReadAsBinary(java.io.InputStream is)
Populate this instance from the given
InputStream as a binary KeyValue. |
public KeyValue()
KeyValue class.public KeyValue(java.lang.String name)
KeyValue class.name - The optional name of the root key.public KeyValue(java.lang.String name,
java.lang.String value)
KeyValue class.name - The optional name of the root key.value - The optional value assigned to the root key.public KeyValue get(java.lang.String key)
KeyValue with the specified key.
If no child with the given key exists, INVALID is returned.key - keyKeyValuepublic void set(java.lang.String key,
KeyValue value)
KeyValue with the specified key.key - keyvalue - the child KeyValuepublic java.lang.String asString()
public byte asByte(byte defaultValue)
defaultValue - The default value to return if the conversion is invalid.public byte asByte()
public short asShort(short defaultValue)
defaultValue - The default value to return if the conversion is invalid.public short asShort()
public int asInteger(int defaultValue)
defaultValue - The default value to return if the conversion is invalid.public int asInteger()
public long asLong(long defaultValue)
defaultValue - The default value to return if the conversion is invalid.public long asLong()
public float asFloat(float defaultValue)
defaultValue - The default value to return if the conversion is invalid.public float asFloat()
public boolean asBoolean(boolean defaultValue)
defaultValue - The default value to return if the conversion is invalid.public boolean asBoolean()
public <T extends java.lang.Enum<T>> java.util.EnumSet<T> asEnum(java.lang.Class<T> enumClass,
T defaultValue)
T - the type of the enum to convert toenumClass - the type of the enum to convert todefaultValue - The default value to return if the conversion is invalid.public <T extends java.lang.Enum<T>> java.util.EnumSet<T> asEnum(java.lang.Class<T> enumClass,
java.util.EnumSet<T> defaultValue)
T - the type of the enum to convert toenumClass - the type of the enum to convert todefaultValue - The default value to return if the conversion is invalid.public java.lang.String getName()
public void setName(java.lang.String name)
public java.lang.String getValue()
public void setValue(java.lang.String value)
public java.util.List<KeyValue> getChildren()
public boolean readAsText(java.io.InputStream is)
throws java.io.IOException
java.io.IOExceptionpublic boolean readFileAsText(java.lang.String filename)
throws java.io.IOException
filename - The file to open and read.java.io.IOException - exception while reading from the filepublic static KeyValue loadAsText(java.lang.String path)
KeyValue.path - The path to the file to load.KeyValue instance if the load was successful, or null on failure.public static KeyValue tryLoadAsBinary(java.lang.String path)
KeyValue.path - The path to the file to load.KeyValue instance if the load was successful, or null on failure.public static KeyValue loadFromString(java.lang.String input)
KeyValue from the given input text.input - The input text to load.KeyValue instance if the load was successful, or null on failure.public void saveToFile(java.io.File path,
boolean binary)
throws java.io.IOException
path - The file path to save to.binary - If set to true, saves this instance as binary.java.io.IOException - exception while writing to the filepublic void saveToStream(java.io.OutputStream os,
boolean binary)
throws java.io.IOException
java.io.IOExceptionpublic boolean tryReadAsBinary(java.io.InputStream is)
throws java.io.IOException
InputStream as a binary KeyValue.is - The input InputStream to read from.java.io.IOException - exception while reading from the streampublic java.lang.String toString()
toString in class java.lang.Object