Getting Values

Example of getting values

Getting data types

Example
// Getting a object value.
Object object1 = configuration.get("path0");
Object object2 = configuration.get("path0", "alternative object");

// Getting a string value.
String value1 = configuration.getString("path1");
String value2 = configuration.getString("path1", "If the path doesnt exist or it is not a string.");

// Geting a integer value.
int value3 = configuration.getInteger("path2");
int value4 = configuration.getInteger("path2", 2);

// Getting a long value.
// If the value is actually a integer
// it will convert it into a long.
long value5 = configuration.getLong("path3");
long value6 = configuration.getLong("path3", 2L);

// Getting a double value.
// If the value is actually a integer
// it will convert it into a double.
double value7 = configuration.getDouble("path4");
double value8 = configuration.getDouble("path4", 0.1D);

// Getting a boolean value.
// Defaults to false unless specifying a seccond argument.
boolean value9 = configuration.getBoolean("path5");
boolean value10 = configuration.getBoolean("path5", true);

// Getting a list.
// If the path doesnt exist or the value is not a list
// it will return null.
List<?> list1 = configuration.getList("path6");
List<?> list2 = configuration.getList("path6", new ArrayList<>());

// Getting a string list.
// If the path doesnt exist or the value is not a list
// it will return null.
List<String> list3 = configuration.getListString("path7");
List<String> list4 = configuration.getListString("path7", new ArrayList<>());

// Getting a integer list.
// If the path doesnt exist or the value is not a list
// it will return null.
List<Integer> list5 = configuration.getListInteger("path8");
List<Integer> list6 = configuration.getListInteger("path8", new ArrayList<>());

// Getting a map of string to object.
// If the path doesnt exist or the value is not a map
// it will return null.
Map<String, Object> map1 = configuration.getMap("path9");
Map<String, Object> map2 = configuration.getMap("path9", new HashMap<>());

// Getting a class instance.
// This will use gson to convert the map into the class.
// If the path doesnt exist or the value is not a class
// it will return null.
ClassObject classObject1 = configuration.getClass("path10", ClassObject.class);
ClassObject classObject2 = configuration.getClass("path10", ClassObject.class, defaultClass);

Other methods

Example
// Getting a section of the configuration.
ConfigurationSection section = configuration.getSection("location1.location2");

// Getting the location of the configuration section.
// In this example it will return "location1.location2".
String fromBasePath1 = section.getBasePath();

// In this example it will return "location1.location2.location3"
String fromBasePath2 = section.getBasePath("location3");

// Used to get the sections map keys.
// Can be used to iterate though the sections.
List<String> keys = section.getKeys();

Last updated