summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorNathan Adams <dinnerbone@dinnerbone.com>2011-10-26 09:47:51 +0100
committerNathan Adams <dinnerbone@dinnerbone.com>2011-10-26 09:47:51 +0100
commite33fce94b5b8a7082b6a32ae3e420262d8a7126f (patch)
treecc01919e79aba68a36e2ec6f1737b46ee5b6affc /src/main/java/org
parentb1a44c2161832721980c182ee0cb63192f405ca5 (diff)
downloadbukkit-e33fce94b5b8a7082b6a32ae3e420262d8a7126f.tar
bukkit-e33fce94b5b8a7082b6a32ae3e420262d8a7126f.tar.gz
bukkit-e33fce94b5b8a7082b6a32ae3e420262d8a7126f.tar.lz
bukkit-e33fce94b5b8a7082b6a32ae3e420262d8a7126f.tar.xz
bukkit-e33fce94b5b8a7082b6a32ae3e420262d8a7126f.zip
Added helper methods such as getStringList to ConfigurationSection
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/bukkit/configuration/ConfigurationSection.java150
-rw-r--r--src/main/java/org/bukkit/configuration/MemorySection.java305
2 files changed, 455 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/configuration/ConfigurationSection.java b/src/main/java/org/bukkit/configuration/ConfigurationSection.java
index 739a3359..0843c04e 100644
--- a/src/main/java/org/bukkit/configuration/ConfigurationSection.java
+++ b/src/main/java/org/bukkit/configuration/ConfigurationSection.java
@@ -390,6 +390,156 @@ public interface ConfigurationSection {
public boolean isList(String path);
+ /**
+ * Gets the requested List of String by path.
+ * <p>
+ * If the List does not exist but a default value has been specified, this
+ * will return the default value. If the List does not exist and no default
+ * value was specified, this will return null.
+ * <p>
+ * This method will attempt to cast any values into a String if possible, but may
+ * miss any values out if they are not compatible.
+ *
+ * @param path Path of the List to get.
+ * @return Requested List of String.
+ */
+ public List<String> getStringList(String path);
+
+ /**
+ * Gets the requested List of Integer by path.
+ * <p>
+ * If the List does not exist but a default value has been specified, this
+ * will return the default value. If the List does not exist and no default
+ * value was specified, this will return null.
+ * <p>
+ * This method will attempt to cast any values into a Integer if possible, but may
+ * miss any values out if they are not compatible.
+ *
+ * @param path Path of the List to get.
+ * @return Requested List of Integer.
+ */
+ public List<Integer> getIntegerList(String path);
+
+ /**
+ * Gets the requested List of Boolean by path.
+ * <p>
+ * If the List does not exist but a default value has been specified, this
+ * will return the default value. If the List does not exist and no default
+ * value was specified, this will return null.
+ * <p>
+ * This method will attempt to cast any values into a Boolean if possible, but may
+ * miss any values out if they are not compatible.
+ *
+ * @param path Path of the List to get.
+ * @return Requested List of Boolean.
+ */
+ public List<Boolean> getBooleanList(String path);
+
+ /**
+ * Gets the requested List of Double by path.
+ * <p>
+ * If the List does not exist but a default value has been specified, this
+ * will return the default value. If the List does not exist and no default
+ * value was specified, this will return null.
+ * <p>
+ * This method will attempt to cast any values into a Double if possible, but may
+ * miss any values out if they are not compatible.
+ *
+ * @param path Path of the List to get.
+ * @return Requested List of Double.
+ */
+ public List<Double> getDoubleList(String path);
+
+ /**
+ * Gets the requested List of Float by path.
+ * <p>
+ * If the List does not exist but a default value has been specified, this
+ * will return the default value. If the List does not exist and no default
+ * value was specified, this will return null.
+ * <p>
+ * This method will attempt to cast any values into a Float if possible, but may
+ * miss any values out if they are not compatible.
+ *
+ * @param path Path of the List to get.
+ * @return Requested List of Float.
+ */
+ public List<Float> getFloatList(String path);
+
+ /**
+ * Gets the requested List of Long by path.
+ * <p>
+ * If the List does not exist but a default value has been specified, this
+ * will return the default value. If the List does not exist and no default
+ * value was specified, this will return null.
+ * <p>
+ * This method will attempt to cast any values into a Long if possible, but may
+ * miss any values out if they are not compatible.
+ *
+ * @param path Path of the List to get.
+ * @return Requested List of Long.
+ */
+ public List<Long> getLongList(String path);
+
+ /**
+ * Gets the requested List of Byte by path.
+ * <p>
+ * If the List does not exist but a default value has been specified, this
+ * will return the default value. If the List does not exist and no default
+ * value was specified, this will return null.
+ * <p>
+ * This method will attempt to cast any values into a Byte if possible, but may
+ * miss any values out if they are not compatible.
+ *
+ * @param path Path of the List to get.
+ * @return Requested List of Byte.
+ */
+ public List<Byte> getByteList(String path);
+
+ /**
+ * Gets the requested List of Character by path.
+ * <p>
+ * If the List does not exist but a default value has been specified, this
+ * will return the default value. If the List does not exist and no default
+ * value was specified, this will return null.
+ * <p>
+ * This method will attempt to cast any values into a Character if possible, but may
+ * miss any values out if they are not compatible.
+ *
+ * @param path Path of the List to get.
+ * @return Requested List of Character.
+ */
+ public List<Character> getCharacterList(String path);
+
+ /**
+ * Gets the requested List of Short by path.
+ * <p>
+ * If the List does not exist but a default value has been specified, this
+ * will return the default value. If the List does not exist and no default
+ * value was specified, this will return null.
+ * <p>
+ * This method will attempt to cast any values into a Short if possible, but may
+ * miss any values out if they are not compatible.
+ *
+ * @param path Path of the List to get.
+ * @return Requested List of Short.
+ */
+ public List<Short> getShortList(String path);
+
+ /**
+ * Gets the requested List of Maps by path.
+ * <p>
+ * If the List does not exist but a default value has been specified, this
+ * will return the default value. If the List does not exist and no default
+ * value was specified, this will return null.
+ * <p>
+ * This method will attempt to cast any values into a Map if possible, but may
+ * miss any values out if they are not compatible.
+ *
+ * @param path Path of the List to get.
+ * @return Requested List of Maps.
+ */
+ public List<Map<String, Object>> getMapList(String path);
+
// Bukkit
/**
diff --git a/src/main/java/org/bukkit/configuration/MemorySection.java b/src/main/java/org/bukkit/configuration/MemorySection.java
index fa330e64..46965c23 100644
--- a/src/main/java/org/bukkit/configuration/MemorySection.java
+++ b/src/main/java/org/bukkit/configuration/MemorySection.java
@@ -2,6 +2,7 @@ package org.bukkit.configuration;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import java.io.File;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -430,6 +431,310 @@ public class MemorySection implements ConfigurationSection {
return val instanceof List;
}
+ public List getStringList(String path) {
+ if (path == null) {
+ throw new IllegalArgumentException("Path cannot be null");
+ }
+
+ List<Object> list = getList(path);
+ List<String> result = new ArrayList();
+
+ for (Object object : list) {
+ if ((object instanceof String) || (isPrimitiveWrapper(object))) {
+ result.add(String.valueOf(object));
+ }
+ }
+
+ return result;
+ }
+
+ public List getIntegerList(String path) {
+ if (path == null) {
+ throw new IllegalArgumentException("Path cannot be null");
+ }
+
+ List<Object> list = getList(path);
+ List<Integer> result = new ArrayList();
+
+ for (Object object : list) {
+ if (object instanceof Integer) {
+ result.add((Integer)object);
+ } else if (object instanceof String) {
+ try {
+ result.add(Integer.valueOf((String)object));
+ } catch (Exception ex) {}
+ } else if (object instanceof Byte) {
+ result.add((Integer)(int)(byte)(Byte)object);
+ } else if (object instanceof Character) {
+ result.add((Integer)(int)(char)(Character)object);
+ } else if (object instanceof Short) {
+ result.add((Integer)(int)(short)(Short)object);
+ } else if (object instanceof Integer) {
+ result.add((Integer)(int)(int)(Integer)object);
+ } else if (object instanceof Long) {
+ result.add((Integer)(int)(long)(Long)object);
+ } else if (object instanceof Float) {
+ result.add((Integer)(int)(float)(Float)object);
+ } else if (object instanceof Double) {
+ result.add((Integer)(int)(double)(Double)object);
+ }
+ }
+
+ return result;
+ }
+
+ public List getBooleanList(String path) {
+ if (path == null) {
+ throw new IllegalArgumentException("Path cannot be null");
+ }
+
+ List<Object> list = getList(path);
+ List<Boolean> result = new ArrayList();
+
+ for (Object object : list) {
+ if (object instanceof Boolean) {
+ result.add((Boolean)object);
+ } else if (object instanceof String) {
+ if (Boolean.TRUE.toString().equals(object)) {
+ result.add(true);
+ } else if (Boolean.FALSE.toString().equals(object)) {
+ result.add(false);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public List getDoubleList(String path) {
+ if (path == null) {
+ throw new IllegalArgumentException("Path cannot be null");
+ }
+
+ List<Object> list = getList(path);
+ List<Double> result = new ArrayList();
+
+ for (Object object : list) {
+ if (object instanceof Double) {
+ result.add((Double)object);
+ } else if (object instanceof String) {
+ try {
+ result.add(Double.valueOf((String)object));
+ } catch (Exception ex) {}
+ } else if (object instanceof Byte) {
+ result.add((Double)(double)(byte)(Byte)object);
+ } else if (object instanceof Character) {
+ result.add((Double)(double)(char)(Character)object);
+ } else if (object instanceof Short) {
+ result.add((Double)(double)(short)(Short)object);
+ } else if (object instanceof Integer) {
+ result.add((Double)(double)(int)(Integer)object);
+ } else if (object instanceof Long) {
+ result.add((Double)(double)(long)(Long)object);
+ } else if (object instanceof Float) {
+ result.add((Double)(double)(float)(Float)object);
+ } else if (object instanceof Double) {
+ result.add((Double)(double)(double)(Double)object);
+ }
+ }
+
+ return result;
+ }
+
+ public List getFloatList(String path) {
+ if (path == null) {
+ throw new IllegalArgumentException("Path cannot be null");
+ }
+
+ List<Object> list = getList(path);
+ List<Float> result = new ArrayList();
+
+ for (Object object : list) {
+ if (object instanceof Float) {
+ result.add((Float)object);
+ } else if (object instanceof String) {
+ try {
+ result.add(Float.valueOf((String)object));
+ } catch (Exception ex) {}
+ } else if (object instanceof Byte) {
+ result.add((Float)(float)(byte)(Byte)object);
+ } else if (object instanceof Character) {
+ result.add((Float)(float)(char)(Character)object);
+ } else if (object instanceof Short) {
+ result.add((Float)(float)(short)(Short)object);
+ } else if (object instanceof Integer) {
+ result.add((Float)(float)(int)(Integer)object);
+ } else if (object instanceof Long) {
+ result.add((Float)(float)(long)(Long)object);
+ } else if (object instanceof Float) {
+ result.add((Float)(float)(float)(Float)object);
+ } else if (object instanceof Double) {
+ result.add((Float)(float)(double)(Double)object);
+ }
+ }
+
+ return result;
+ }
+
+ public List getLongList(String path) {
+ if (path == null) {
+ throw new IllegalArgumentException("Path cannot be null");
+ }
+
+ List<Object> list = getList(path);
+ List<Long> result = new ArrayList();
+
+ for (Object object : list) {
+ if (object instanceof Long) {
+ result.add((Long)object);
+ } else if (object instanceof String) {
+ try {
+ result.add(Long.valueOf((String)object));
+ } catch (Exception ex) {}
+ } else if (object instanceof Byte) {
+ result.add((Long)(long)(byte)(Byte)object);
+ } else if (object instanceof Character) {
+ result.add((Long)(long)(char)(Character)object);
+ } else if (object instanceof Short) {
+ result.add((Long)(long)(short)(Short)object);
+ } else if (object instanceof Integer) {
+ result.add((Long)(long)(int)(Integer)object);
+ } else if (object instanceof Long) {
+ result.add((Long)(long)(long)(Long)object);
+ } else if (object instanceof Float) {
+ result.add((Long)(long)(float)(Float)object);
+ } else if (object instanceof Double) {
+ result.add((Long)(long)(double)(Double)object);
+ }
+ }
+
+ return result;
+ }
+
+ public List getByteList(String path) {
+ if (path == null) {
+ throw new IllegalArgumentException("Path cannot be null");
+ }
+
+ List<Object> list = getList(path);
+ List<Byte> result = new ArrayList();
+
+ for (Object object : list) {
+ if (object instanceof Byte) {
+ result.add((Byte)object);
+ } else if (object instanceof String) {
+ try {
+ result.add(Byte.valueOf((String)object));
+ } catch (Exception ex) {}
+ } else if (object instanceof Byte) {
+ result.add((Byte)(byte)(byte)(Byte)object);
+ } else if (object instanceof Character) {
+ result.add((Byte)(byte)(char)(Character)object);
+ } else if (object instanceof Short) {
+ result.add((Byte)(byte)(short)(Short)object);
+ } else if (object instanceof Integer) {
+ result.add((Byte)(byte)(int)(Integer)object);
+ } else if (object instanceof Long) {
+ result.add((Byte)(byte)(long)(Long)object);
+ } else if (object instanceof Float) {
+ result.add((Byte)(byte)(float)(Float)object);
+ } else if (object instanceof Double) {
+ result.add((Byte)(byte)(double)(Double)object);
+ }
+ }
+
+ return result;
+ }
+
+ public List getCharacterList(String path) {
+ if (path == null) {
+ throw new IllegalArgumentException("Path cannot be null");
+ }
+
+ List<Object> list = getList(path);
+ List<Character> result = new ArrayList();
+
+ for (Object object : list) {
+ if (object instanceof Character) {
+ result.add((Character)object);
+ } else if (object instanceof String) {
+ String str = (String)object;
+
+ if (str.length() == 1) {
+ result.add(str.charAt(0));
+ }
+ } else if (object instanceof Byte) {
+ result.add((Character)(char)(byte)(Byte)object);
+ } else if (object instanceof Character) {
+ result.add((Character)(char)(char)(Character)object);
+ } else if (object instanceof Short) {
+ result.add((Character)(char)(short)(Short)object);
+ } else if (object instanceof Integer) {
+ result.add((Character)(char)(int)(Integer)object);
+ } else if (object instanceof Long) {
+ result.add((Character)(char)(long)(Long)object);
+ } else if (object instanceof Float) {
+ result.add((Character)(char)(float)(Float)object);
+ } else if (object instanceof Double) {
+ result.add((Character)(char)(double)(Double)object);
+ }
+ }
+
+ return result;
+ }
+
+ public List getShortList(String path) {
+ if (path == null) {
+ throw new IllegalArgumentException("Path cannot be null");
+ }
+
+ List<Object> list = getList(path);
+ List<Short> result = new ArrayList();
+
+ for (Object object : list) {
+ if (object instanceof Short) {
+ result.add((Short)object);
+ } else if (object instanceof String) {
+ try {
+ result.add(Short.valueOf((String)object));
+ } catch (Exception ex) {}
+ } else if (object instanceof Byte) {
+ result.add((Short)(short)(byte)(Byte)object);
+ } else if (object instanceof Character) {
+ result.add((Short)(short)(char)(Character)object);
+ } else if (object instanceof Short) {
+ result.add((Short)(short)(short)(Short)object);
+ } else if (object instanceof Integer) {
+ result.add((Short)(short)(int)(Integer)object);
+ } else if (object instanceof Long) {
+ result.add((Short)(short)(long)(Long)object);
+ } else if (object instanceof Float) {
+ result.add((Short)(short)(float)(Float)object);
+ } else if (object instanceof Double) {
+ result.add((Short)(short)(double)(Double)object);
+ }
+ }
+
+ return result;
+ }
+
+ public List<Map<String, Object>> getMapList(String path) {
+ if (path == null) {
+ throw new IllegalArgumentException("Path cannot be null");
+ }
+
+ List<Object> list = getList(path);
+ List<Map<String, Object>> result = new ArrayList();
+
+ for (Object object : list) {
+ if (object instanceof Map) {
+ result.add((Map<String, Object>)object);
+ }
+ }
+
+ return result;
+ }
+
// Bukkit
public Vector getVector(String path) {
if (path == null) {