public class TLVariable
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
class |
TLVariable.NullableBoolean
A class that "wraps" the boolean primitive type so that it can be null.
|
Constructor and Description |
---|
TLVariable(java.lang.String declaration)
Creates a new variable from its declaration.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getDeclaration()
Gets the original declaration of the variable.
|
java.lang.String |
getName()
Gets the name of the variable.
|
java.lang.String |
getValue()
Gets the original value of the variable as a
String . |
java.lang.String[] |
getValueAsArray()
Returns the variable as a String array, splitting it with ';'.
|
boolean |
getValueAsBoolean()
Returns the variable value as a boolean.
|
boolean |
getValueAsBooleanOrDefault(boolean value)
Returns the variable value as a boolean.
|
byte |
getValueAsByte()
Returns the variable value as a byte.
|
byte |
getValueAsByteOrDefault(byte value) |
char |
getValueAsChar()
Returns the first character of the value.
|
char |
getValueAsCharOrDefault(char value) |
java.io.File |
getValueAsCreatedFile(java.lang.String content)
Returns the file by the path represented by the value.
|
double |
getValueAsDouble()
Returns the variable value as a double.
|
double |
getValueAsDoubleOrDefault(double value) |
java.io.File |
getValueAsExistingFile(boolean checkReadable)
Returns the file by the path represented by the value only if it exists, otherwise null.
|
java.io.File |
getValueAsFile()
Returns the file by the path represented by the value.
|
java.io.File |
getValueAsFile(boolean absolute)
Returns the file by the path represented by the value.
|
float |
getValueAsFloat()
Returns the variable value as a float.
|
float |
getValueAsFloatOrDefault(float value) |
int |
getValueAsInt()
Returns the variable value as an int.
|
int |
getValueAsIntOrDefault(int value) |
long |
getValueAsLong()
Returns the variable value as a long.
|
long |
getValueAsLongOrDefault(long value) |
java.util.Map<java.lang.String,java.lang.String> |
getValueAsMap()
Returns the map represented by the value following this syntax:
"key0@val0;key1@val1" will result in a map with two keys: "key0" and "key1" and two corresponding values "val0" and "val1".
|
java.util.Map<java.lang.String,java.lang.String> |
getValueAsMapOrDefault(java.util.Map<java.lang.String,java.lang.String> value) |
java.lang.Object |
getValueAsObject()
Returns the value as an Object.
|
java.lang.Object |
getValueAsObjectOrDefault(java.lang.Object value)
Returns the value as an Object.
|
java.lang.Object |
getValueAsObjectOrDefault(java.lang.Object value,
boolean replaceNull)
Returns the value as an Object.
|
short |
getValueAsShort()
Returns the variable value as a short.
|
short |
getValueAsShortOrDefault(short value) |
TLVariable.NullableBoolean |
getValueAsTrueBoolean()
Returns the variable value as a
TLVariable.NullableBoolean . |
java.lang.String |
getValueWithChatColors()
Returns the value as a formatted Minecraft message, replacing '&' by a paragraph sign were it marks a chat color.
|
boolean |
isExactNumeric()
Checks if this value is an exact number.
|
boolean |
isNumeric()
Checks if this value is numeric.
|
public TLVariable(java.lang.String declaration) throws TLException
declaration
- The variable's declaration.TLException
- If the declaration provided is invalid.public java.lang.String getDeclaration()
public java.lang.String getName()
public java.lang.String getValue()
String
.public boolean getValueAsBoolean()
getValueAsTrueBoolean()
should be used to determine if the 'false' value is set so or is simply absent.getValueAsTrueBoolean()
,
getValueAsBooleanOrDefault(boolean)
public TLVariable.NullableBoolean getValueAsTrueBoolean()
TLVariable.NullableBoolean
. Unlike getValueAsBoolean()
,
it will return a null-filled object (not null) in case a boolean is not indicated.
For example, "tRue" will return a NullableBoolean that returns true when converted
,
"FALSE" in the same situation will result in false while
"yes" or "blah-blah-BLAH" will cause an exception if converted.
TLVariable.NullableBoolean.convert()
public boolean getValueAsBooleanOrDefault(boolean value)
value
- The value to return if the variable's value is not a boolean.public byte getValueAsByte() throws java.lang.NumberFormatException, java.lang.ClassCastException
java.lang.NumberFormatException
- If the value is not numeric.java.lang.ClassCastException
- If the value is not a byte.public byte getValueAsByteOrDefault(byte value)
public short getValueAsShort() throws java.lang.NumberFormatException, java.lang.ClassCastException
java.lang.NumberFormatException
- If the value is not numeric.java.lang.ClassCastException
- If the value is not a short.public short getValueAsShortOrDefault(short value)
public int getValueAsInt() throws java.lang.NumberFormatException, java.lang.ClassCastException
java.lang.NumberFormatException
- If the value is not numeric.java.lang.ClassCastException
- If the value is not an int.public int getValueAsIntOrDefault(int value)
public long getValueAsLong() throws java.lang.NumberFormatException
java.lang.NumberFormatException
- If the value is not numeric.public long getValueAsLongOrDefault(long value)
public float getValueAsFloat() throws java.lang.NumberFormatException, java.lang.ClassCastException
java.lang.NumberFormatException
- If the value is not numeric.java.lang.ClassCastException
- If the value is not an float.public float getValueAsFloatOrDefault(float value)
public double getValueAsDouble() throws java.lang.NumberFormatException
java.lang.NumberFormatException
- If the value is not numeric.public double getValueAsDoubleOrDefault(double value)
public java.lang.String[] getValueAsArray()
E.g. "red;blue;;green;yellow;" returns {"red", "blue", "", "green", "yellow"}.
String.split(String)
public char getValueAsChar() throws java.lang.IndexOutOfBoundsException
E.g. "portal" returns 'p'.
java.lang.IndexOutOfBoundsException
- If the string is "".public char getValueAsCharOrDefault(char value)
public java.util.Map<java.lang.String,java.lang.String> getValueAsMap() throws java.lang.IllegalStateException
"key0@val0;key1@val1" will result in a map with two keys: "key0" and "key1" and two corresponding values "val0" and "val1".
java.lang.IllegalStateException
- If some key does not have a pair, e.g. in "key0@val0;key1;key2@val2"
key1 will cause an error.public java.util.Map<java.lang.String,java.lang.String> getValueAsMapOrDefault(java.util.Map<java.lang.String,java.lang.String> value)
public boolean isExactNumeric()
isNumeric()
public boolean isNumeric()
isExactNumeric()
public java.lang.String getValueWithChatColors()
public java.lang.Object getValueAsObject() throws TLSaveableException
The syntax is different from arrays and maps: it looks like
"package.className*arg0*arg1*arg2...
" or "~null
" (to indicate a null object).
When instantiated the arguments are passed in the order of their declaration.
TLSaveableException
- A wrap for all exceptions that may be thrown during reflection operations;
includes the argument declaration.getValueAsObjectOrDefault(Object, boolean)
,
getValueAsObjectOrDefault(Object)
public java.lang.Object getValueAsObjectOrDefault(java.lang.Object value, boolean replaceNull)
getValueAsObject()
for conditions that the Object must comply.value
- The default value to return in case the instantiation fails.replaceNull
- Indicates whether to consider null appropriate or not, where true will make the method return
the default value in case the represented Object is null.getValueAsObject()
public java.lang.Object getValueAsObjectOrDefault(java.lang.Object value)
getValueAsObject()
for conditions that the Object must comply.
Invocation of this method is actually equal to TLVariable.getValueAsObjectOrDefault(value, false)
.value
- The default value to return in case the instantiation fails.getValueAsObject()
public java.io.File getValueAsFile(boolean absolute)
absolute
- If true, the method will try to return the file in its absolute form, otherwise it may be abstract.SecurityException
).public java.io.File getValueAsFile()
SecurityException
).getValueAsFile(boolean)
public java.io.File getValueAsExistingFile(boolean checkReadable)
checkReadable
- Whether to check readability of the file. If true, an existing but unreadable file will return null,
otherwise the file is returned even if it is not readable.public java.io.File getValueAsCreatedFile(java.lang.String content) throws java.io.IOException, java.lang.SecurityException
content
- Data to write to the file if it is created. If null nothing is written.java.io.IOException
- If any IO error occurs.java.lang.SecurityException
- If any security error occurs.