Class Entry
Config
file.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> Optional<T>
Returns this entry converted to the specified type.<T> Optional<T>
Returns this entry converted to the specified value.<T> Optional<T>
Returns this entry converted to the specified type.<T> Optional<T>
Same asas(Type, Type...)
but specifies the parser to use to parse the entry.Returns this entry as a parsed boolean.Optional<byte[]>
asBytes()
Returns this entry as a byte array.asDouble()
Returns this entry as a double.asFloat()
Returns this entry as a float.Returns this entry as an integer.asList()
Returns this entry as a parsed list.Returns this entry as a parsed list.asLong()
Returns this entry as a long.asMap()
Returns this entry as a parsed map.Returns this entry as a parsed map.asString()
Returns this entry as a string.Returns this entry as a string array.get()
Returns this entry as a string.Returns the same-line comment of this entry.getKey()
Returns the name of this entry.Returns the modifiers for this entry.Returns the pre-lines of this entry.getValue()
Returns the raw value of this entry.boolean
Returnstrue if this entry exists in the config and is not empty.boolean
Returnstrue if this entry exists in the config.Returns this entry converted to the specified type or returns the default value.Returns this entry converted to the specified type or returns the default value.toString()
Returns this entry as a string.
-
Constructor Details
-
Entry
Constructor.- Parameters:
config
- The config that this entry belongs to.configMap
- The map that this belongs to.sectionName
- The section name of this entry.entryName
- The name of this entry.
-
-
Method Details
-
isPresent
Returnstrue if this entry exists in the config.- Returns:
true if this entry exists in the config.
-
isNotEmpty
Returnstrue if this entry exists in the config and is not empty.- Returns:
true if this entry exists in the config and is not empty.
-
get
Returns this entry as a string.- Returns:
true if this entry exists in the config and is not empty.- Throws:
NullPointerException
- if value wasnull .
-
orElse
Returns this entry converted to the specified type or returns the default value.This is equivalent to calling
as( but is simpler and avoids the creation of andef .getClass()).orElse(def )Optional
object.- Parameters:
def
- The default value to return if value does not exist.- Returns:
- This entry converted to the specified type or returns the default value.
-
orElseGet
Returns this entry converted to the specified type or returns the default value.This is equivalent to calling
as( but is simpler and avoids the creation of andef .getClass()).orElse(def )Optional
object.- Parameters:
def
- The default value to return if value does not exist.- Returns:
- This entry converted to the specified type or returns the default value.
-
as
Returns this entry converted to the specified type.- Type Parameters:
T
- The type to convert the value to.- Parameters:
type
- The type to convert the value to.- Returns:
- This entry converted to the specified type.
-
as
Returns this entry converted to the specified value.The type can be a simple type (e.g. beans, strings, numbers) or parameterized type (collections/maps).
Examples:
Config
config = Config.create ().name("MyConfig.cfg" ).build();// Parse into a linked-list of strings. Listlist =config .get("MySection/myListOfStrings" ).to(LinkedList.class , String.class );// Parse into a linked-list of beans. Listlist =config .get("MySection/myListOfBeans" ).to(LinkedList.class , MyBean.class );// Parse into a linked-list of linked-lists of strings. Listlist =config .get("MySection/my2dListOfStrings" ).to(LinkedList.class , LinkedList.class , String.class );// Parse into a map of string keys/values. Mapmap =config .get("MySection/myMap" ).to(TreeMap.class , String.class , String.class );// Parse into a map containing string keys and values of lists containing beans. Mapmap =config .get("MySection/myMapOfListsOfBeans" ).to(TreeMap.class , String.class , List.class , MyBean.class );Collection classes are assumed to be followed by zero or one objects indicating the element type.Map classes are assumed to be followed by zero or two meta objects indicating the key and value types.The array can be arbitrarily long to indicate arbitrarily complex data structures.
Notes:
-
Use the
as(Class)
method instead if you don't need a parameterized map/collection.
- Type Parameters:
T
- The object type to create.- Parameters:
type
- The object type to create.
Can be any of the following:ClassMeta
,Class
,ParameterizedType
,GenericArrayType
args
- The type arguments of the class if it's a collection or map.
Can be any of the following:ClassMeta
,Class
,ParameterizedType
,GenericArrayType
Ignored if the main type is not a map or collection.- Returns:
- The value, or
Optional.empty()
if the section or key does not exist.
-
Use the
-
as
Same asas(Type, Type...)
but specifies the parser to use to parse the entry.- Type Parameters:
T
- The object type to create.- Parameters:
parser
- The parser to use to parse the entry.type
- The object type to create.
Can be any of the following:ClassMeta
,Class
,ParameterizedType
,GenericArrayType
args
- The type arguments of the class if it's a collection or map.
Can be any of the following:ClassMeta
,Class
,ParameterizedType
,GenericArrayType
Ignored if the main type is not a map or collection.- Returns:
- The value, or
Optional.empty()
if the section or key does not exist.
-
as
Returns this entry converted to the specified type.- Type Parameters:
T
- The type to convert the value to.- Parameters:
parser
- The parser to use to parse the entry value.type
- The type to convert the value to.- Returns:
- This entry converted to the specified type, or
Optional.empty()
if the entry does not exist.
-
toString
Returns this entry as a string. -
asString
Returns this entry as a string.- Returns:
- This entry as a string, or
Optional.empty()
if the entry does not exist.
-
asStringArray
Returns this entry as a string array.If the value exists, splits the value on commas and returns the values as trimmed strings.
- Returns:
- This entry as a string array, or
Optional.empty()
if the entry does not exist.
-
asInteger
Returns this entry as an integer."K" ,"M" , and"G" can be used to identify kilo, mega, and giga in base 2."k" ,"m" , and"g" can be used to identify kilo, mega, and giga in base 10.Example:
-
"100K" -> 1024000 -
"100M" -> 104857600 -
"100k" -> 1000000 -
"100m" -> 100000000
Uses
Integer.decode(String)
underneath, so any of the following integer formats are supported:"0x..." "0X..." "#..." "0..."
- Returns:
- The value, or
Optional.empty()
if the value does not exist or the value is empty.
-
-
asBoolean
Returns this entry as a parsed boolean.Uses
Boolean.parseBoolean(String)
to parse value.- Returns:
- The value, or
Optional.empty()
if the value does not exist or the value is empty.
-
asLong
Returns this entry as a long."K" ,"M" ,"G" ,"T" , and"P" can be used to identify kilo, mega, giga, tera, and penta in base 2."k" ,"m" ,"g" ,"t" , and"p" can be used to identify kilo, mega, giga, tera, and p in base 10.Example:
-
"100K" -> 1024000 -
"100M" -> 104857600 -
"100k" -> 1000000 -
"100m" -> 100000000
Uses
Long.decode(String)
underneath, so any of the following integer formats are supported:"0x..." "0X..." "#..." "0..."
- Returns:
- The value, or
Optional.empty()
if the value does not exist or the value is empty.
-
-
asDouble
Returns this entry as a double.Uses
Double.valueOf(String)
underneath, so any of the following number formats are supported:"0x..." "0X..." "#..." "0..."
- Returns:
- The value, or
Optional.empty()
if the value does not exist or the value is empty.
-
asFloat
Returns this entry as a float.Uses
Float.valueOf(String)
underneath, so any of the following number formats are supported:"0x..." "0X..." "#..." "0..."
- Returns:
- The value, or
Optional.empty()
if the value does not exist or the value is empty.
-
asBytes
Returns this entry as a byte array.Byte arrays are stored as encoded strings, typically BASE64, but dependent on the
Config.Builder.binaryFormat(BinaryFormat)
setting.- Returns:
- The value, or
Optional.empty()
if the section or key does not exist.
-
asMap
Returns this entry as a parsed map.Uses the parser registered on the
Config
to parse the entry.If the parser is a JSON parser, the starting/trailing
"{" /"}" in the value are optional.- Returns:
- The value, or
Optional.empty()
if the section or key does not exist. - Throws:
ParseException
- If value could not be parsed.
-
asMap
Returns this entry as a parsed map.If the parser is a JSON parser, the starting/trailing
"{" /"}" in the value are optional.- Parameters:
parser
- The parser to use to parse the value, orOptional.empty()
to use the parser defined on the config.- Returns:
- The value, or
null if the section or key does not exist. - Throws:
ParseException
- If value could not be parsed.
-
asList
Returns this entry as a parsed list.Uses the parser registered on the
Config
to parse the entry.If the parser is a JSON parser, the starting/trailing
"[" /"]" in the value are optional.- Returns:
- The value, or
Optional.empty()
if the section or key does not exist. - Throws:
ParseException
- If value could not be parsed.
-
asList
Returns this entry as a parsed list.If the parser is a JSON parser, the starting/trailing
"[" /"]" in the value are optional.- Parameters:
parser
- The parser to use to parse the value, orOptional.empty()
to use the parser defined on the config.- Returns:
- The value, or
Optional.empty()
if the section or key does not exist. - Throws:
ParseException
- If value could not be parsed.
-
getKey
Returns the name of this entry.- Returns:
- The name of this entry.
-
getValue
Returns the raw value of this entry.- Returns:
- The raw value of this entry.
-
getComment
Returns the same-line comment of this entry.- Returns:
- The same-line comment of this entry.
-
getPreLines
Returns the pre-lines of this entry.- Returns:
- The pre-lines of this entry as an unmodifiable list.
-
getModifiers
Returns the modifiers for this entry.- Returns:
- The modifiers for this entry, or
null if it has no modifiers.
-