diff --git a/.gitignore b/.gitignore
index 90dc65d43..1e4e21fc2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,4 +6,5 @@
/target/PlotSquared-Uber.jar
/target/maven-archiver
*.project
-*.classpath
\ No newline at end of file
+*.classpath
+/target/
diff --git a/src/main/java/com/intellectualcrafters/configuration/Configuration.java b/src/main/java/com/intellectualcrafters/configuration/Configuration.java
index a912b5323..58e826d78 100644
--- a/src/main/java/com/intellectualcrafters/configuration/Configuration.java
+++ b/src/main/java/com/intellectualcrafters/configuration/Configuration.java
@@ -5,7 +5,8 @@ import java.util.Map;
/**
* Represents a source of configurable options and settings
*/
-public interface Configuration extends ConfigurationSection {
+public interface Configuration extends ConfigurationSection
+{
/**
* Sets the default value of the given path as provided.
*
@@ -20,7 +21,8 @@ public interface Configuration extends ConfigurationSection {
* @param value Value to set the default to.
* @throws IllegalArgumentException Thrown if path is null.
*/
- public void addDefault(String path, Object value);
+ @Override
+ public void addDefault(final String path, final Object value);
/**
* Sets the default values of the given paths as provided.
@@ -32,7 +34,7 @@ public interface Configuration extends ConfigurationSection {
* @param defaults A map of Path->Values to add to defaults.
* @throws IllegalArgumentException Thrown if defaults is null.
*/
- public void addDefaults(Map defaults);
+ public void addDefaults(final Map defaults);
/**
* Sets the default values of the given paths as provided.
@@ -49,7 +51,7 @@ public interface Configuration extends ConfigurationSection {
* @param defaults A configuration holding a list of defaults to copy.
* @throws IllegalArgumentException Thrown if defaults is null or this.
*/
- public void addDefaults(Configuration defaults);
+ public void addDefaults(final Configuration defaults);
/**
* Sets the source of all default values for this {@link Configuration}.
@@ -60,7 +62,7 @@ public interface Configuration extends ConfigurationSection {
* @param defaults New source of default values for this configuration.
* @throws IllegalArgumentException Thrown if defaults is null or this.
*/
- public void setDefaults(Configuration defaults);
+ public void setDefaults(final Configuration defaults);
/**
* Gets the source {@link Configuration} for this configuration.
diff --git a/src/main/java/com/intellectualcrafters/configuration/ConfigurationOptions.java b/src/main/java/com/intellectualcrafters/configuration/ConfigurationOptions.java
index 4f32c6545..3768af587 100644
--- a/src/main/java/com/intellectualcrafters/configuration/ConfigurationOptions.java
+++ b/src/main/java/com/intellectualcrafters/configuration/ConfigurationOptions.java
@@ -4,12 +4,14 @@ package com.intellectualcrafters.configuration;
* Various settings for controlling the input and output of a {@link
* Configuration}
*/
-public class ConfigurationOptions {
+public class ConfigurationOptions
+{
private char pathSeparator = '.';
private boolean copyDefaults = false;
private final Configuration configuration;
- protected ConfigurationOptions(Configuration configuration) {
+ protected ConfigurationOptions(final Configuration configuration)
+ {
this.configuration = configuration;
}
@@ -18,7 +20,8 @@ public class ConfigurationOptions {
*
* @return Parent configuration
*/
- public Configuration configuration() {
+ public Configuration configuration()
+ {
return configuration;
}
@@ -31,7 +34,8 @@ public class ConfigurationOptions {
*
* @return Path separator
*/
- public char pathSeparator() {
+ public char pathSeparator()
+ {
return pathSeparator;
}
@@ -45,8 +49,9 @@ public class ConfigurationOptions {
* @param value Path separator
* @return This object, for chaining
*/
- public ConfigurationOptions pathSeparator(char value) {
- this.pathSeparator = value;
+ public ConfigurationOptions pathSeparator(final char value)
+ {
+ pathSeparator = value;
return this;
}
@@ -64,7 +69,8 @@ public class ConfigurationOptions {
*
* @return Whether or not defaults are directly copied
*/
- public boolean copyDefaults() {
+ public boolean copyDefaults()
+ {
return copyDefaults;
}
@@ -83,8 +89,9 @@ public class ConfigurationOptions {
* @param value Whether or not defaults are directly copied
* @return This object, for chaining
*/
- public ConfigurationOptions copyDefaults(boolean value) {
- this.copyDefaults = value;
+ public ConfigurationOptions copyDefaults(final boolean value)
+ {
+ copyDefaults = value;
return this;
}
}
diff --git a/src/main/java/com/intellectualcrafters/configuration/ConfigurationSection.java b/src/main/java/com/intellectualcrafters/configuration/ConfigurationSection.java
index 9e368b566..d2f3dbd1b 100644
--- a/src/main/java/com/intellectualcrafters/configuration/ConfigurationSection.java
+++ b/src/main/java/com/intellectualcrafters/configuration/ConfigurationSection.java
@@ -7,7 +7,8 @@ import java.util.Set;
/**
* Represents a section of a {@link Configuration}
*/
-public interface ConfigurationSection {
+public interface ConfigurationSection
+{
/**
* Gets a set containing all keys in this section.
*
@@ -22,7 +23,7 @@ public interface ConfigurationSection {
* list.
* @return Set of keys contained within this ConfigurationSection.
*/
- public Set getKeys(boolean deep);
+ public Set getKeys(final boolean deep);
/**
* Gets a Map containing all keys and their values for this section.
@@ -38,7 +39,7 @@ public interface ConfigurationSection {
* list.
* @return Map of keys and values of this section.
*/
- public Map getValues(boolean deep);
+ public Map getValues(final boolean deep);
/**
* Checks if this {@link ConfigurationSection} contains the given path.
@@ -51,7 +52,7 @@ public interface ConfigurationSection {
* default or being set.
* @throws IllegalArgumentException Thrown when path is null.
*/
- public boolean contains(String path);
+ public boolean contains(final String path);
/**
* Checks if this {@link ConfigurationSection} has a value set for the
@@ -65,7 +66,7 @@ public interface ConfigurationSection {
* having a default.
* @throws IllegalArgumentException Thrown when path is null.
*/
- public boolean isSet(String path);
+ public boolean isSet(final String path);
/**
* Gets the path of this {@link ConfigurationSection} from its root {@link
@@ -132,7 +133,7 @@ public interface ConfigurationSection {
* @param path Path of the Object to get.
* @return Requested Object.
*/
- public Object get(String path);
+ public Object get(final String path);
/**
* Gets the requested Object by path, returning a default value if not
@@ -146,7 +147,7 @@ public interface ConfigurationSection {
* @param def The default value to return if the path is not found.
* @return Requested Object.
*/
- public Object get(String path, Object def);
+ public Object get(final String path, final Object def);
/**
* Sets the specified path to the given value.
@@ -162,7 +163,7 @@ public interface ConfigurationSection {
* @param path Path of the object to set.
* @param value New value to set the path to.
*/
- public void set(String path, Object value);
+ public void set(final String path, final Object value);
/**
* Creates an empty {@link ConfigurationSection} at the specified path.
@@ -174,7 +175,7 @@ public interface ConfigurationSection {
* @param path Path to create the section at.
* @return Newly created section
*/
- public ConfigurationSection createSection(String path);
+ public ConfigurationSection createSection(final String path);
/**
* Creates a {@link ConfigurationSection} at the specified path, with
@@ -188,7 +189,7 @@ public interface ConfigurationSection {
* @param map The values to used.
* @return Newly created section
*/
- public ConfigurationSection createSection(String path, Map, ?> map);
+ public ConfigurationSection createSection(final String path, final Map, ?> map);
// Primitives
/**
@@ -201,7 +202,7 @@ public interface ConfigurationSection {
* @param path Path of the String to get.
* @return Requested String.
*/
- public String getString(String path);
+ public String getString(final String path);
/**
* Gets the requested String by path, returning a default value if not
@@ -216,7 +217,7 @@ public interface ConfigurationSection {
* not a String.
* @return Requested String.
*/
- public String getString(String path, String def);
+ public String getString(final String path, final String def);
/**
* Checks if the specified path is a String.
@@ -229,7 +230,7 @@ public interface ConfigurationSection {
* @param path Path of the String to check.
* @return Whether or not the specified path is a String.
*/
- public boolean isString(String path);
+ public boolean isString(final String path);
/**
* Gets the requested int by path.
@@ -241,7 +242,7 @@ public interface ConfigurationSection {
* @param path Path of the int to get.
* @return Requested int.
*/
- public int getInt(String path);
+ public int getInt(final String path);
/**
* Gets the requested int by path, returning a default value if not found.
@@ -255,7 +256,7 @@ public interface ConfigurationSection {
* not an int.
* @return Requested int.
*/
- public int getInt(String path, int def);
+ public int getInt(final String path, final int def);
/**
* Checks if the specified path is an int.
@@ -268,7 +269,7 @@ public interface ConfigurationSection {
* @param path Path of the int to check.
* @return Whether or not the specified path is an int.
*/
- public boolean isInt(String path);
+ public boolean isInt(final String path);
/**
* Gets the requested boolean by path.
@@ -280,7 +281,7 @@ public interface ConfigurationSection {
* @param path Path of the boolean to get.
* @return Requested boolean.
*/
- public boolean getBoolean(String path);
+ public boolean getBoolean(final String path);
/**
* Gets the requested boolean by path, returning a default value if not
@@ -295,7 +296,7 @@ public interface ConfigurationSection {
* not a boolean.
* @return Requested boolean.
*/
- public boolean getBoolean(String path, boolean def);
+ public boolean getBoolean(final String path, final boolean def);
/**
* Checks if the specified path is a boolean.
@@ -308,7 +309,7 @@ public interface ConfigurationSection {
* @param path Path of the boolean to check.
* @return Whether or not the specified path is a boolean.
*/
- public boolean isBoolean(String path);
+ public boolean isBoolean(final String path);
/**
* Gets the requested double by path.
@@ -320,7 +321,7 @@ public interface ConfigurationSection {
* @param path Path of the double to get.
* @return Requested double.
*/
- public double getDouble(String path);
+ public double getDouble(final String path);
/**
* Gets the requested double by path, returning a default value if not
@@ -335,7 +336,7 @@ public interface ConfigurationSection {
* not a double.
* @return Requested double.
*/
- public double getDouble(String path, double def);
+ public double getDouble(final String path, final double def);
/**
* Checks if the specified path is a double.
@@ -348,7 +349,7 @@ public interface ConfigurationSection {
* @param path Path of the double to check.
* @return Whether or not the specified path is a double.
*/
- public boolean isDouble(String path);
+ public boolean isDouble(final String path);
/**
* Gets the requested long by path.
@@ -360,7 +361,7 @@ public interface ConfigurationSection {
* @param path Path of the long to get.
* @return Requested long.
*/
- public long getLong(String path);
+ public long getLong(final String path);
/**
* Gets the requested long by path, returning a default value if not
@@ -375,7 +376,7 @@ public interface ConfigurationSection {
* not a long.
* @return Requested long.
*/
- public long getLong(String path, long def);
+ public long getLong(final String path, final long def);
/**
* Checks if the specified path is a long.
@@ -388,7 +389,7 @@ public interface ConfigurationSection {
* @param path Path of the long to check.
* @return Whether or not the specified path is a long.
*/
- public boolean isLong(String path);
+ public boolean isLong(final String path);
// Java
/**
@@ -401,7 +402,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List.
*/
- public List> getList(String path);
+ public List> getList(final String path);
/**
* Gets the requested List by path, returning a default value if not
@@ -416,7 +417,7 @@ public interface ConfigurationSection {
* not a List.
* @return Requested List.
*/
- public List> getList(String path, List> def);
+ public List> getList(final String path, final List> def);
/**
* Checks if the specified path is a List.
@@ -429,7 +430,7 @@ public interface ConfigurationSection {
* @param path Path of the List to check.
* @return Whether or not the specified path is a List.
*/
- public boolean isList(String path);
+ public boolean isList(final String path);
/**
* Gets the requested List of String by path.
@@ -444,7 +445,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List of String.
*/
- public List getStringList(String path);
+ public List getStringList(final String path);
/**
* Gets the requested List of Integer by path.
@@ -459,7 +460,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List of Integer.
*/
- public List getIntegerList(String path);
+ public List getIntegerList(final String path);
/**
* Gets the requested List of Boolean by path.
@@ -474,7 +475,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List of Boolean.
*/
- public List getBooleanList(String path);
+ public List getBooleanList(final String path);
/**
* Gets the requested List of Double by path.
@@ -489,7 +490,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List of Double.
*/
- public List getDoubleList(String path);
+ public List getDoubleList(final String path);
/**
* Gets the requested List of Float by path.
@@ -504,7 +505,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List of Float.
*/
- public List getFloatList(String path);
+ public List getFloatList(final String path);
/**
* Gets the requested List of Long by path.
@@ -519,7 +520,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List of Long.
*/
- public List getLongList(String path);
+ public List getLongList(final String path);
/**
* Gets the requested List of Byte by path.
@@ -534,7 +535,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List of Byte.
*/
- public List getByteList(String path);
+ public List getByteList(final String path);
/**
* Gets the requested List of Character by path.
@@ -549,7 +550,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List of Character.
*/
- public List getCharacterList(String path);
+ public List getCharacterList(final String path);
/**
* Gets the requested List of Short by path.
@@ -564,7 +565,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List of Short.
*/
- public List getShortList(String path);
+ public List getShortList(final String path);
/**
* Gets the requested List of Maps by path.
@@ -579,7 +580,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List of Maps.
*/
- public List> getMapList(String path);
+ public List> getMapList(final String path);
/**
* Gets the requested ConfigurationSection by path.
@@ -592,7 +593,7 @@ public interface ConfigurationSection {
* @param path Path of the ConfigurationSection to get.
* @return Requested ConfigurationSection.
*/
- public ConfigurationSection getConfigurationSection(String path);
+ public ConfigurationSection getConfigurationSection(final String path);
/**
* Checks if the specified path is a ConfigurationSection.
@@ -606,7 +607,7 @@ public interface ConfigurationSection {
* @param path Path of the ConfigurationSection to check.
* @return Whether or not the specified path is a ConfigurationSection.
*/
- public boolean isConfigurationSection(String path);
+ public boolean isConfigurationSection(final String path);
/**
* Gets the equivalent {@link ConfigurationSection} from the default
@@ -638,5 +639,5 @@ public interface ConfigurationSection {
* @param value Value to set the default to.
* @throws IllegalArgumentException Thrown if path is null.
*/
- public void addDefault(String path, Object value);
+ public void addDefault(final String path, final Object value);
}
diff --git a/src/main/java/com/intellectualcrafters/configuration/InvalidConfigurationException.java b/src/main/java/com/intellectualcrafters/configuration/InvalidConfigurationException.java
index 38e9b0cb3..c7769dd7d 100644
--- a/src/main/java/com/intellectualcrafters/configuration/InvalidConfigurationException.java
+++ b/src/main/java/com/intellectualcrafters/configuration/InvalidConfigurationException.java
@@ -4,13 +4,15 @@ package com.intellectualcrafters.configuration;
* Exception thrown when attempting to load an invalid {@link Configuration}
*/
@SuppressWarnings("serial")
-public class InvalidConfigurationException extends Exception {
+public class InvalidConfigurationException extends Exception
+{
/**
* Creates a new instance of InvalidConfigurationException without a
* message or cause.
*/
- public InvalidConfigurationException() {}
+ public InvalidConfigurationException()
+ {}
/**
* Constructs an instance of InvalidConfigurationException with the
@@ -18,7 +20,8 @@ public class InvalidConfigurationException extends Exception {
*
* @param msg The details of the exception.
*/
- public InvalidConfigurationException(String msg) {
+ public InvalidConfigurationException(final String msg)
+ {
super(msg);
}
@@ -28,7 +31,8 @@ public class InvalidConfigurationException extends Exception {
*
* @param cause The cause of the exception.
*/
- public InvalidConfigurationException(Throwable cause) {
+ public InvalidConfigurationException(final Throwable cause)
+ {
super(cause);
}
@@ -39,7 +43,8 @@ public class InvalidConfigurationException extends Exception {
* @param cause The cause of the exception.
* @param msg The details of the exception.
*/
- public InvalidConfigurationException(String msg, Throwable cause) {
+ public InvalidConfigurationException(final String msg, final Throwable cause)
+ {
super(msg, cause);
}
}
diff --git a/src/main/java/com/intellectualcrafters/configuration/MemoryConfiguration.java b/src/main/java/com/intellectualcrafters/configuration/MemoryConfiguration.java
index ad81ab8f8..5448f837a 100644
--- a/src/main/java/com/intellectualcrafters/configuration/MemoryConfiguration.java
+++ b/src/main/java/com/intellectualcrafters/configuration/MemoryConfiguration.java
@@ -7,14 +7,16 @@ import java.util.Map;
* from any source, and stores all values in memory only.
* This is useful for temporary Configurations for providing defaults.
*/
-public class MemoryConfiguration extends MemorySection implements Configuration {
+public class MemoryConfiguration extends MemorySection implements Configuration
+{
protected Configuration defaults;
protected MemoryConfigurationOptions options;
/**
* Creates an empty {@link MemoryConfiguration} with no default values.
*/
- public MemoryConfiguration() {}
+ public MemoryConfiguration()
+ {}
/**
* Creates an empty {@link MemoryConfiguration} using the specified {@link
@@ -23,51 +25,67 @@ public class MemoryConfiguration extends MemorySection implements Configuration
* @param defaults Default value provider
* @throws IllegalArgumentException Thrown if defaults is null
*/
- public MemoryConfiguration(Configuration defaults) {
+ public MemoryConfiguration(final Configuration defaults)
+ {
this.defaults = defaults;
}
@Override
- public void addDefault(String path, Object value) {
- if (path == null) throw new NullPointerException("Path may not be null");
- if (defaults == null) {
+ public void addDefault(final String path, final Object value)
+ {
+ if (path == null) { throw new NullPointerException("Path may not be null"); }
+ if (defaults == null)
+ {
defaults = new MemoryConfiguration();
}
defaults.set(path, value);
}
- public void addDefaults(Map defaults) {
- if (defaults == null) throw new NullPointerException("Defaults may not be null");
+ @Override
+ public void addDefaults(final Map defaults)
+ {
+ if (defaults == null) { throw new NullPointerException("Defaults may not be null"); }
- for (Map.Entry entry : defaults.entrySet()) {
+ for (final Map.Entry entry : defaults.entrySet())
+ {
addDefault(entry.getKey(), entry.getValue());
}
}
- public void addDefaults(Configuration defaults) {
- if (defaults == null) throw new NullPointerException("Defaults may not be null");
+ @Override
+ public void addDefaults(final Configuration defaults)
+ {
+ if (defaults == null) { throw new NullPointerException("Defaults may not be null"); }
addDefaults(defaults.getValues(true));
}
- public void setDefaults(Configuration defaults) {
- if (defaults == null) throw new NullPointerException("Defaults may not be null");
+ @Override
+ public void setDefaults(final Configuration defaults)
+ {
+ if (defaults == null) { throw new NullPointerException("Defaults may not be null"); }
this.defaults = defaults;
}
- public Configuration getDefaults() {
+ @Override
+ public Configuration getDefaults()
+ {
return defaults;
}
@Override
- public ConfigurationSection getParent() {
+ public ConfigurationSection getParent()
+ {
return null;
}
- public MemoryConfigurationOptions options() {
- if (options == null) {
+ @Override
+ public MemoryConfigurationOptions options()
+ {
+ if (options == null)
+ {
options = new MemoryConfigurationOptions(this);
}
diff --git a/src/main/java/com/intellectualcrafters/configuration/MemoryConfigurationOptions.java b/src/main/java/com/intellectualcrafters/configuration/MemoryConfigurationOptions.java
index 1720118c6..4e6af36c2 100644
--- a/src/main/java/com/intellectualcrafters/configuration/MemoryConfigurationOptions.java
+++ b/src/main/java/com/intellectualcrafters/configuration/MemoryConfigurationOptions.java
@@ -4,24 +4,29 @@ package com.intellectualcrafters.configuration;
* Various settings for controlling the input and output of a {@link
* MemoryConfiguration}
*/
-public class MemoryConfigurationOptions extends ConfigurationOptions {
- protected MemoryConfigurationOptions(MemoryConfiguration configuration) {
+public class MemoryConfigurationOptions extends ConfigurationOptions
+{
+ protected MemoryConfigurationOptions(final MemoryConfiguration configuration)
+ {
super(configuration);
}
@Override
- public MemoryConfiguration configuration() {
+ public MemoryConfiguration configuration()
+ {
return (MemoryConfiguration) super.configuration();
}
@Override
- public MemoryConfigurationOptions copyDefaults(boolean value) {
+ public MemoryConfigurationOptions copyDefaults(final boolean value)
+ {
super.copyDefaults(value);
return this;
}
@Override
- public MemoryConfigurationOptions pathSeparator(char value) {
+ public MemoryConfigurationOptions pathSeparator(final char value)
+ {
super.pathSeparator(value);
return this;
}
diff --git a/src/main/java/com/intellectualcrafters/configuration/MemorySection.java b/src/main/java/com/intellectualcrafters/configuration/MemorySection.java
index 2c3bc0f4c..042e9efe4 100644
--- a/src/main/java/com/intellectualcrafters/configuration/MemorySection.java
+++ b/src/main/java/com/intellectualcrafters/configuration/MemorySection.java
@@ -10,70 +10,74 @@ import java.util.Set;
/**
* A type of {@link ConfigurationSection} that is stored in memory.
*/
-public class MemorySection implements ConfigurationSection {
+public class MemorySection implements ConfigurationSection
+{
protected final Map map = new LinkedHashMap();
private final Configuration root;
private final ConfigurationSection parent;
private final String path;
private final String fullPath;
- public static double toDouble(Object obj, double def) {
- if (obj instanceof Number) {
- return ((Number) obj).doubleValue();
- }
- if (obj instanceof String) {
- try {
+ public static double toDouble(final Object obj, final double def)
+ {
+ if (obj instanceof Number) { return ((Number) obj).doubleValue(); }
+ if (obj instanceof String)
+ {
+ try
+ {
return Double.parseDouble((String) obj);
}
- catch (Exception e) {}
+ catch (final Exception e)
+ {}
}
- else if (obj instanceof List) {
- List> val = ((List>) obj);
- if (val.size() > 0) {
- return toDouble(val.get(0), def);
- }
+ else if (obj instanceof List)
+ {
+ final List> val = ((List>) obj);
+ if (val.size() > 0) { return toDouble(val.get(0), def); }
}
return def;
}
-
- public static int toInt(Object obj, int def) {
- if (obj instanceof Number) {
- return ((Number) obj).intValue();
- }
- if (obj instanceof String) {
- try {
+
+ public static int toInt(final Object obj, final int def)
+ {
+ if (obj instanceof Number) { return ((Number) obj).intValue(); }
+ if (obj instanceof String)
+ {
+ try
+ {
return Integer.parseInt((String) obj);
}
- catch (Exception e) {}
+ catch (final Exception e)
+ {}
}
- else if (obj instanceof List) {
- List> val = ((List>) obj);
- if (val.size() > 0) {
- return toInt(val.get(0), def);
- }
+ else if (obj instanceof List)
+ {
+ final List> val = ((List>) obj);
+ if (val.size() > 0) { return toInt(val.get(0), def); }
}
return def;
}
-
- public static long toLong(Object obj, long def) {
- if (obj instanceof Number) {
- return ((Number) obj).longValue();
- }
- if (obj instanceof String) {
- try {
+
+ public static long toLong(final Object obj, final long def)
+ {
+ if (obj instanceof Number) { return ((Number) obj).longValue(); }
+ if (obj instanceof String)
+ {
+ try
+ {
return Long.parseLong((String) obj);
}
- catch (Exception e) {}
+ catch (final Exception e)
+ {}
}
- else if (obj instanceof List) {
- List> val = ((List>) obj);
- if (val.size() > 0) {
- return toLong(val.get(0), def);
- }
+ else if (obj instanceof List)
+ {
+ final List> val = ((List>) obj);
+ if (val.size() > 0) { return toLong(val.get(0), def); }
}
return def;
}
-
+
/**
* Creates an empty MemorySection for use as a root {@link Configuration}
* section.
@@ -84,15 +88,14 @@ public class MemorySection implements ConfigurationSection {
* @throws IllegalStateException Thrown if this is not a {@link
* Configuration} root.
*/
- protected MemorySection() {
- if (!(this instanceof Configuration)) {
- throw new IllegalStateException("Cannot construct a root MemorySection when not a Configuration");
- }
+ protected MemorySection()
+ {
+ if (!(this instanceof Configuration)) { throw new IllegalStateException("Cannot construct a root MemorySection when not a Configuration"); }
- this.path = "";
- this.fullPath = "";
- this.parent = null;
- this.root = (Configuration) this;
+ path = "";
+ fullPath = "";
+ parent = null;
+ root = (Configuration) this;
}
/**
@@ -104,27 +107,32 @@ public class MemorySection implements ConfigurationSection {
* @throws IllegalArgumentException Thrown is parent or path is null, or
* if parent contains no root Configuration.
*/
- protected MemorySection(ConfigurationSection parent, String path) {
- if (parent == null) throw new NullPointerException("Parent may not be null");
- if (path == null) throw new NullPointerException("Path may not be null");
+ protected MemorySection(final ConfigurationSection parent, final String path)
+ {
+ if (parent == null) { throw new NullPointerException("Parent may not be null"); }
+ if (path == null) { throw new NullPointerException("Path may not be null"); }
this.path = path;
this.parent = parent;
- this.root = parent.getRoot();
+ root = parent.getRoot();
- if (root == null) throw new NullPointerException("Path may not be orphaned");
+ if (root == null) { throw new NullPointerException("Path may not be orphaned"); }
- this.fullPath = createPath(parent, path);
+ fullPath = createPath(parent, path);
}
- public Set getKeys(boolean deep) {
- Set result = new LinkedHashSet();
+ @Override
+ public Set getKeys(final boolean deep)
+ {
+ final Set result = new LinkedHashSet();
- Configuration root = getRoot();
- if (root != null && root.options().copyDefaults()) {
- ConfigurationSection defaults = getDefaultSection();
+ final Configuration root = getRoot();
+ if ((root != null) && root.options().copyDefaults())
+ {
+ final ConfigurationSection defaults = getDefaultSection();
- if (defaults != null) {
+ if (defaults != null)
+ {
result.addAll(defaults.getKeys(deep));
}
}
@@ -134,14 +142,18 @@ public class MemorySection implements ConfigurationSection {
return result;
}
- public Map getValues(boolean deep) {
- Map result = new LinkedHashMap();
+ @Override
+ public Map getValues(final boolean deep)
+ {
+ final Map result = new LinkedHashMap();
- Configuration root = getRoot();
- if (root != null && root.options().copyDefaults()) {
- ConfigurationSection defaults = getDefaultSection();
+ final Configuration root = getRoot();
+ if ((root != null) && root.options().copyDefaults())
+ {
+ final ConfigurationSection defaults = getDefaultSection();
- if (defaults != null) {
+ if (defaults != null)
+ {
result.putAll(defaults.getValues(deep));
}
}
@@ -151,172 +163,200 @@ public class MemorySection implements ConfigurationSection {
return result;
}
- public boolean contains(String path) {
+ @Override
+ public boolean contains(final String path)
+ {
return get(path) != null;
}
- public boolean isSet(String path) {
- Configuration root = getRoot();
- if (root == null) {
- return false;
- }
- if (root.options().copyDefaults()) {
- return contains(path);
- }
+ @Override
+ public boolean isSet(final String path)
+ {
+ final Configuration root = getRoot();
+ if (root == null) { return false; }
+ if (root.options().copyDefaults()) { return contains(path); }
return get(path, null) != null;
}
- public String getCurrentPath() {
+ @Override
+ public String getCurrentPath()
+ {
return fullPath;
}
- public String getName() {
+ @Override
+ public String getName()
+ {
return path;
}
- public Configuration getRoot() {
+ @Override
+ public Configuration getRoot()
+ {
return root;
}
- public ConfigurationSection getParent() {
+ @Override
+ public ConfigurationSection getParent()
+ {
return parent;
}
- public void addDefault(String path, Object value) {
- if (path == null) throw new NullPointerException("Path cannot be null");
+ @Override
+ public void addDefault(final String path, final Object value)
+ {
+ if (path == null) { throw new NullPointerException("Path cannot be null"); }
- Configuration root = getRoot();
- if (root == null) {
- throw new IllegalStateException("Cannot add default without root");
- }
- if (root == this) {
- throw new UnsupportedOperationException("Unsupported addDefault(String, Object) implementation");
- }
+ final Configuration root = getRoot();
+ if (root == null) { throw new IllegalStateException("Cannot add default without root"); }
+ if (root == this) { throw new UnsupportedOperationException("Unsupported addDefault(String, Object) implementation"); }
root.addDefault(createPath(this, path), value);
}
- public ConfigurationSection getDefaultSection() {
- Configuration root = getRoot();
- Configuration defaults = root == null ? null : root.getDefaults();
+ @Override
+ public ConfigurationSection getDefaultSection()
+ {
+ final Configuration root = getRoot();
+ final Configuration defaults = root == null ? null : root.getDefaults();
- if (defaults != null) {
- if (defaults.isConfigurationSection(getCurrentPath())) {
- return defaults.getConfigurationSection(getCurrentPath());
- }
+ if (defaults != null)
+ {
+ if (defaults.isConfigurationSection(getCurrentPath())) { return defaults.getConfigurationSection(getCurrentPath()); }
}
return null;
}
- public void set(String path, Object value) {
- if (path == null) throw new NullPointerException("Cannot set to an empty path");
+ @Override
+ public void set(final String path, final Object value)
+ {
+ if (path == null) { throw new NullPointerException("Cannot set to an empty path"); }
- Configuration root = getRoot();
- if (root == null) {
- throw new IllegalStateException("Cannot use section without a root");
- }
+ final Configuration root = getRoot();
+ if (root == null) { throw new IllegalStateException("Cannot use section without a root"); }
final char separator = root.options().pathSeparator();
// i1 is the leading (higher) index
// i2 is the trailing (lower) index
int i1 = -1, i2;
ConfigurationSection section = this;
- while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1) {
- String node = path.substring(i2, i1);
- ConfigurationSection subSection = section.getConfigurationSection(node);
- if (subSection == null) {
+ while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1)
+ {
+ final String node = path.substring(i2, i1);
+ final ConfigurationSection subSection = section.getConfigurationSection(node);
+ if (subSection == null)
+ {
section = section.createSection(node);
- } else {
+ }
+ else
+ {
section = subSection;
}
}
- String key = path.substring(i2);
- if (section == this) {
- if (value == null) {
+ final String key = path.substring(i2);
+ if (section == this)
+ {
+ if (value == null)
+ {
map.remove(key);
- } else {
+ }
+ else
+ {
map.put(key, value);
}
- } else {
+ }
+ else
+ {
section.set(key, value);
}
}
- public Object get(String path) {
+ @Override
+ public Object get(final String path)
+ {
return get(path, getDefault(path));
}
- public Object get(String path, Object def) {
- if (path == null) throw new NullPointerException("Path cannot be null");
+ @Override
+ public Object get(final String path, final Object def)
+ {
+ if (path == null) { throw new NullPointerException("Path cannot be null"); }
- if (path.length() == 0) {
- return this;
- }
+ if (path.length() == 0) { return this; }
- Configuration root = getRoot();
- if (root == null) {
- throw new IllegalStateException("Cannot access section without a root");
- }
+ final Configuration root = getRoot();
+ if (root == null) { throw new IllegalStateException("Cannot access section without a root"); }
final char separator = root.options().pathSeparator();
// i1 is the leading (higher) index
// i2 is the trailing (lower) index
int i1 = -1, i2;
ConfigurationSection section = this;
- while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1) {
+ while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1)
+ {
section = section.getConfigurationSection(path.substring(i2, i1));
- if (section == null) {
- return def;
- }
+ if (section == null) { return def; }
}
- String key = path.substring(i2);
- if (section == this) {
- Object result = map.get(key);
+ final String key = path.substring(i2);
+ if (section == this)
+ {
+ final Object result = map.get(key);
return (result == null) ? def : result;
}
return section.get(key, def);
}
- public ConfigurationSection createSection(String path) {
- if (path == null) throw new NullPointerException("Cannot create section at empty path");
- Configuration root = getRoot();
- if (root == null) {
- throw new IllegalStateException("Cannot create section without a root");
- }
+ @Override
+ public ConfigurationSection createSection(final String path)
+ {
+ if (path == null) { throw new NullPointerException("Cannot create section at empty path"); }
+ final Configuration root = getRoot();
+ if (root == null) { throw new IllegalStateException("Cannot create section without a root"); }
final char separator = root.options().pathSeparator();
// i1 is the leading (higher) index
// i2 is the trailing (lower) index
int i1 = -1, i2;
ConfigurationSection section = this;
- while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1) {
- String node = path.substring(i2, i1);
- ConfigurationSection subSection = section.getConfigurationSection(node);
- if (subSection == null) {
+ while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1)
+ {
+ final String node = path.substring(i2, i1);
+ final ConfigurationSection subSection = section.getConfigurationSection(node);
+ if (subSection == null)
+ {
section = section.createSection(node);
- } else {
+ }
+ else
+ {
section = subSection;
}
}
- String key = path.substring(i2);
- if (section == this) {
- ConfigurationSection result = new MemorySection(this, key);
+ final String key = path.substring(i2);
+ if (section == this)
+ {
+ final ConfigurationSection result = new MemorySection(this, key);
map.put(key, result);
return result;
}
return section.createSection(key);
}
- public ConfigurationSection createSection(String path, Map, ?> map) {
- ConfigurationSection section = createSection(path);
+ @Override
+ public ConfigurationSection createSection(final String path, final Map, ?> map)
+ {
+ final ConfigurationSection section = createSection(path);
- for (Map.Entry, ?> entry : map.entrySet()) {
- if (entry.getValue() instanceof Map) {
+ for (final Map.Entry, ?> entry : map.entrySet())
+ {
+ if (entry.getValue() instanceof Map)
+ {
section.createSection(entry.getKey().toString(), (Map, ?>) entry.getValue());
- } else {
+ }
+ else
+ {
section.set(entry.getKey().toString(), entry.getValue());
}
}
@@ -325,108 +365,146 @@ public class MemorySection implements ConfigurationSection {
}
// Primitives
- public String getString(String path) {
- Object def = getDefault(path);
+ @Override
+ public String getString(final String path)
+ {
+ final Object def = getDefault(path);
return getString(path, def != null ? def.toString() : null);
}
- public String getString(String path, String def) {
- Object val = get(path, def);
+ @Override
+ public String getString(final String path, final String def)
+ {
+ final Object val = get(path, def);
return (val != null) ? val.toString() : def;
}
- public boolean isString(String path) {
- Object val = get(path);
+ @Override
+ public boolean isString(final String path)
+ {
+ final Object val = get(path);
return val instanceof String;
}
- public int getInt(String path) {
- Object def = getDefault(path);
+ @Override
+ public int getInt(final String path)
+ {
+ final Object def = getDefault(path);
return getInt(path, toInt(def, 0));
}
- public int getInt(String path, int def) {
- Object val = get(path, def);
+ @Override
+ public int getInt(final String path, final int def)
+ {
+ final Object val = get(path, def);
return toInt(val, def);
}
- public boolean isInt(String path) {
- Object val = get(path);
+ @Override
+ public boolean isInt(final String path)
+ {
+ final Object val = get(path);
return val instanceof Integer;
}
- public boolean getBoolean(String path) {
- Object def = getDefault(path);
+ @Override
+ public boolean getBoolean(final String path)
+ {
+ final Object def = getDefault(path);
return getBoolean(path, (def instanceof Boolean) ? (Boolean) def : false);
}
- public boolean getBoolean(String path, boolean def) {
- Object val = get(path, def);
+ @Override
+ public boolean getBoolean(final String path, final boolean def)
+ {
+ final Object val = get(path, def);
return (val instanceof Boolean) ? (Boolean) val : def;
}
- public boolean isBoolean(String path) {
- Object val = get(path);
+ @Override
+ public boolean isBoolean(final String path)
+ {
+ final Object val = get(path);
return val instanceof Boolean;
}
- public double getDouble(String path) {
- Object def = getDefault(path);
+ @Override
+ public double getDouble(final String path)
+ {
+ final Object def = getDefault(path);
return getDouble(path, toDouble(def, 0));
}
- public double getDouble(String path, double def) {
- Object val = get(path, def);
+ @Override
+ public double getDouble(final String path, final double def)
+ {
+ final Object val = get(path, def);
return toDouble(val, def);
}
- public boolean isDouble(String path) {
- Object val = get(path);
+ @Override
+ public boolean isDouble(final String path)
+ {
+ final Object val = get(path);
return val instanceof Double;
}
- public long getLong(String path) {
- Object def = getDefault(path);
+ @Override
+ public long getLong(final String path)
+ {
+ final Object def = getDefault(path);
return getLong(path, toLong(def, 0));
}
- public long getLong(String path, long def) {
- Object val = get(path, def);
+ @Override
+ public long getLong(final String path, final long def)
+ {
+ final Object val = get(path, def);
return toLong(val, def);
}
- public boolean isLong(String path) {
- Object val = get(path);
+ @Override
+ public boolean isLong(final String path)
+ {
+ final Object val = get(path);
return val instanceof Long;
}
// Java
- public List> getList(String path) {
- Object def = getDefault(path);
+ @Override
+ public List> getList(final String path)
+ {
+ final Object def = getDefault(path);
return getList(path, (def instanceof List) ? (List>) def : null);
}
- public List> getList(String path, List> def) {
- Object val = get(path, def);
+ @Override
+ public List> getList(final String path, final List> def)
+ {
+ final Object val = get(path, def);
return (List>) ((val instanceof List) ? val : def);
}
- public boolean isList(String path) {
- Object val = get(path);
+ @Override
+ public boolean isList(final String path)
+ {
+ final Object val = get(path);
return val instanceof List;
}
- public List getStringList(String path) {
- List> list = getList(path);
+ @Override
+ public List getStringList(final String path)
+ {
+ final List> list = getList(path);
- if (list == null) {
- return new ArrayList(0);
- }
+ if (list == null) { return new ArrayList(0); }
- List result = new ArrayList();
+ final List result = new ArrayList();
- for (Object object : list) {
- if ((object instanceof String) || (isPrimitiveWrapper(object))) {
+ for (final Object object : list)
+ {
+ if ((object instanceof String) || (isPrimitiveWrapper(object)))
+ {
result.add(String.valueOf(object));
}
}
@@ -434,26 +512,36 @@ public class MemorySection implements ConfigurationSection {
return result;
}
- public List getIntegerList(String path) {
- List> list = getList(path);
+ @Override
+ public List getIntegerList(final String path)
+ {
+ final List> list = getList(path);
- if (list == null) {
- return new ArrayList(0);
- }
+ if (list == null) { return new ArrayList(0); }
- List result = new ArrayList();
+ final List result = new ArrayList();
- for (Object object : list) {
- if (object instanceof Integer) {
+ for (final Object object : list)
+ {
+ if (object instanceof Integer)
+ {
result.add((Integer) object);
- } else if (object instanceof String) {
- try {
+ }
+ else if (object instanceof String)
+ {
+ try
+ {
result.add(Integer.valueOf((String) object));
- } catch (Exception ex) {
}
- } else if (object instanceof Character) {
+ catch (final Exception ex)
+ {}
+ }
+ else if (object instanceof Character)
+ {
result.add((int) ((Character) object).charValue());
- } else if (object instanceof Number) {
+ }
+ else if (object instanceof Number)
+ {
result.add(((Number) object).intValue());
}
}
@@ -461,22 +549,29 @@ public class MemorySection implements ConfigurationSection {
return result;
}
- public List getBooleanList(String path) {
- List> list = getList(path);
+ @Override
+ public List getBooleanList(final String path)
+ {
+ final List> list = getList(path);
- if (list == null) {
- return new ArrayList(0);
- }
+ if (list == null) { return new ArrayList(0); }
- List result = new ArrayList();
+ final List result = new ArrayList();
- for (Object object : list) {
- if (object instanceof Boolean) {
+ for (final Object object : list)
+ {
+ if (object instanceof Boolean)
+ {
result.add((Boolean) object);
- } else if (object instanceof String) {
- if (Boolean.TRUE.toString().equals(object)) {
+ }
+ else if (object instanceof String)
+ {
+ if (Boolean.TRUE.toString().equals(object))
+ {
result.add(true);
- } else if (Boolean.FALSE.toString().equals(object)) {
+ }
+ else if (Boolean.FALSE.toString().equals(object))
+ {
result.add(false);
}
}
@@ -485,26 +580,36 @@ public class MemorySection implements ConfigurationSection {
return result;
}
- public List getDoubleList(String path) {
- List> list = getList(path);
+ @Override
+ public List getDoubleList(final String path)
+ {
+ final List> list = getList(path);
- if (list == null) {
- return new ArrayList(0);
- }
+ if (list == null) { return new ArrayList(0); }
- List result = new ArrayList();
+ final List result = new ArrayList();
- for (Object object : list) {
- if (object instanceof Double) {
+ for (final Object object : list)
+ {
+ if (object instanceof Double)
+ {
result.add((Double) object);
- } else if (object instanceof String) {
- try {
+ }
+ else if (object instanceof String)
+ {
+ try
+ {
result.add(Double.valueOf((String) object));
- } catch (Exception ex) {
}
- } else if (object instanceof Character) {
+ catch (final Exception ex)
+ {}
+ }
+ else if (object instanceof Character)
+ {
result.add((double) ((Character) object).charValue());
- } else if (object instanceof Number) {
+ }
+ else if (object instanceof Number)
+ {
result.add(((Number) object).doubleValue());
}
}
@@ -512,26 +617,36 @@ public class MemorySection implements ConfigurationSection {
return result;
}
- public List getFloatList(String path) {
- List> list = getList(path);
+ @Override
+ public List getFloatList(final String path)
+ {
+ final List> list = getList(path);
- if (list == null) {
- return new ArrayList(0);
- }
+ if (list == null) { return new ArrayList(0); }
- List result = new ArrayList();
+ final List result = new ArrayList();
- for (Object object : list) {
- if (object instanceof Float) {
+ for (final Object object : list)
+ {
+ if (object instanceof Float)
+ {
result.add((Float) object);
- } else if (object instanceof String) {
- try {
+ }
+ else if (object instanceof String)
+ {
+ try
+ {
result.add(Float.valueOf((String) object));
- } catch (Exception ex) {
}
- } else if (object instanceof Character) {
+ catch (final Exception ex)
+ {}
+ }
+ else if (object instanceof Character)
+ {
result.add((float) ((Character) object).charValue());
- } else if (object instanceof Number) {
+ }
+ else if (object instanceof Number)
+ {
result.add(((Number) object).floatValue());
}
}
@@ -539,26 +654,36 @@ public class MemorySection implements ConfigurationSection {
return result;
}
- public List getLongList(String path) {
- List> list = getList(path);
+ @Override
+ public List getLongList(final String path)
+ {
+ final List> list = getList(path);
- if (list == null) {
- return new ArrayList(0);
- }
+ if (list == null) { return new ArrayList(0); }
- List result = new ArrayList();
+ final List result = new ArrayList();
- for (Object object : list) {
- if (object instanceof Long) {
+ for (final Object object : list)
+ {
+ if (object instanceof Long)
+ {
result.add((Long) object);
- } else if (object instanceof String) {
- try {
+ }
+ else if (object instanceof String)
+ {
+ try
+ {
result.add(Long.valueOf((String) object));
- } catch (Exception ex) {
}
- } else if (object instanceof Character) {
+ catch (final Exception ex)
+ {}
+ }
+ else if (object instanceof Character)
+ {
result.add((long) ((Character) object).charValue());
- } else if (object instanceof Number) {
+ }
+ else if (object instanceof Number)
+ {
result.add(((Number) object).longValue());
}
}
@@ -566,26 +691,36 @@ public class MemorySection implements ConfigurationSection {
return result;
}
- public List getByteList(String path) {
- List> list = getList(path);
+ @Override
+ public List getByteList(final String path)
+ {
+ final List> list = getList(path);
- if (list == null) {
- return new ArrayList(0);
- }
+ if (list == null) { return new ArrayList(0); }
- List result = new ArrayList();
+ final List result = new ArrayList();
- for (Object object : list) {
- if (object instanceof Byte) {
+ for (final Object object : list)
+ {
+ if (object instanceof Byte)
+ {
result.add((Byte) object);
- } else if (object instanceof String) {
- try {
+ }
+ else if (object instanceof String)
+ {
+ try
+ {
result.add(Byte.valueOf((String) object));
- } catch (Exception ex) {
}
- } else if (object instanceof Character) {
+ catch (final Exception ex)
+ {}
+ }
+ else if (object instanceof Character)
+ {
result.add((byte) ((Character) object).charValue());
- } else if (object instanceof Number) {
+ }
+ else if (object instanceof Number)
+ {
result.add(((Number) object).byteValue());
}
}
@@ -593,25 +728,32 @@ public class MemorySection implements ConfigurationSection {
return result;
}
- public List getCharacterList(String path) {
- List> list = getList(path);
+ @Override
+ public List getCharacterList(final String path)
+ {
+ final List> list = getList(path);
- if (list == null) {
- return new ArrayList(0);
- }
+ if (list == null) { return new ArrayList(0); }
- List result = new ArrayList();
+ final List result = new ArrayList();
- for (Object object : list) {
- if (object instanceof Character) {
+ for (final Object object : list)
+ {
+ if (object instanceof Character)
+ {
result.add((Character) object);
- } else if (object instanceof String) {
- String str = (String) object;
+ }
+ else if (object instanceof String)
+ {
+ final String str = (String) object;
- if (str.length() == 1) {
+ if (str.length() == 1)
+ {
result.add(str.charAt(0));
}
- } else if (object instanceof Number) {
+ }
+ else if (object instanceof Number)
+ {
result.add((char) ((Number) object).intValue());
}
}
@@ -619,26 +761,36 @@ public class MemorySection implements ConfigurationSection {
return result;
}
- public List getShortList(String path) {
- List> list = getList(path);
+ @Override
+ public List getShortList(final String path)
+ {
+ final List> list = getList(path);
- if (list == null) {
- return new ArrayList(0);
- }
+ if (list == null) { return new ArrayList(0); }
- List result = new ArrayList();
+ final List result = new ArrayList();
- for (Object object : list) {
- if (object instanceof Short) {
+ for (final Object object : list)
+ {
+ if (object instanceof Short)
+ {
result.add((Short) object);
- } else if (object instanceof String) {
- try {
+ }
+ else if (object instanceof String)
+ {
+ try
+ {
result.add(Short.valueOf((String) object));
- } catch (Exception ex) {
}
- } else if (object instanceof Character) {
+ catch (final Exception ex)
+ {}
+ }
+ else if (object instanceof Character)
+ {
result.add((short) ((Character) object).charValue());
- } else if (object instanceof Number) {
+ }
+ else if (object instanceof Number)
+ {
result.add(((Number) object).shortValue());
}
}
@@ -646,16 +798,18 @@ public class MemorySection implements ConfigurationSection {
return result;
}
- public List> getMapList(String path) {
- List> list = getList(path);
- List> result = new ArrayList>();
+ @Override
+ public List> getMapList(final String path)
+ {
+ final List> list = getList(path);
+ final List> result = new ArrayList>();
- if (list == null) {
- return result;
- }
+ if (list == null) { return result; }
- for (Object object : list) {
- if (object instanceof Map) {
+ for (final Object object : list)
+ {
+ if (object instanceof Map)
+ {
result.add((Map, ?>) object);
}
}
@@ -663,74 +817,93 @@ public class MemorySection implements ConfigurationSection {
return result;
}
- public ConfigurationSection getConfigurationSection(String path) {
+ @Override
+ public ConfigurationSection getConfigurationSection(final String path)
+ {
Object val = get(path, null);
- if (val != null) {
- return (val instanceof ConfigurationSection) ? (ConfigurationSection) val : null;
- }
+ if (val != null) { return (val instanceof ConfigurationSection) ? (ConfigurationSection) val : null; }
val = get(path, getDefault(path));
return (val instanceof ConfigurationSection) ? createSection(path) : null;
}
- public boolean isConfigurationSection(String path) {
- Object val = get(path);
+ @Override
+ public boolean isConfigurationSection(final String path)
+ {
+ final Object val = get(path);
return val instanceof ConfigurationSection;
}
- protected boolean isPrimitiveWrapper(Object input) {
- return input instanceof Integer || input instanceof Boolean ||
- input instanceof Character || input instanceof Byte ||
- input instanceof Short || input instanceof Double ||
- input instanceof Long || input instanceof Float;
+ protected boolean isPrimitiveWrapper(final Object input)
+ {
+ return (input instanceof Integer) || (input instanceof Boolean) ||
+ (input instanceof Character) || (input instanceof Byte) ||
+ (input instanceof Short) || (input instanceof Double) ||
+ (input instanceof Long) || (input instanceof Float);
}
- protected Object getDefault(String path) {
- if (path == null) throw new NullPointerException("Path may not be null");
+ protected Object getDefault(final String path)
+ {
+ if (path == null) { throw new NullPointerException("Path may not be null"); }
- Configuration root = getRoot();
- Configuration defaults = root == null ? null : root.getDefaults();
+ final Configuration root = getRoot();
+ final Configuration defaults = root == null ? null : root.getDefaults();
return (defaults == null) ? null : defaults.get(createPath(this, path));
}
- protected void mapChildrenKeys(Set output, ConfigurationSection section, boolean deep) {
- if (section instanceof MemorySection) {
- MemorySection sec = (MemorySection) section;
+ protected void mapChildrenKeys(final Set output, final ConfigurationSection section, final boolean deep)
+ {
+ if (section instanceof MemorySection)
+ {
+ final MemorySection sec = (MemorySection) section;
- for (Map.Entry entry : sec.map.entrySet()) {
+ for (final Map.Entry entry : sec.map.entrySet())
+ {
output.add(createPath(section, entry.getKey(), this));
- if ((deep) && (entry.getValue() instanceof ConfigurationSection)) {
- ConfigurationSection subsection = (ConfigurationSection) entry.getValue();
+ if ((deep) && (entry.getValue() instanceof ConfigurationSection))
+ {
+ final ConfigurationSection subsection = (ConfigurationSection) entry.getValue();
mapChildrenKeys(output, subsection, deep);
}
}
- } else {
- Set keys = section.getKeys(deep);
+ }
+ else
+ {
+ final Set keys = section.getKeys(deep);
- for (String key : keys) {
+ for (final String key : keys)
+ {
output.add(createPath(section, key, this));
}
}
}
- protected void mapChildrenValues(Map output, ConfigurationSection section, boolean deep) {
- if (section instanceof MemorySection) {
- MemorySection sec = (MemorySection) section;
+ protected void mapChildrenValues(final Map output, final ConfigurationSection section, final boolean deep)
+ {
+ if (section instanceof MemorySection)
+ {
+ final MemorySection sec = (MemorySection) section;
- for (Map.Entry entry : sec.map.entrySet()) {
+ for (final Map.Entry entry : sec.map.entrySet())
+ {
output.put(createPath(section, entry.getKey(), this), entry.getValue());
- if (entry.getValue() instanceof ConfigurationSection) {
- if (deep) {
+ if (entry.getValue() instanceof ConfigurationSection)
+ {
+ if (deep)
+ {
mapChildrenValues(output, (ConfigurationSection) entry.getValue(), deep);
}
}
}
- } else {
- Map values = section.getValues(deep);
+ }
+ else
+ {
+ final Map values = section.getValues(deep);
- for (Map.Entry entry : values.entrySet()) {
+ for (final Map.Entry entry : values.entrySet())
+ {
output.put(createPath(section, entry.getKey(), this), entry.getValue());
}
}
@@ -747,7 +920,8 @@ public class MemorySection implements ConfigurationSection {
* @param key Name of the specified section.
* @return Full path of the section from its root.
*/
- public static String createPath(ConfigurationSection section, String key) {
+ public static String createPath(final ConfigurationSection section, final String key)
+ {
return createPath(section, key, (section == null) ? null : section.getRoot());
}
@@ -763,18 +937,20 @@ public class MemorySection implements ConfigurationSection {
* @param relativeTo Section to create the path relative to.
* @return Full path of the section from its root.
*/
- public static String createPath(ConfigurationSection section, String key, ConfigurationSection relativeTo) {
- if (section == null) throw new NullPointerException("Cannot create path without a section");
- Configuration root = section.getRoot();
- if (root == null) {
- throw new IllegalStateException("Cannot create path without a root");
- }
- char separator = root.options().pathSeparator();
+ public static String createPath(final ConfigurationSection section, final String key, final ConfigurationSection relativeTo)
+ {
+ if (section == null) { throw new NullPointerException("Cannot create path without a section"); }
+ final Configuration root = section.getRoot();
+ if (root == null) { throw new IllegalStateException("Cannot create path without a root"); }
+ final char separator = root.options().pathSeparator();
- StringBuilder builder = new StringBuilder();
- if (section != null) {
- for (ConfigurationSection parent = section; (parent != null) && (parent != relativeTo); parent = parent.getParent()) {
- if (builder.length() > 0) {
+ final StringBuilder builder = new StringBuilder();
+ if (section != null)
+ {
+ for (ConfigurationSection parent = section; (parent != null) && (parent != relativeTo); parent = parent.getParent())
+ {
+ if (builder.length() > 0)
+ {
builder.insert(0, separator);
}
@@ -782,8 +958,10 @@ public class MemorySection implements ConfigurationSection {
}
}
- if ((key != null) && (key.length() > 0)) {
- if (builder.length() > 0) {
+ if ((key != null) && (key.length() > 0))
+ {
+ if (builder.length() > 0)
+ {
builder.append(separator);
}
@@ -794,15 +972,16 @@ public class MemorySection implements ConfigurationSection {
}
@Override
- public String toString() {
- Configuration root = getRoot();
+ public String toString()
+ {
+ final Configuration root = getRoot();
return new StringBuilder()
- .append(getClass().getSimpleName())
- .append("[path='")
- .append(getCurrentPath())
- .append("', root='")
- .append(root == null ? null : root.getClass().getSimpleName())
- .append("']")
- .toString();
+ .append(getClass().getSimpleName())
+ .append("[path='")
+ .append(getCurrentPath())
+ .append("', root='")
+ .append(root == null ? null : root.getClass().getSimpleName())
+ .append("']")
+ .toString();
}
}
diff --git a/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java b/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java
index 171374deb..5cec0073b 100644
--- a/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java
+++ b/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java
@@ -24,7 +24,8 @@ import com.intellectualcrafters.configuration.MemoryConfiguration;
* This is a base class for all File based implementations of {@link
* Configuration}
*/
-public abstract class FileConfiguration extends MemoryConfiguration {
+public abstract class FileConfiguration extends MemoryConfiguration
+{
/**
* This value specified that the system default encoding should be
* completely ignored, as it cannot handle the ASCII character set, or it
@@ -49,7 +50,8 @@ public abstract class FileConfiguration extends MemoryConfiguration {
*/
@Deprecated
public static final boolean SYSTEM_UTF;
- static {
+ static
+ {
final byte[] testBytes = Base64Coder.decode("ICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX4NCg==");
final String testString = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\r\n";
final Charset defaultCharset = Charset.defaultCharset();
@@ -63,7 +65,8 @@ public abstract class FileConfiguration extends MemoryConfiguration {
/**
* Creates an empty {@link FileConfiguration} with no default values.
*/
- public FileConfiguration() {
+ public FileConfiguration()
+ {
super();
}
@@ -73,7 +76,8 @@ public abstract class FileConfiguration extends MemoryConfiguration {
*
* @param defaults Default value provider
*/
- public FileConfiguration(Configuration defaults) {
+ public FileConfiguration(final Configuration defaults)
+ {
super(defaults);
}
@@ -92,17 +96,21 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* any reason.
* @throws IllegalArgumentException Thrown when file is null.
*/
- public void save(File file) throws IOException {
- if (file == null) throw new NullPointerException("File cannot be null");
+ public void save(final File file) throws IOException
+ {
+ if (file == null) { throw new NullPointerException("File cannot be null"); }
file.getParentFile().mkdirs();
- String data = saveToString();
+ final String data = saveToString();
- Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF8_OVERRIDE && !UTF_BIG ? StandardCharsets.UTF_8 : Charset.defaultCharset());
+ final Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF8_OVERRIDE && !UTF_BIG ? StandardCharsets.UTF_8 : Charset.defaultCharset());
- try {
+ try
+ {
writer.write(data);
- } finally {
+ }
+ finally
+ {
writer.close();
}
}
@@ -122,8 +130,9 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* any reason.
* @throws IllegalArgumentException Thrown when file is null.
*/
- public void save(String file) throws IOException {
- if (file == null) throw new NullPointerException("File cannot be null");
+ public void save(final String file) throws IOException
+ {
+ if (file == null) { throw new NullPointerException("File cannot be null"); }
save(new File(file));
}
@@ -157,8 +166,9 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* a valid Configuration.
* @throws IllegalArgumentException Thrown when file is null.
*/
- public void load(File file) throws IOException, InvalidConfigurationException {
- if (file == null) throw new NullPointerException("File cannot be null");
+ public void load(final File file) throws IOException, InvalidConfigurationException
+ {
+ if (file == null) { throw new NullPointerException("File cannot be null"); }
final FileInputStream stream = new FileInputStream(file);
@@ -184,8 +194,9 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* @see #load(Reader)
*/
@Deprecated
- public void load(InputStream stream) throws IOException, InvalidConfigurationException {
- if (stream == null) throw new NullPointerException("Stream cannot be null");
+ public void load(final InputStream stream) throws IOException, InvalidConfigurationException
+ {
+ if (stream == null) { throw new NullPointerException("Stream cannot be null"); }
load(new InputStreamReader(stream, UTF8_OVERRIDE ? StandardCharsets.UTF_8 : Charset.defaultCharset()));
}
@@ -203,19 +214,24 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* represent a valid Configuration
* @throws IllegalArgumentException thrown when reader is null
*/
- public void load(Reader reader) throws IOException, InvalidConfigurationException {
- BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
+ public void load(final Reader reader) throws IOException, InvalidConfigurationException
+ {
+ final BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
- StringBuilder builder = new StringBuilder();
+ final StringBuilder builder = new StringBuilder();
- try {
+ try
+ {
String line;
- while ((line = input.readLine()) != null) {
+ while ((line = input.readLine()) != null)
+ {
builder.append(line);
builder.append('\n');
}
- } finally {
+ }
+ finally
+ {
input.close();
}
@@ -240,8 +256,9 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* a valid Configuration.
* @throws IllegalArgumentException Thrown when file is null.
*/
- public void load(String file) throws IOException, InvalidConfigurationException {
- if (file == null) throw new NullPointerException("File cannot be null");
+ public void load(final String file) throws IOException, InvalidConfigurationException
+ {
+ if (file == null) { throw new NullPointerException("File cannot be null"); }
load(new File(file));
}
@@ -261,7 +278,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* invalid.
* @throws IllegalArgumentException Thrown if contents is null.
*/
- public abstract void loadFromString(String contents) throws InvalidConfigurationException;
+ public abstract void loadFromString(final String contents) throws InvalidConfigurationException;
/**
* Compiles the header for this {@link FileConfiguration} and returns the
@@ -276,11 +293,13 @@ public abstract class FileConfiguration extends MemoryConfiguration {
protected abstract String buildHeader();
@Override
- public FileConfigurationOptions options() {
- if (options == null) {
+ public FileConfigurationOptions options()
+ {
+ if (options == null)
+ {
options = new FileConfigurationOptions(this);
}
return (FileConfigurationOptions) options;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/intellectualcrafters/configuration/file/FileConfigurationOptions.java b/src/main/java/com/intellectualcrafters/configuration/file/FileConfigurationOptions.java
index 72936c667..9b26be71c 100644
--- a/src/main/java/com/intellectualcrafters/configuration/file/FileConfigurationOptions.java
+++ b/src/main/java/com/intellectualcrafters/configuration/file/FileConfigurationOptions.java
@@ -7,27 +7,32 @@ import com.intellectualcrafters.configuration.MemoryConfigurationOptions;
* Various settings for controlling the input and output of a {@link
* FileConfiguration}
*/
-public class FileConfigurationOptions extends MemoryConfigurationOptions {
+public class FileConfigurationOptions extends MemoryConfigurationOptions
+{
private String header = null;
private boolean copyHeader = true;
- protected FileConfigurationOptions(MemoryConfiguration configuration) {
+ protected FileConfigurationOptions(final MemoryConfiguration configuration)
+ {
super(configuration);
}
@Override
- public FileConfiguration configuration() {
+ public FileConfiguration configuration()
+ {
return (FileConfiguration) super.configuration();
}
@Override
- public FileConfigurationOptions copyDefaults(boolean value) {
+ public FileConfigurationOptions copyDefaults(final boolean value)
+ {
super.copyDefaults(value);
return this;
}
@Override
- public FileConfigurationOptions pathSeparator(char value) {
+ public FileConfigurationOptions pathSeparator(final char value)
+ {
super.pathSeparator(value);
return this;
}
@@ -46,7 +51,8 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
*
* @return Header
*/
- public String header() {
+ public String header()
+ {
return header;
}
@@ -65,8 +71,9 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
* @param value New header
* @return This object, for chaining
*/
- public FileConfigurationOptions header(String value) {
- this.header = value;
+ public FileConfigurationOptions header(final String value)
+ {
+ header = value;
return this;
}
@@ -88,7 +95,8 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
*
* @return Whether or not to copy the header
*/
- public boolean copyHeader() {
+ public boolean copyHeader()
+ {
return copyHeader;
}
@@ -111,7 +119,8 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
* @param value Whether or not to copy the header
* @return This object, for chaining
*/
- public FileConfigurationOptions copyHeader(boolean value) {
+ public FileConfigurationOptions copyHeader(final boolean value)
+ {
copyHeader = value;
return this;
diff --git a/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java b/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java
index d1277be62..2a3a5fc20 100644
--- a/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java
+++ b/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java
@@ -22,7 +22,8 @@ import com.intellectualcrafters.plot.PS;
* An implementation of {@link Configuration} which saves all files in Yaml.
* Note that this implementation is not synchronized.
*/
-public class YamlConfiguration extends FileConfiguration {
+public class YamlConfiguration extends FileConfiguration
+{
protected static final String COMMENT_PREFIX = "# ";
protected static final String BLANK_CONFIG = "{}\n";
private final DumperOptions yamlOptions = new DumperOptions();
@@ -30,16 +31,18 @@ public class YamlConfiguration extends FileConfiguration {
private final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
@Override
- public String saveToString() {
+ public String saveToString()
+ {
yamlOptions.setIndent(options().indent());
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
yamlOptions.setAllowUnicode(SYSTEM_UTF);
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
- String header = buildHeader();
+ final String header = buildHeader();
String dump = yaml.dump(getValues(false));
- if (dump.equals(BLANK_CONFIG)) {
+ if (dump.equals(BLANK_CONFIG))
+ {
dump = "";
}
@@ -47,63 +50,85 @@ public class YamlConfiguration extends FileConfiguration {
}
@Override
- public void loadFromString(String contents) throws InvalidConfigurationException {
- if (contents == null) throw new NullPointerException("Contents cannot be null");
+ public void loadFromString(final String contents) throws InvalidConfigurationException
+ {
+ if (contents == null) { throw new NullPointerException("Contents cannot be null"); }
Map, ?> input;
- try {
+ try
+ {
input = (Map, ?>) yaml.load(contents);
- } catch (YAMLException e) {
+ }
+ catch (final YAMLException e)
+ {
throw new InvalidConfigurationException(e);
- } catch (ClassCastException e) {
+ }
+ catch (final ClassCastException e)
+ {
throw new InvalidConfigurationException("Top level is not a Map.");
}
- String header = parseHeader(contents);
- if (header.length() > 0) {
+ final String header = parseHeader(contents);
+ if (header.length() > 0)
+ {
options().header(header);
}
- if (input != null) {
+ if (input != null)
+ {
convertMapsToSections(input, this);
}
}
- protected void convertMapsToSections(Map, ?> input, ConfigurationSection section) {
- for (Map.Entry, ?> entry : input.entrySet()) {
- String key = entry.getKey().toString();
- Object value = entry.getValue();
+ protected void convertMapsToSections(final Map, ?> input, final ConfigurationSection section)
+ {
+ for (final Map.Entry, ?> entry : input.entrySet())
+ {
+ final String key = entry.getKey().toString();
+ final Object value = entry.getValue();
- if (value instanceof Map) {
+ if (value instanceof Map)
+ {
convertMapsToSections((Map, ?>) value, section.createSection(key));
- } else {
+ }
+ else
+ {
section.set(key, value);
}
}
}
- protected String parseHeader(String input) {
- String[] lines = input.split("\r?\n", -1);
- StringBuilder result = new StringBuilder();
+ protected String parseHeader(final String input)
+ {
+ final String[] lines = input.split("\r?\n", -1);
+ final StringBuilder result = new StringBuilder();
boolean readingHeader = true;
boolean foundHeader = false;
- for (int i = 0; (i < lines.length) && (readingHeader); i++) {
- String line = lines[i];
+ for (int i = 0; (i < lines.length) && (readingHeader); i++)
+ {
+ final String line = lines[i];
- if (line.startsWith(COMMENT_PREFIX)) {
- if (i > 0) {
+ if (line.startsWith(COMMENT_PREFIX))
+ {
+ if (i > 0)
+ {
result.append("\n");
}
- if (line.length() > COMMENT_PREFIX.length()) {
+ if (line.length() > COMMENT_PREFIX.length())
+ {
result.append(line.substring(COMMENT_PREFIX.length()));
}
foundHeader = true;
- } else if ((foundHeader) && (line.length() == 0)) {
+ }
+ else if ((foundHeader) && (line.length() == 0))
+ {
result.append("\n");
- } else if (foundHeader) {
+ }
+ else if (foundHeader)
+ {
readingHeader = false;
}
}
@@ -112,34 +137,35 @@ public class YamlConfiguration extends FileConfiguration {
}
@Override
- protected String buildHeader() {
- String header = options().header();
+ protected String buildHeader()
+ {
+ final String header = options().header();
- if (options().copyHeader()) {
- Configuration def = getDefaults();
+ if (options().copyHeader())
+ {
+ final Configuration def = getDefaults();
- if ((def != null) && (def instanceof FileConfiguration)) {
- FileConfiguration filedefaults = (FileConfiguration) def;
- String defaultsHeader = filedefaults.buildHeader();
+ if ((def != null) && (def instanceof FileConfiguration))
+ {
+ final FileConfiguration filedefaults = (FileConfiguration) def;
+ final String defaultsHeader = filedefaults.buildHeader();
- if ((defaultsHeader != null) && (defaultsHeader.length() > 0)) {
- return defaultsHeader;
- }
+ if ((defaultsHeader != null) && (defaultsHeader.length() > 0)) { return defaultsHeader; }
}
}
- if (header == null) {
- return "";
- }
+ if (header == null) { return ""; }
- StringBuilder builder = new StringBuilder();
- String[] lines = header.split("\r?\n", -1);
+ final StringBuilder builder = new StringBuilder();
+ final String[] lines = header.split("\r?\n", -1);
boolean startedHeader = false;
- for (int i = lines.length - 1; i >= 0; i--) {
+ for (int i = lines.length - 1; i >= 0; i--)
+ {
builder.insert(0, "\n");
- if ((startedHeader) || (lines[i].length() != 0)) {
+ if ((startedHeader) || (lines[i].length() != 0))
+ {
builder.insert(0, lines[i]);
builder.insert(0, COMMENT_PREFIX);
startedHeader = true;
@@ -150,8 +176,10 @@ public class YamlConfiguration extends FileConfiguration {
}
@Override
- public YamlConfigurationOptions options() {
- if (options == null) {
+ public YamlConfigurationOptions options()
+ {
+ if (options == null)
+ {
options = new YamlConfigurationOptions(this);
}
@@ -171,28 +199,36 @@ public class YamlConfiguration extends FileConfiguration {
* @return Resulting configuration
* @throws IllegalArgumentException Thrown if file is null
*/
- public static YamlConfiguration loadConfiguration(File file) {
- if (file == null) throw new NullPointerException("File cannot be null");
+ public static YamlConfiguration loadConfiguration(final File file)
+ {
+ if (file == null) { throw new NullPointerException("File cannot be null"); }
- YamlConfiguration config = new YamlConfiguration();
+ final YamlConfiguration config = new YamlConfiguration();
- try {
+ try
+ {
config.load(file);
- } catch (Exception ex) {
- try {
- String path = file.getAbsolutePath() + "_broken";
+ }
+ catch (final Exception ex)
+ {
+ try
+ {
+ file.getAbsolutePath();
File dest = new File(file.getAbsolutePath() + "_broken");
int i = 0;
- while (dest.exists()) {
+ while (dest.exists())
+ {
dest = new File(file.getAbsolutePath() + "_broken_" + i++);
}
- Files.copy( file.toPath(), dest.toPath() , StandardCopyOption.REPLACE_EXISTING);
+ Files.copy(file.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
PS.debug("&dCould not read: &7" + file);
PS.debug("&drenamed to: &7" + dest.getName());
PS.debug("&c============ Full stacktrace ============");
ex.printStackTrace();
PS.debug("&c=========================================");
- } catch (IOException e) {
+ }
+ catch (final IOException e)
+ {
e.printStackTrace();
}
}
@@ -215,17 +251,23 @@ public class YamlConfiguration extends FileConfiguration {
* @see #loadConfiguration(Reader)
*/
@Deprecated
- public static YamlConfiguration loadConfiguration(InputStream stream) {
- if (stream == null) throw new NullPointerException("Stream cannot be null");
+ public static YamlConfiguration loadConfiguration(final InputStream stream)
+ {
+ if (stream == null) { throw new NullPointerException("Stream cannot be null"); }
- YamlConfiguration config = new YamlConfiguration();
+ final YamlConfiguration config = new YamlConfiguration();
- try {
+ try
+ {
config.load(stream);
- } catch (IOException ex) {
+ }
+ catch (final IOException ex)
+ {
PS.debug("Cannot load configuration from stream");
ex.printStackTrace();
- } catch (InvalidConfigurationException ex) {
+ }
+ catch (final InvalidConfigurationException ex)
+ {
ex.printStackTrace();
PS.debug("Cannot load configuration from stream");
}
@@ -233,7 +275,6 @@ public class YamlConfiguration extends FileConfiguration {
return config;
}
-
/**
* Creates a new {@link YamlConfiguration}, loading from the given reader.
*
@@ -245,17 +286,23 @@ public class YamlConfiguration extends FileConfiguration {
* @return resulting configuration
* @throws IllegalArgumentException Thrown if stream is null
*/
- public static YamlConfiguration loadConfiguration(Reader reader) {
- if (reader == null) throw new NullPointerException("Reader cannot be null");
+ public static YamlConfiguration loadConfiguration(final Reader reader)
+ {
+ if (reader == null) { throw new NullPointerException("Reader cannot be null"); }
- YamlConfiguration config = new YamlConfiguration();
+ final YamlConfiguration config = new YamlConfiguration();
- try {
+ try
+ {
config.load(reader);
- } catch (IOException ex) {
+ }
+ catch (final IOException ex)
+ {
PS.debug("Cannot load configuration from stream");
ex.printStackTrace();
- } catch (InvalidConfigurationException ex) {
+ }
+ catch (final InvalidConfigurationException ex)
+ {
PS.debug("Cannot load configuration from stream");
ex.printStackTrace();
}
diff --git a/src/main/java/com/intellectualcrafters/configuration/file/YamlConfigurationOptions.java b/src/main/java/com/intellectualcrafters/configuration/file/YamlConfigurationOptions.java
index 6783d5ce4..75eae9250 100644
--- a/src/main/java/com/intellectualcrafters/configuration/file/YamlConfigurationOptions.java
+++ b/src/main/java/com/intellectualcrafters/configuration/file/YamlConfigurationOptions.java
@@ -4,38 +4,45 @@ package com.intellectualcrafters.configuration.file;
* Various settings for controlling the input and output of a {@link
* YamlConfiguration}
*/
-public class YamlConfigurationOptions extends FileConfigurationOptions {
+public class YamlConfigurationOptions extends FileConfigurationOptions
+{
private int indent = 2;
- protected YamlConfigurationOptions(YamlConfiguration configuration) {
+ protected YamlConfigurationOptions(final YamlConfiguration configuration)
+ {
super(configuration);
}
@Override
- public YamlConfiguration configuration() {
+ public YamlConfiguration configuration()
+ {
return (YamlConfiguration) super.configuration();
}
@Override
- public YamlConfigurationOptions copyDefaults(boolean value) {
+ public YamlConfigurationOptions copyDefaults(final boolean value)
+ {
super.copyDefaults(value);
return this;
}
@Override
- public YamlConfigurationOptions pathSeparator(char value) {
+ public YamlConfigurationOptions pathSeparator(final char value)
+ {
super.pathSeparator(value);
return this;
}
@Override
- public YamlConfigurationOptions header(String value) {
+ public YamlConfigurationOptions header(final String value)
+ {
super.header(value);
return this;
}
@Override
- public YamlConfigurationOptions copyHeader(boolean value) {
+ public YamlConfigurationOptions copyHeader(final boolean value)
+ {
super.copyHeader(value);
return this;
}
@@ -47,7 +54,8 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
*
* @return How much to indent by
*/
- public int indent() {
+ public int indent()
+ {
return indent;
}
@@ -59,11 +67,12 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
* @param value New indent
* @return This object, for chaining
*/
- public YamlConfigurationOptions indent(int value) {
- if (value < 2) throw new IllegalArgumentException("Indent must be at least 2 characters");
- if (value > 9) throw new IllegalArgumentException("Indent cannot be greater than 9 characters");
+ public YamlConfigurationOptions indent(final int value)
+ {
+ if (value < 2) { throw new IllegalArgumentException("Indent must be at least 2 characters"); }
+ if (value > 9) { throw new IllegalArgumentException("Indent cannot be greater than 9 characters"); }
- this.indent = value;
+ indent = value;
return this;
}
}
diff --git a/src/main/java/com/intellectualcrafters/configuration/file/YamlConstructor.java b/src/main/java/com/intellectualcrafters/configuration/file/YamlConstructor.java
index 5a8b41732..688a53791 100644
--- a/src/main/java/com/intellectualcrafters/configuration/file/YamlConstructor.java
+++ b/src/main/java/com/intellectualcrafters/configuration/file/YamlConstructor.java
@@ -10,30 +10,37 @@ import org.yaml.snakeyaml.nodes.Tag;
import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization;
-public class YamlConstructor extends SafeConstructor {
+public class YamlConstructor extends SafeConstructor
+{
- public YamlConstructor() {
- this.yamlConstructors.put(Tag.MAP, new ConstructCustomObject());
+ public YamlConstructor()
+ {
+ yamlConstructors.put(Tag.MAP, new ConstructCustomObject());
}
- private class ConstructCustomObject extends ConstructYamlMap {
+ private class ConstructCustomObject extends ConstructYamlMap
+ {
@Override
- public Object construct(Node node) {
- if (node.isTwoStepsConstruction()) {
- throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
- }
+ public Object construct(final Node node)
+ {
+ if (node.isTwoStepsConstruction()) { throw new YAMLException("Unexpected referential mapping structure. Node: " + node); }
- Map, ?> raw = (Map, ?>) super.construct(node);
+ final Map, ?> raw = (Map, ?>) super.construct(node);
- if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
- Map typed = new LinkedHashMap(raw.size());
- for (Map.Entry, ?> entry : raw.entrySet()) {
+ if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY))
+ {
+ final Map typed = new LinkedHashMap(raw.size());
+ for (final Map.Entry, ?> entry : raw.entrySet())
+ {
typed.put(entry.getKey().toString(), entry.getValue());
}
- try {
+ try
+ {
return ConfigurationSerialization.deserializeObject(typed);
- } catch (IllegalArgumentException ex) {
+ }
+ catch (final IllegalArgumentException ex)
+ {
throw new YAMLException("Could not deserialize object", ex);
}
}
@@ -42,7 +49,8 @@ public class YamlConstructor extends SafeConstructor {
}
@Override
- public void construct2ndStep(Node node, Object object) {
+ public void construct2ndStep(final Node node, final Object object)
+ {
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
}
}
diff --git a/src/main/java/com/intellectualcrafters/configuration/file/YamlRepresenter.java b/src/main/java/com/intellectualcrafters/configuration/file/YamlRepresenter.java
index d4ef6da29..f5bf748f2 100644
--- a/src/main/java/com/intellectualcrafters/configuration/file/YamlRepresenter.java
+++ b/src/main/java/com/intellectualcrafters/configuration/file/YamlRepresenter.java
@@ -10,25 +10,31 @@ import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable;
import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization;
-public class YamlRepresenter extends Representer {
+public class YamlRepresenter extends Representer
+{
- public YamlRepresenter() {
- this.multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection());
- this.multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
+ public YamlRepresenter()
+ {
+ multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection());
+ multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
}
- private class RepresentConfigurationSection extends RepresentMap {
+ private class RepresentConfigurationSection extends RepresentMap
+ {
@Override
- public Node representData(Object data) {
+ public Node representData(final Object data)
+ {
return super.representData(((ConfigurationSection) data).getValues(false));
}
}
- private class RepresentConfigurationSerializable extends RepresentMap {
+ private class RepresentConfigurationSerializable extends RepresentMap
+ {
@Override
- public Node representData(Object data) {
- ConfigurationSerializable serializable = (ConfigurationSerializable) data;
- Map values = new LinkedHashMap();
+ public Node representData(final Object data)
+ {
+ final ConfigurationSerializable serializable = (ConfigurationSerializable) data;
+ final Map values = new LinkedHashMap();
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
values.putAll(serializable.serialize());
diff --git a/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerializable.java b/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerializable.java
index e403ebed9..0cca20083 100644
--- a/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerializable.java
+++ b/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerializable.java
@@ -21,7 +21,8 @@ import java.util.Map;
* @see DelegateDeserialization
* @see SerializableAs
*/
-public interface ConfigurationSerializable {
+public interface ConfigurationSerializable
+{
/**
* Creates a Map representation of this class.
diff --git a/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerialization.java b/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerialization.java
index db59bff3f..17eb82574 100644
--- a/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerialization.java
+++ b/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerialization.java
@@ -14,103 +14,130 @@ import com.intellectualcrafters.configuration.Configuration;
/**
* Utility class for storing and retrieving classes for {@link Configuration}.
*/
-public class ConfigurationSerialization {
+public class ConfigurationSerialization
+{
public static final String SERIALIZED_TYPE_KEY = "==";
private final Class extends ConfigurationSerializable> clazz;
private static Map> aliases = new HashMap>();
- protected ConfigurationSerialization(Class extends ConfigurationSerializable> clazz) {
+ protected ConfigurationSerialization(final Class extends ConfigurationSerializable> clazz)
+ {
this.clazz = clazz;
}
- protected Method getMethod(String name, boolean isStatic) {
- try {
- Method method = clazz.getDeclaredMethod(name, Map.class);
+ protected Method getMethod(final String name, final boolean isStatic)
+ {
+ try
+ {
+ final Method method = clazz.getDeclaredMethod(name, Map.class);
- if (!ConfigurationSerializable.class.isAssignableFrom(method.getReturnType())) {
- return null;
- }
- if (Modifier.isStatic(method.getModifiers()) != isStatic) {
- return null;
- }
+ if (!ConfigurationSerializable.class.isAssignableFrom(method.getReturnType())) { return null; }
+ if (Modifier.isStatic(method.getModifiers()) != isStatic) { return null; }
return method;
- } catch (NoSuchMethodException ex) {
+ }
+ catch (final NoSuchMethodException ex)
+ {
return null;
- } catch (SecurityException ex) {
+ }
+ catch (final SecurityException ex)
+ {
return null;
}
}
- protected Constructor extends ConfigurationSerializable> getConstructor() {
- try {
+ protected Constructor extends ConfigurationSerializable> getConstructor()
+ {
+ try
+ {
return clazz.getConstructor(Map.class);
- } catch (NoSuchMethodException ex) {
+ }
+ catch (final NoSuchMethodException ex)
+ {
return null;
- } catch (SecurityException ex) {
+ }
+ catch (final SecurityException ex)
+ {
return null;
}
}
- protected ConfigurationSerializable deserializeViaMethod(Method method, Map args) {
- try {
- ConfigurationSerializable result = (ConfigurationSerializable) method.invoke(null, args);
+ protected ConfigurationSerializable deserializeViaMethod(final Method method, final Map args)
+ {
+ try
+ {
+ final ConfigurationSerializable result = (ConfigurationSerializable) method.invoke(null, args);
- if (result == null) {
- Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE, "Could not call method '" + method.toString() + "' of " + clazz + " for deserialization: method returned null");
- } else {
+ if (result == null)
+ {
+ Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
+ "Could not call method '" + method.toString() + "' of " + clazz + " for deserialization: method returned null");
+ }
+ else
+ {
return result;
}
- } catch (Throwable ex) {
+ }
+ catch (final Throwable ex)
+ {
Logger.getLogger(ConfigurationSerialization.class.getName()).log(
- Level.SEVERE,
- "Could not call method '" + method.toString() + "' of " + clazz + " for deserialization",
- ex instanceof InvocationTargetException ? ex.getCause() : ex);
+ Level.SEVERE,
+ "Could not call method '" + method.toString() + "' of " + clazz + " for deserialization",
+ ex instanceof InvocationTargetException ? ex.getCause() : ex);
}
return null;
}
- protected ConfigurationSerializable deserializeViaCtor(Constructor extends ConfigurationSerializable> ctor, Map args) {
- try {
+ protected ConfigurationSerializable deserializeViaCtor(final Constructor extends ConfigurationSerializable> ctor, final Map args)
+ {
+ try
+ {
return ctor.newInstance(args);
- } catch (Throwable ex) {
+ }
+ catch (final Throwable ex)
+ {
Logger.getLogger(ConfigurationSerialization.class.getName()).log(
- Level.SEVERE,
- "Could not call constructor '" + ctor.toString() + "' of " + clazz + " for deserialization",
- ex instanceof InvocationTargetException ? ex.getCause() : ex);
+ Level.SEVERE,
+ "Could not call constructor '" + ctor.toString() + "' of " + clazz + " for deserialization",
+ ex instanceof InvocationTargetException ? ex.getCause() : ex);
}
return null;
}
- public ConfigurationSerializable deserialize(Map args) {
- if (args == null) {
- throw new NullPointerException("Args must not be null");
- }
+ public ConfigurationSerializable deserialize(final Map args)
+ {
+ if (args == null) { throw new NullPointerException("Args must not be null"); }
ConfigurationSerializable result = null;
Method method = null;
- if (result == null) {
+ if (result == null)
+ {
method = getMethod("deserialize", true);
- if (method != null) {
+ if (method != null)
+ {
result = deserializeViaMethod(method, args);
}
}
- if (result == null) {
+ if (result == null)
+ {
method = getMethod("valueOf", true);
- if (method != null) {
+ if (method != null)
+ {
result = deserializeViaMethod(method, args);
}
}
- if (result == null) {
- Constructor extends ConfigurationSerializable> constructor = getConstructor();
+ if (result == null)
+ {
+ final Constructor extends ConfigurationSerializable> constructor = getConstructor();
- if (constructor != null) {
+ if (constructor != null)
+ {
result = deserializeViaCtor(constructor, args);
}
}
@@ -133,7 +160,8 @@ public class ConfigurationSerialization {
* @param clazz Class to deserialize into
* @return New instance of the specified class
*/
- public static ConfigurationSerializable deserializeObject(Map args, Class extends ConfigurationSerializable> clazz) {
+ public static ConfigurationSerializable deserializeObject(final Map args, final Class extends ConfigurationSerializable> clazz)
+ {
return new ConfigurationSerialization(clazz).deserialize(args);
}
@@ -151,25 +179,28 @@ public class ConfigurationSerialization {
* @param args Arguments for deserialization
* @return New instance of the specified class
*/
- public static ConfigurationSerializable deserializeObject(Map args) {
+ public static ConfigurationSerializable deserializeObject(final Map args)
+ {
Class extends ConfigurationSerializable> clazz = null;
- if (args.containsKey(SERIALIZED_TYPE_KEY)) {
- try {
- String alias = (String) args.get(SERIALIZED_TYPE_KEY);
+ if (args.containsKey(SERIALIZED_TYPE_KEY))
+ {
+ try
+ {
+ final String alias = (String) args.get(SERIALIZED_TYPE_KEY);
- if (alias == null) {
- throw new IllegalArgumentException("Cannot have null alias");
- }
+ if (alias == null) { throw new IllegalArgumentException("Cannot have null alias"); }
clazz = getClassByAlias(alias);
- if (clazz == null) {
- throw new IllegalArgumentException("Specified class does not exist ('" + alias + "')");
- }
- } catch (ClassCastException ex) {
+ if (clazz == null) { throw new IllegalArgumentException("Specified class does not exist ('" + alias + "')"); }
+ }
+ catch (final ClassCastException ex)
+ {
ex.fillInStackTrace();
throw ex;
}
- } else {
+ }
+ else
+ {
throw new IllegalArgumentException("Args doesn't contain type key ('" + SERIALIZED_TYPE_KEY + "')");
}
@@ -182,10 +213,12 @@ public class ConfigurationSerialization {
*
* @param clazz Class to register
*/
- public static void registerClass(Class extends ConfigurationSerializable> clazz) {
- DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
+ public static void registerClass(final Class extends ConfigurationSerializable> clazz)
+ {
+ final DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
- if (delegate == null) {
+ if (delegate == null)
+ {
registerClass(clazz, getAlias(clazz));
registerClass(clazz, clazz.getName());
}
@@ -199,7 +232,8 @@ public class ConfigurationSerialization {
* @param alias Alias to register as
* @see SerializableAs
*/
- public static void registerClass(Class extends ConfigurationSerializable> clazz, String alias) {
+ public static void registerClass(final Class extends ConfigurationSerializable> clazz, final String alias)
+ {
aliases.put(alias, clazz);
}
@@ -208,7 +242,8 @@ public class ConfigurationSerialization {
*
* @param alias Alias to unregister
*/
- public static void unregisterClass(String alias) {
+ public static void unregisterClass(final String alias)
+ {
aliases.remove(alias);
}
@@ -218,9 +253,10 @@ public class ConfigurationSerialization {
*
* @param clazz Class to unregister
*/
- public static void unregisterClass(Class extends ConfigurationSerializable> clazz) {
- while (aliases.values().remove(clazz)) {
- }
+ public static void unregisterClass(final Class extends ConfigurationSerializable> clazz)
+ {
+ while (aliases.values().remove(clazz))
+ {}
}
/**
@@ -230,7 +266,8 @@ public class ConfigurationSerialization {
* @param alias Alias of the serializable
* @return Registered class, or null if not found
*/
- public static Class extends ConfigurationSerializable> getClassByAlias(String alias) {
+ public static Class extends ConfigurationSerializable> getClassByAlias(final String alias)
+ {
return aliases.get(alias);
}
@@ -241,23 +278,27 @@ public class ConfigurationSerialization {
* @param clazz Class to get alias for
* @return Alias to use for the class
*/
- public static String getAlias(Class extends ConfigurationSerializable> clazz) {
+ public static String getAlias(final Class extends ConfigurationSerializable> clazz)
+ {
DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
- if (delegate != null) {
- if ((delegate.value() == null) || (delegate.value() == clazz)) {
+ if (delegate != null)
+ {
+ if ((delegate.value() == null) || (delegate.value() == clazz))
+ {
delegate = null;
- } else {
+ }
+ else
+ {
return getAlias(delegate.value());
}
}
- if (delegate == null) {
- SerializableAs alias = clazz.getAnnotation(SerializableAs.class);
+ if (delegate == null)
+ {
+ final SerializableAs alias = clazz.getAnnotation(SerializableAs.class);
- if ((alias != null) && (alias.value() != null)) {
- return alias.value();
- }
+ if ((alias != null) && (alias.value() != null)) { return alias.value(); }
}
return clazz.getName();
diff --git a/src/main/java/com/intellectualcrafters/configuration/serialization/DelegateDeserialization.java b/src/main/java/com/intellectualcrafters/configuration/serialization/DelegateDeserialization.java
index bc505ccf2..bb0e04d68 100644
--- a/src/main/java/com/intellectualcrafters/configuration/serialization/DelegateDeserialization.java
+++ b/src/main/java/com/intellectualcrafters/configuration/serialization/DelegateDeserialization.java
@@ -11,7 +11,8 @@ import java.lang.annotation.Target;
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
-public @interface DelegateDeserialization {
+public @interface DelegateDeserialization
+{
/**
* Which class should be used as a delegate for this classes
* deserialization
diff --git a/src/main/java/com/intellectualcrafters/configuration/serialization/SerializableAs.java b/src/main/java/com/intellectualcrafters/configuration/serialization/SerializableAs.java
index 668da9ac9..fde872a1b 100644
--- a/src/main/java/com/intellectualcrafters/configuration/serialization/SerializableAs.java
+++ b/src/main/java/com/intellectualcrafters/configuration/serialization/SerializableAs.java
@@ -21,7 +21,8 @@ import java.lang.annotation.Target;
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
-public @interface SerializableAs {
+public @interface SerializableAs
+{
/**
* This is the name your class will be stored and retrieved as.
*
diff --git a/src/main/java/com/intellectualcrafters/jnbt/ByteArrayTag.java b/src/main/java/com/intellectualcrafters/jnbt/ByteArrayTag.java
index 67fc3d9b4..146f4e658 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/ByteArrayTag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/ByteArrayTag.java
@@ -3,7 +3,8 @@ package com.intellectualcrafters.jnbt;
/**
* The {@code TAG_Byte_Array} tag.
*/
-public final class ByteArrayTag extends Tag {
+public final class ByteArrayTag extends Tag
+{
private final byte[] value;
/**
@@ -11,7 +12,8 @@ public final class ByteArrayTag extends Tag {
*
* @param value the value of the tag
*/
- public ByteArrayTag(final byte[] value) {
+ public ByteArrayTag(final byte[] value)
+ {
super();
this.value = value;
}
@@ -22,30 +24,36 @@ public final class ByteArrayTag extends Tag {
* @param name the name of the tag
* @param value the value of the tag
*/
- public ByteArrayTag(final String name, final byte[] value) {
+ public ByteArrayTag(final String name, final byte[] value)
+ {
super(name);
this.value = value;
}
@Override
- public byte[] getValue() {
- return this.value;
+ public byte[] getValue()
+ {
+ return value;
}
@Override
- public String toString() {
+ public String toString()
+ {
final StringBuilder hex = new StringBuilder();
- for (final byte b : this.value) {
+ for (final byte b : value)
+ {
final String hexDigits = Integer.toHexString(b).toUpperCase();
- if (hexDigits.length() == 1) {
+ if (hexDigits.length() == 1)
+ {
hex.append("0");
}
hex.append(hexDigits).append(" ");
}
final String name = getName();
String append = "";
- if ((name != null) && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
+ if ((name != null) && !name.equals(""))
+ {
+ append = "(\"" + getName() + "\")";
}
return "TAG_Byte_Array" + append + ": " + hex;
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/ByteTag.java b/src/main/java/com/intellectualcrafters/jnbt/ByteTag.java
index 6ee42254c..fbdb1d30e 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/ByteTag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/ByteTag.java
@@ -3,7 +3,8 @@ package com.intellectualcrafters.jnbt;
/**
* The {@code TAG_Byte} tag.
*/
-public final class ByteTag extends Tag {
+public final class ByteTag extends Tag
+{
private final byte value;
/**
@@ -11,7 +12,8 @@ public final class ByteTag extends Tag {
*
* @param value the value of the tag
*/
- public ByteTag(final byte value) {
+ public ByteTag(final byte value)
+ {
super();
this.value = value;
}
@@ -22,23 +24,27 @@ public final class ByteTag extends Tag {
* @param name the name of the tag
* @param value the value of the tag
*/
- public ByteTag(final String name, final byte value) {
+ public ByteTag(final String name, final byte value)
+ {
super(name);
this.value = value;
}
@Override
- public Byte getValue() {
- return this.value;
+ public Byte getValue()
+ {
+ return value;
}
@Override
- public String toString() {
+ public String toString()
+ {
final String name = getName();
String append = "";
- if ((name != null) && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
+ if ((name != null) && !name.equals(""))
+ {
+ append = "(\"" + getName() + "\")";
}
- return "TAG_Byte" + append + ": " + this.value;
+ return "TAG_Byte" + append + ": " + value;
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java b/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java
index 842aba19b..6400f748f 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java
@@ -8,7 +8,8 @@ import java.util.Map;
/**
* The {@code TAG_Compound} tag.
*/
-public final class CompoundTag extends Tag {
+public final class CompoundTag extends Tag
+{
private final Map value;
/**
@@ -16,7 +17,8 @@ public final class CompoundTag extends Tag {
*
* @param value the value of the tag
*/
- public CompoundTag(final Map value) {
+ public CompoundTag(final Map value)
+ {
super();
this.value = Collections.unmodifiableMap(value);
}
@@ -27,7 +29,8 @@ public final class CompoundTag extends Tag {
* @param name the name of the tag
* @param value the value of the tag
*/
- public CompoundTag(final String name, final Map value) {
+ public CompoundTag(final String name, final Map value)
+ {
super(name);
this.value = Collections.unmodifiableMap(value);
}
@@ -39,13 +42,15 @@ public final class CompoundTag extends Tag {
*
* @return true if the tag contains the given key
*/
- public boolean containsKey(final String key) {
- return this.value.containsKey(key);
+ public boolean containsKey(final String key)
+ {
+ return value.containsKey(key);
}
@Override
- public Map getValue() {
- return this.value;
+ public Map getValue()
+ {
+ return value;
}
/**
@@ -55,7 +60,8 @@ public final class CompoundTag extends Tag {
*
* @return the new compound tag
*/
- public CompoundTag setValue(final Map value) {
+ public CompoundTag setValue(final Map value)
+ {
return new CompoundTag(getName(), value);
}
@@ -64,8 +70,9 @@ public final class CompoundTag extends Tag {
*
* @return the builder
*/
- public CompoundTagBuilder createBuilder() {
- return new CompoundTagBuilder(new HashMap(this.value));
+ public CompoundTagBuilder createBuilder()
+ {
+ return new CompoundTagBuilder(new HashMap(value));
}
/**
@@ -76,11 +83,15 @@ public final class CompoundTag extends Tag {
*
* @return a byte array
*/
- public byte[] getByteArray(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof ByteArrayTag) {
+ public byte[] getByteArray(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof ByteArrayTag)
+ {
return ((ByteArrayTag) tag).getValue();
- } else {
+ }
+ else
+ {
return new byte[0];
}
}
@@ -93,11 +104,15 @@ public final class CompoundTag extends Tag {
*
* @return a byte
*/
- public byte getByte(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof ByteTag) {
+ public byte getByte(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof ByteTag)
+ {
return ((ByteTag) tag).getValue();
- } else {
+ }
+ else
+ {
return (byte) 0;
}
}
@@ -110,11 +125,15 @@ public final class CompoundTag extends Tag {
*
* @return a double
*/
- public double getDouble(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof DoubleTag) {
+ public double getDouble(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof DoubleTag)
+ {
return ((DoubleTag) tag).getValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -127,21 +146,35 @@ public final class CompoundTag extends Tag {
*
* @return a double
*/
- public double asDouble(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof ByteTag) {
+ public double asDouble(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof ByteTag)
+ {
return ((ByteTag) tag).getValue();
- } else if (tag instanceof ShortTag) {
+ }
+ else if (tag instanceof ShortTag)
+ {
return ((ShortTag) tag).getValue();
- } else if (tag instanceof IntTag) {
+ }
+ else if (tag instanceof IntTag)
+ {
return ((IntTag) tag).getValue();
- } else if (tag instanceof LongTag) {
+ }
+ else if (tag instanceof LongTag)
+ {
return ((LongTag) tag).getValue();
- } else if (tag instanceof FloatTag) {
+ }
+ else if (tag instanceof FloatTag)
+ {
return ((FloatTag) tag).getValue();
- } else if (tag instanceof DoubleTag) {
+ }
+ else if (tag instanceof DoubleTag)
+ {
return ((DoubleTag) tag).getValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -154,11 +187,15 @@ public final class CompoundTag extends Tag {
*
* @return a float
*/
- public float getFloat(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof FloatTag) {
+ public float getFloat(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof FloatTag)
+ {
return ((FloatTag) tag).getValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -171,11 +208,15 @@ public final class CompoundTag extends Tag {
*
* @return an int array
*/
- public int[] getIntArray(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof IntArrayTag) {
+ public int[] getIntArray(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof IntArrayTag)
+ {
return ((IntArrayTag) tag).getValue();
- } else {
+ }
+ else
+ {
return new int[0];
}
}
@@ -188,11 +229,15 @@ public final class CompoundTag extends Tag {
*
* @return an int
*/
- public int getInt(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof IntTag) {
+ public int getInt(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof IntTag)
+ {
return ((IntTag) tag).getValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -205,21 +250,35 @@ public final class CompoundTag extends Tag {
*
* @return an int
*/
- public int asInt(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof ByteTag) {
+ public int asInt(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof ByteTag)
+ {
return ((ByteTag) tag).getValue();
- } else if (tag instanceof ShortTag) {
+ }
+ else if (tag instanceof ShortTag)
+ {
return ((ShortTag) tag).getValue();
- } else if (tag instanceof IntTag) {
+ }
+ else if (tag instanceof IntTag)
+ {
return ((IntTag) tag).getValue();
- } else if (tag instanceof LongTag) {
+ }
+ else if (tag instanceof LongTag)
+ {
return ((LongTag) tag).getValue().intValue();
- } else if (tag instanceof FloatTag) {
+ }
+ else if (tag instanceof FloatTag)
+ {
return ((FloatTag) tag).getValue().intValue();
- } else if (tag instanceof DoubleTag) {
+ }
+ else if (tag instanceof DoubleTag)
+ {
return ((DoubleTag) tag).getValue().intValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -232,11 +291,15 @@ public final class CompoundTag extends Tag {
*
* @return a list of tags
*/
- public List getList(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof ListTag) {
+ public List getList(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof ListTag)
+ {
return ((ListTag) tag).getValue();
- } else {
+ }
+ else
+ {
return Collections.emptyList();
}
}
@@ -249,11 +312,15 @@ public final class CompoundTag extends Tag {
*
* @return a tag list instance
*/
- public ListTag getListTag(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof ListTag) {
+ public ListTag getListTag(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof ListTag)
+ {
return (ListTag) tag;
- } else {
+ }
+ else
+ {
return new ListTag(key, StringTag.class, Collections. emptyList());
}
}
@@ -270,16 +337,23 @@ public final class CompoundTag extends Tag {
* @return a list of tags
*/
@SuppressWarnings("unchecked")
- public List getList(final String key, final Class listType) {
- final Tag tag = this.value.get(key);
- if (tag instanceof ListTag) {
+ public List getList(final String key, final Class listType)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof ListTag)
+ {
final ListTag listTag = (ListTag) tag;
- if (listTag.getType().equals(listType)) {
+ if (listTag.getType().equals(listType))
+ {
return (List) listTag.getValue();
- } else {
+ }
+ else
+ {
return Collections.emptyList();
}
- } else {
+ }
+ else
+ {
return Collections.emptyList();
}
}
@@ -292,11 +366,15 @@ public final class CompoundTag extends Tag {
*
* @return a long
*/
- public long getLong(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof LongTag) {
+ public long getLong(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof LongTag)
+ {
return ((LongTag) tag).getValue();
- } else {
+ }
+ else
+ {
return 0L;
}
}
@@ -309,21 +387,35 @@ public final class CompoundTag extends Tag {
*
* @return a long
*/
- public long asLong(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof ByteTag) {
+ public long asLong(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof ByteTag)
+ {
return ((ByteTag) tag).getValue();
- } else if (tag instanceof ShortTag) {
+ }
+ else if (tag instanceof ShortTag)
+ {
return ((ShortTag) tag).getValue();
- } else if (tag instanceof IntTag) {
+ }
+ else if (tag instanceof IntTag)
+ {
return ((IntTag) tag).getValue();
- } else if (tag instanceof LongTag) {
+ }
+ else if (tag instanceof LongTag)
+ {
return ((LongTag) tag).getValue();
- } else if (tag instanceof FloatTag) {
+ }
+ else if (tag instanceof FloatTag)
+ {
return ((FloatTag) tag).getValue().longValue();
- } else if (tag instanceof DoubleTag) {
+ }
+ else if (tag instanceof DoubleTag)
+ {
return ((DoubleTag) tag).getValue().longValue();
- } else {
+ }
+ else
+ {
return 0L;
}
}
@@ -336,11 +428,15 @@ public final class CompoundTag extends Tag {
*
* @return a short
*/
- public short getShort(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof ShortTag) {
+ public short getShort(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof ShortTag)
+ {
return ((ShortTag) tag).getValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -353,25 +449,32 @@ public final class CompoundTag extends Tag {
*
* @return a string
*/
- public String getString(final String key) {
- final Tag tag = this.value.get(key);
- if (tag instanceof StringTag) {
+ public String getString(final String key)
+ {
+ final Tag tag = value.get(key);
+ if (tag instanceof StringTag)
+ {
return ((StringTag) tag).getValue();
- } else {
+ }
+ else
+ {
return "";
}
}
@Override
- public String toString() {
+ public String toString()
+ {
final String name = getName();
String append = "";
- if ((name != null) && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
+ if ((name != null) && !name.equals(""))
+ {
+ append = "(\"" + getName() + "\")";
}
final StringBuilder bldr = new StringBuilder();
- bldr.append("TAG_Compound").append(append).append(": ").append(this.value.size()).append(" entries\r\n{\r\n");
- for (final Map.Entry entry : this.value.entrySet()) {
+ bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n");
+ for (final Map.Entry entry : value.entrySet())
+ {
bldr.append(" ").append(entry.getValue().toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
}
bldr.append("}");
diff --git a/src/main/java/com/intellectualcrafters/jnbt/CompoundTagBuilder.java b/src/main/java/com/intellectualcrafters/jnbt/CompoundTagBuilder.java
index 3036481f2..69f4d7356 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/CompoundTagBuilder.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/CompoundTagBuilder.java
@@ -8,14 +8,16 @@ import java.util.Map;
/**
* Helps create compound tags.
*/
-public class CompoundTagBuilder {
+public class CompoundTagBuilder
+{
private final Map entries;
/**
* Create a new instance.
*/
- CompoundTagBuilder() {
- this.entries = new HashMap();
+ CompoundTagBuilder()
+ {
+ entries = new HashMap();
}
/**
@@ -23,9 +25,10 @@ public class CompoundTagBuilder {
*
* @param value the value
*/
- CompoundTagBuilder(final Map value) {
+ CompoundTagBuilder(final Map value)
+ {
checkNotNull(value);
- this.entries = value;
+ entries = value;
}
/**
@@ -33,7 +36,8 @@ public class CompoundTagBuilder {
*
* @return a new builder
*/
- public static CompoundTagBuilder create() {
+ public static CompoundTagBuilder create()
+ {
return new CompoundTagBuilder();
}
@@ -45,10 +49,11 @@ public class CompoundTagBuilder {
*
* @return this object
*/
- public CompoundTagBuilder put(final String key, final Tag value) {
+ public CompoundTagBuilder put(final String key, final Tag value)
+ {
checkNotNull(key);
checkNotNull(value);
- this.entries.put(key, value);
+ entries.put(key, value);
return this;
}
@@ -60,7 +65,8 @@ public class CompoundTagBuilder {
*
* @return this object
*/
- public CompoundTagBuilder putByteArray(final String key, final byte[] value) {
+ public CompoundTagBuilder putByteArray(final String key, final byte[] value)
+ {
return put(key, new ByteArrayTag(key, value));
}
@@ -72,7 +78,8 @@ public class CompoundTagBuilder {
*
* @return this object
*/
- public CompoundTagBuilder putByte(final String key, final byte value) {
+ public CompoundTagBuilder putByte(final String key, final byte value)
+ {
return put(key, new ByteTag(key, value));
}
@@ -84,7 +91,8 @@ public class CompoundTagBuilder {
*
* @return this object
*/
- public CompoundTagBuilder putDouble(final String key, final double value) {
+ public CompoundTagBuilder putDouble(final String key, final double value)
+ {
return put(key, new DoubleTag(key, value));
}
@@ -96,7 +104,8 @@ public class CompoundTagBuilder {
*
* @return this object
*/
- public CompoundTagBuilder putFloat(final String key, final float value) {
+ public CompoundTagBuilder putFloat(final String key, final float value)
+ {
return put(key, new FloatTag(key, value));
}
@@ -108,7 +117,8 @@ public class CompoundTagBuilder {
*
* @return this object
*/
- public CompoundTagBuilder putIntArray(final String key, final int[] value) {
+ public CompoundTagBuilder putIntArray(final String key, final int[] value)
+ {
return put(key, new IntArrayTag(key, value));
}
@@ -120,7 +130,8 @@ public class CompoundTagBuilder {
*
* @return this object
*/
- public CompoundTagBuilder putInt(final String key, final int value) {
+ public CompoundTagBuilder putInt(final String key, final int value)
+ {
return put(key, new IntTag(key, value));
}
@@ -132,7 +143,8 @@ public class CompoundTagBuilder {
*
* @return this object
*/
- public CompoundTagBuilder putLong(final String key, final long value) {
+ public CompoundTagBuilder putLong(final String key, final long value)
+ {
return put(key, new LongTag(key, value));
}
@@ -144,7 +156,8 @@ public class CompoundTagBuilder {
*
* @return this object
*/
- public CompoundTagBuilder putShort(final String key, final short value) {
+ public CompoundTagBuilder putShort(final String key, final short value)
+ {
return put(key, new ShortTag(key, value));
}
@@ -156,7 +169,8 @@ public class CompoundTagBuilder {
*
* @return this object
*/
- public CompoundTagBuilder putString(final String key, final String value) {
+ public CompoundTagBuilder putString(final String key, final String value)
+ {
return put(key, new StringTag(key, value));
}
@@ -167,9 +181,11 @@ public class CompoundTagBuilder {
*
* @return this object
*/
- public CompoundTagBuilder putAll(final Map value) {
+ public CompoundTagBuilder putAll(final Map value)
+ {
checkNotNull(value);
- for (final Map.Entry entry : value.entrySet()) {
+ for (final Map.Entry entry : value.entrySet())
+ {
put(entry.getKey(), entry.getValue());
}
return this;
@@ -180,8 +196,9 @@ public class CompoundTagBuilder {
*
* @return the new compound tag
*/
- public CompoundTag build() {
- return new CompoundTag(new HashMap(this.entries));
+ public CompoundTag build()
+ {
+ return new CompoundTag(new HashMap(entries));
}
/**
@@ -191,7 +208,8 @@ public class CompoundTagBuilder {
*
* @return the created compound tag
*/
- public CompoundTag build(final String name) {
- return new CompoundTag(name, new HashMap(this.entries));
+ public CompoundTag build(final String name)
+ {
+ return new CompoundTag(name, new HashMap(entries));
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/DoubleTag.java b/src/main/java/com/intellectualcrafters/jnbt/DoubleTag.java
index f7db525b3..272571f16 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/DoubleTag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/DoubleTag.java
@@ -3,7 +3,8 @@ package com.intellectualcrafters.jnbt;
/**
* The {@code TAG_Double} tag.
*/
-public final class DoubleTag extends Tag {
+public final class DoubleTag extends Tag
+{
private final double value;
/**
@@ -11,7 +12,8 @@ public final class DoubleTag extends Tag {
*
* @param value the value of the tag
*/
- public DoubleTag(final double value) {
+ public DoubleTag(final double value)
+ {
super();
this.value = value;
}
@@ -22,23 +24,27 @@ public final class DoubleTag extends Tag {
* @param name the name of the tag
* @param value the value of the tag
*/
- public DoubleTag(final String name, final double value) {
+ public DoubleTag(final String name, final double value)
+ {
super(name);
this.value = value;
}
@Override
- public Double getValue() {
- return this.value;
+ public Double getValue()
+ {
+ return value;
}
@Override
- public String toString() {
+ public String toString()
+ {
final String name = getName();
String append = "";
- if ((name != null) && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
+ if ((name != null) && !name.equals(""))
+ {
+ append = "(\"" + getName() + "\")";
}
- return "TAG_Double" + append + ": " + this.value;
+ return "TAG_Double" + append + ": " + value;
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/EndTag.java b/src/main/java/com/intellectualcrafters/jnbt/EndTag.java
index 70ffaa488..811ab5e81 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/EndTag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/EndTag.java
@@ -3,21 +3,25 @@ package com.intellectualcrafters.jnbt;
/**
* The {@code TAG_End} tag.
*/
-public final class EndTag extends Tag {
+public final class EndTag extends Tag
+{
/**
* Creates the tag.
*/
- public EndTag() {
+ public EndTag()
+ {
super();
}
@Override
- public Object getValue() {
+ public Object getValue()
+ {
return null;
}
@Override
- public String toString() {
+ public String toString()
+ {
return "TAG_End";
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/FloatTag.java b/src/main/java/com/intellectualcrafters/jnbt/FloatTag.java
index 02649fbad..6cb78472b 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/FloatTag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/FloatTag.java
@@ -3,7 +3,8 @@ package com.intellectualcrafters.jnbt;
/**
* The {@code TAG_Float} tag.
*/
-public final class FloatTag extends Tag {
+public final class FloatTag extends Tag
+{
private final float value;
/**
@@ -11,7 +12,8 @@ public final class FloatTag extends Tag {
*
* @param value the value of the tag
*/
- public FloatTag(final float value) {
+ public FloatTag(final float value)
+ {
super();
this.value = value;
}
@@ -22,23 +24,27 @@ public final class FloatTag extends Tag {
* @param name the name of the tag
* @param value the value of the tag
*/
- public FloatTag(final String name, final float value) {
+ public FloatTag(final String name, final float value)
+ {
super(name);
this.value = value;
}
@Override
- public Float getValue() {
- return this.value;
+ public Float getValue()
+ {
+ return value;
}
@Override
- public String toString() {
+ public String toString()
+ {
final String name = getName();
String append = "";
- if ((name != null) && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
+ if ((name != null) && !name.equals(""))
+ {
+ append = "(\"" + getName() + "\")";
}
- return "TAG_Float" + append + ": " + this.value;
+ return "TAG_Float" + append + ": " + value;
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/IntArrayTag.java b/src/main/java/com/intellectualcrafters/jnbt/IntArrayTag.java
index 372002f05..14df42798 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/IntArrayTag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/IntArrayTag.java
@@ -5,7 +5,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* The {@code TAG_Int_Array} tag.
*/
-public final class IntArrayTag extends Tag {
+public final class IntArrayTag extends Tag
+{
private final int[] value;
/**
@@ -13,7 +14,8 @@ public final class IntArrayTag extends Tag {
*
* @param value the value of the tag
*/
- public IntArrayTag(final int[] value) {
+ public IntArrayTag(final int[] value)
+ {
super();
checkNotNull(value);
this.value = value;
@@ -25,31 +27,37 @@ public final class IntArrayTag extends Tag {
* @param name the name of the tag
* @param value the value of the tag
*/
- public IntArrayTag(final String name, final int[] value) {
+ public IntArrayTag(final String name, final int[] value)
+ {
super(name);
checkNotNull(value);
this.value = value;
}
@Override
- public int[] getValue() {
- return this.value;
+ public int[] getValue()
+ {
+ return value;
}
@Override
- public String toString() {
+ public String toString()
+ {
final StringBuilder hex = new StringBuilder();
- for (final int b : this.value) {
+ for (final int b : value)
+ {
final String hexDigits = Integer.toHexString(b).toUpperCase();
- if (hexDigits.length() == 1) {
+ if (hexDigits.length() == 1)
+ {
hex.append("0");
}
hex.append(hexDigits).append(" ");
}
final String name = getName();
String append = "";
- if ((name != null) && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
+ if ((name != null) && !name.equals(""))
+ {
+ append = "(\"" + getName() + "\")";
}
return "TAG_Int_Array" + append + ": " + hex;
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/IntTag.java b/src/main/java/com/intellectualcrafters/jnbt/IntTag.java
index abffe3825..389f4a67d 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/IntTag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/IntTag.java
@@ -3,7 +3,8 @@ package com.intellectualcrafters.jnbt;
/**
* The {@code TAG_Int} tag.
*/
-public final class IntTag extends Tag {
+public final class IntTag extends Tag
+{
private final int value;
/**
@@ -11,7 +12,8 @@ public final class IntTag extends Tag {
*
* @param value the value of the tag
*/
- public IntTag(final int value) {
+ public IntTag(final int value)
+ {
super();
this.value = value;
}
@@ -22,23 +24,27 @@ public final class IntTag extends Tag {
* @param name the name of the tag
* @param value the value of the tag
*/
- public IntTag(final String name, final int value) {
+ public IntTag(final String name, final int value)
+ {
super(name);
this.value = value;
}
@Override
- public Integer getValue() {
- return this.value;
+ public Integer getValue()
+ {
+ return value;
}
@Override
- public String toString() {
+ public String toString()
+ {
final String name = getName();
String append = "";
- if ((name != null) && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
+ if ((name != null) && !name.equals(""))
+ {
+ append = "(\"" + getName() + "\")";
}
- return "TAG_Int" + append + ": " + this.value;
+ return "TAG_Int" + append + ": " + value;
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/ListTag.java b/src/main/java/com/intellectualcrafters/jnbt/ListTag.java
index 5a0cd5faf..6a859ed57 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/ListTag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/ListTag.java
@@ -6,11 +6,11 @@ import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
-
/**
* The {@code TAG_List} tag.
*/
-public final class ListTag extends Tag {
+public final class ListTag extends Tag
+{
private final Class extends Tag> type;
private final List value;
@@ -20,7 +20,8 @@ public final class ListTag extends Tag {
* @param type the type of tag
* @param value the value of the tag
*/
- public ListTag(final Class extends Tag> type, final List extends Tag> value) {
+ public ListTag(final Class extends Tag> type, final List extends Tag> value)
+ {
super();
checkNotNull(value);
this.type = type;
@@ -34,7 +35,8 @@ public final class ListTag extends Tag {
* @param type the type of tag
* @param value the value of the tag
*/
- public ListTag(final String name, final Class extends Tag> type, final List extends Tag> value) {
+ public ListTag(final String name, final Class extends Tag> type, final List extends Tag> value)
+ {
super(name);
checkNotNull(value);
this.type = type;
@@ -46,13 +48,15 @@ public final class ListTag extends Tag {
*
* @return The type of item in this list.
*/
- public Class extends Tag> getType() {
- return this.type;
+ public Class extends Tag> getType()
+ {
+ return type;
}
@Override
- public List getValue() {
- return this.value;
+ public List getValue()
+ {
+ return value;
}
/**
@@ -62,7 +66,8 @@ public final class ListTag extends Tag {
*
* @return a new list tag
*/
- public ListTag setValue(final List list) {
+ public ListTag setValue(final List list)
+ {
return new ListTag(getName(), getType(), list);
}
@@ -73,10 +78,14 @@ public final class ListTag extends Tag {
*
* @return the tag or null
*/
- public Tag getIfExists(final int index) {
- try {
- return this.value.get(index);
- } catch (final NoSuchElementException e) {
+ public Tag getIfExists(final int index)
+ {
+ try
+ {
+ return value.get(index);
+ }
+ catch (final NoSuchElementException e)
+ {
return null;
}
}
@@ -89,11 +98,15 @@ public final class ListTag extends Tag {
*
* @return a byte array
*/
- public byte[] getByteArray(final int index) {
+ public byte[] getByteArray(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof ByteArrayTag) {
+ if (tag instanceof ByteArrayTag)
+ {
return ((ByteArrayTag) tag).getValue();
- } else {
+ }
+ else
+ {
return new byte[0];
}
}
@@ -106,11 +119,15 @@ public final class ListTag extends Tag {
*
* @return a byte
*/
- public byte getByte(final int index) {
+ public byte getByte(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof ByteTag) {
+ if (tag instanceof ByteTag)
+ {
return ((ByteTag) tag).getValue();
- } else {
+ }
+ else
+ {
return (byte) 0;
}
}
@@ -123,11 +140,15 @@ public final class ListTag extends Tag {
*
* @return a double
*/
- public double getDouble(final int index) {
+ public double getDouble(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof DoubleTag) {
+ if (tag instanceof DoubleTag)
+ {
return ((DoubleTag) tag).getValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -140,21 +161,35 @@ public final class ListTag extends Tag {
*
* @return a double
*/
- public double asDouble(final int index) {
+ public double asDouble(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof ByteTag) {
+ if (tag instanceof ByteTag)
+ {
return ((ByteTag) tag).getValue();
- } else if (tag instanceof ShortTag) {
+ }
+ else if (tag instanceof ShortTag)
+ {
return ((ShortTag) tag).getValue();
- } else if (tag instanceof IntTag) {
+ }
+ else if (tag instanceof IntTag)
+ {
return ((IntTag) tag).getValue();
- } else if (tag instanceof LongTag) {
+ }
+ else if (tag instanceof LongTag)
+ {
return ((LongTag) tag).getValue();
- } else if (tag instanceof FloatTag) {
+ }
+ else if (tag instanceof FloatTag)
+ {
return ((FloatTag) tag).getValue();
- } else if (tag instanceof DoubleTag) {
+ }
+ else if (tag instanceof DoubleTag)
+ {
return ((DoubleTag) tag).getValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -167,11 +202,15 @@ public final class ListTag extends Tag {
*
* @return a float
*/
- public float getFloat(final int index) {
+ public float getFloat(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof FloatTag) {
+ if (tag instanceof FloatTag)
+ {
return ((FloatTag) tag).getValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -184,11 +223,15 @@ public final class ListTag extends Tag {
*
* @return an int array
*/
- public int[] getIntArray(final int index) {
+ public int[] getIntArray(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof IntArrayTag) {
+ if (tag instanceof IntArrayTag)
+ {
return ((IntArrayTag) tag).getValue();
- } else {
+ }
+ else
+ {
return new int[0];
}
}
@@ -201,11 +244,15 @@ public final class ListTag extends Tag {
*
* @return an int
*/
- public int getInt(final int index) {
+ public int getInt(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof IntTag) {
+ if (tag instanceof IntTag)
+ {
return ((IntTag) tag).getValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -218,21 +265,35 @@ public final class ListTag extends Tag {
*
* @return an int
*/
- public int asInt(final int index) {
+ public int asInt(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof ByteTag) {
+ if (tag instanceof ByteTag)
+ {
return ((ByteTag) tag).getValue();
- } else if (tag instanceof ShortTag) {
+ }
+ else if (tag instanceof ShortTag)
+ {
return ((ShortTag) tag).getValue();
- } else if (tag instanceof IntTag) {
+ }
+ else if (tag instanceof IntTag)
+ {
return ((IntTag) tag).getValue();
- } else if (tag instanceof LongTag) {
+ }
+ else if (tag instanceof LongTag)
+ {
return ((LongTag) tag).getValue().intValue();
- } else if (tag instanceof FloatTag) {
+ }
+ else if (tag instanceof FloatTag)
+ {
return ((FloatTag) tag).getValue().intValue();
- } else if (tag instanceof DoubleTag) {
+ }
+ else if (tag instanceof DoubleTag)
+ {
return ((DoubleTag) tag).getValue().intValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -245,11 +306,15 @@ public final class ListTag extends Tag {
*
* @return a list of tags
*/
- public List getList(final int index) {
+ public List getList(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof ListTag) {
+ if (tag instanceof ListTag)
+ {
return ((ListTag) tag).getValue();
- } else {
+ }
+ else
+ {
return Collections.emptyList();
}
}
@@ -262,11 +327,15 @@ public final class ListTag extends Tag {
*
* @return a tag list instance
*/
- public ListTag getListTag(final int index) {
+ public ListTag getListTag(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof ListTag) {
+ if (tag instanceof ListTag)
+ {
return (ListTag) tag;
- } else {
+ }
+ else
+ {
return new ListTag(StringTag.class, Collections. emptyList());
}
}
@@ -283,16 +352,23 @@ public final class ListTag extends Tag {
* @return a list of tags
*/
@SuppressWarnings("unchecked")
- public List getList(final int index, final Class listType) {
+ public List getList(final int index, final Class listType)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof ListTag) {
+ if (tag instanceof ListTag)
+ {
final ListTag listTag = (ListTag) tag;
- if (listTag.getType().equals(listType)) {
+ if (listTag.getType().equals(listType))
+ {
return (List) listTag.getValue();
- } else {
+ }
+ else
+ {
return Collections.emptyList();
}
- } else {
+ }
+ else
+ {
return Collections.emptyList();
}
}
@@ -305,11 +381,15 @@ public final class ListTag extends Tag {
*
* @return a long
*/
- public long getLong(final int index) {
+ public long getLong(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof LongTag) {
+ if (tag instanceof LongTag)
+ {
return ((LongTag) tag).getValue();
- } else {
+ }
+ else
+ {
return 0L;
}
}
@@ -322,21 +402,35 @@ public final class ListTag extends Tag {
*
* @return a long
*/
- public long asLong(final int index) {
+ public long asLong(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof ByteTag) {
+ if (tag instanceof ByteTag)
+ {
return ((ByteTag) tag).getValue();
- } else if (tag instanceof ShortTag) {
+ }
+ else if (tag instanceof ShortTag)
+ {
return ((ShortTag) tag).getValue();
- } else if (tag instanceof IntTag) {
+ }
+ else if (tag instanceof IntTag)
+ {
return ((IntTag) tag).getValue();
- } else if (tag instanceof LongTag) {
+ }
+ else if (tag instanceof LongTag)
+ {
return ((LongTag) tag).getValue();
- } else if (tag instanceof FloatTag) {
+ }
+ else if (tag instanceof FloatTag)
+ {
return ((FloatTag) tag).getValue().longValue();
- } else if (tag instanceof DoubleTag) {
+ }
+ else if (tag instanceof DoubleTag)
+ {
return ((DoubleTag) tag).getValue().longValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -349,11 +443,15 @@ public final class ListTag extends Tag {
*
* @return a short
*/
- public short getShort(final int index) {
+ public short getShort(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof ShortTag) {
+ if (tag instanceof ShortTag)
+ {
return ((ShortTag) tag).getValue();
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -366,25 +464,32 @@ public final class ListTag extends Tag {
*
* @return a string
*/
- public String getString(final int index) {
+ public String getString(final int index)
+ {
final Tag tag = getIfExists(index);
- if (tag instanceof StringTag) {
+ if (tag instanceof StringTag)
+ {
return ((StringTag) tag).getValue();
- } else {
+ }
+ else
+ {
return "";
}
}
@Override
- public String toString() {
+ public String toString()
+ {
final String name = getName();
String append = "";
- if ((name != null) && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
+ if ((name != null) && !name.equals(""))
+ {
+ append = "(\"" + getName() + "\")";
}
final StringBuilder bldr = new StringBuilder();
- bldr.append("TAG_List").append(append).append(": ").append(this.value.size()).append(" entries of type ").append(NBTUtils.getTypeName(this.type)).append("\r\n{\r\n");
- for (final Tag t : this.value) {
+ bldr.append("TAG_List").append(append).append(": ").append(value.size()).append(" entries of type ").append(NBTUtils.getTypeName(type)).append("\r\n{\r\n");
+ for (final Tag t : value)
+ {
bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
}
bldr.append("}");
diff --git a/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java b/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java
index af94f866d..013529fbb 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java
@@ -10,7 +10,8 @@ import java.util.List;
/**
* Helps create list tags.
*/
-public class ListTagBuilder {
+public class ListTagBuilder
+{
private final Class extends Tag> type;
private final List entries;
@@ -19,42 +20,42 @@ public class ListTagBuilder {
*
* @param type of tag contained in this list
*/
- ListTagBuilder(final Class extends Tag> type) {
+ ListTagBuilder(final Class extends Tag> type)
+ {
checkNotNull(type);
this.type = type;
- this.entries = new ArrayList();
+ entries = new ArrayList();
}
/**
* Create a new builder instance.
- *
+ *
* @param type
*
* @return a new builder
*/
- public static ListTagBuilder create(final Class extends Tag> type) {
+ public static ListTagBuilder create(final Class extends Tag> type)
+ {
return new ListTagBuilder(type);
}
/**
* Create a new builder instance.
- *
+ *
* @param entries
* @param
*
* @return a new builder
*/
@SafeVarargs
- public static ListTagBuilder createWith(final T... entries) {
+ public static ListTagBuilder createWith(final T... entries)
+ {
checkNotNull(entries);
- if (entries.length == 0) {
- throw new IllegalArgumentException("This method needs an array of at least one entry");
- }
+ if (entries.length == 0) { throw new IllegalArgumentException("This method needs an array of at least one entry"); }
final Class extends Tag> type = entries[0].getClass();
- for (int i = 1; i < entries.length; i++) {
- if (!type.isInstance(entries[i])) {
- throw new IllegalArgumentException("An array of different tag types was provided");
- }
+ for (int i = 1; i < entries.length; i++)
+ {
+ if (!type.isInstance(entries[i])) { throw new IllegalArgumentException("An array of different tag types was provided"); }
}
final ListTagBuilder builder = new ListTagBuilder(type);
builder.addAll(Arrays.asList(entries));
@@ -68,12 +69,11 @@ public class ListTagBuilder {
*
* @return this object
*/
- public ListTagBuilder add(final Tag value) {
+ public ListTagBuilder add(final Tag value)
+ {
checkNotNull(value);
- if (!this.type.isInstance(value)) {
- throw new IllegalArgumentException(value.getClass().getCanonicalName() + " is not of expected type " + this.type.getCanonicalName());
- }
- this.entries.add(value);
+ if (!type.isInstance(value)) { throw new IllegalArgumentException(value.getClass().getCanonicalName() + " is not of expected type " + type.getCanonicalName()); }
+ entries.add(value);
return this;
}
@@ -84,9 +84,11 @@ public class ListTagBuilder {
*
* @return this object
*/
- public ListTagBuilder addAll(final Collection extends Tag> value) {
+ public ListTagBuilder addAll(final Collection extends Tag> value)
+ {
checkNotNull(value);
- for (final Tag v : value) {
+ for (final Tag v : value)
+ {
add(v);
}
return this;
@@ -97,8 +99,9 @@ public class ListTagBuilder {
*
* @return the new list tag
*/
- public ListTag build() {
- return new ListTag(this.type, new ArrayList(this.entries));
+ public ListTag build()
+ {
+ return new ListTag(type, new ArrayList(entries));
}
/**
@@ -108,7 +111,8 @@ public class ListTagBuilder {
*
* @return the created list tag
*/
- public ListTag build(final String name) {
- return new ListTag(name, this.type, new ArrayList(this.entries));
+ public ListTag build(final String name)
+ {
+ return new ListTag(name, type, new ArrayList(entries));
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/LongTag.java b/src/main/java/com/intellectualcrafters/jnbt/LongTag.java
index 0473c075d..f4e53f558 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/LongTag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/LongTag.java
@@ -3,7 +3,8 @@ package com.intellectualcrafters.jnbt;
/**
* The {@code TAG_Long} tag.
*/
-public final class LongTag extends Tag {
+public final class LongTag extends Tag
+{
private final long value;
/**
@@ -11,7 +12,8 @@ public final class LongTag extends Tag {
*
* @param value the value of the tag
*/
- public LongTag(final long value) {
+ public LongTag(final long value)
+ {
super();
this.value = value;
}
@@ -22,23 +24,27 @@ public final class LongTag extends Tag {
* @param name the name of the tag
* @param value the value of the tag
*/
- public LongTag(final String name, final long value) {
+ public LongTag(final String name, final long value)
+ {
super(name);
this.value = value;
}
@Override
- public Long getValue() {
- return this.value;
+ public Long getValue()
+ {
+ return value;
}
@Override
- public String toString() {
+ public String toString()
+ {
final String name = getName();
String append = "";
- if ((name != null) && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
+ if ((name != null) && !name.equals(""))
+ {
+ append = "(\"" + getName() + "\")";
}
- return "TAG_Long" + append + ": " + this.value;
+ return "TAG_Long" + append + ": " + value;
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/NBTConstants.java b/src/main/java/com/intellectualcrafters/jnbt/NBTConstants.java
index 891345802..57f431dbf 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/NBTConstants.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/NBTConstants.java
@@ -25,15 +25,17 @@ import java.nio.charset.Charset;
/**
* A class which holds constant values.
*/
-public final class NBTConstants {
+public final class NBTConstants
+{
public static final Charset CHARSET = Charset.forName("UTF-8");
- public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2, TYPE_INT = 3, TYPE_LONG = 4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6, TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9, TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11;
+ public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2, TYPE_INT = 3, TYPE_LONG = 4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6, TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9,
+ TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11;
/**
* Default private constructor.
*/
- private NBTConstants() {
- }
+ private NBTConstants()
+ {}
/**
* Convert a type ID to its corresponding {@link Tag} class.
@@ -44,8 +46,10 @@ public final class NBTConstants {
*
* @throws IllegalArgumentException thrown if the tag ID is not valid
*/
- public static Class extends Tag> getClassFromType(final int id) {
- switch (id) {
+ public static Class extends Tag> getClassFromType(final int id)
+ {
+ switch (id)
+ {
case TYPE_END:
return EndTag.class;
case TYPE_BYTE:
diff --git a/src/main/java/com/intellectualcrafters/jnbt/NBTInputStream.java b/src/main/java/com/intellectualcrafters/jnbt/NBTInputStream.java
index 2b5981b92..fce72a74b 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/NBTInputStream.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/NBTInputStream.java
@@ -14,11 +14,12 @@ import java.util.Map;
* subclasses of the {@code Tag} object. The NBT format was created by Markus Persson, and the specification
* may be found at @linktourl http://www.minecraft.net/docs/NBT.txt"> http://www.minecraft.net/docs/NBT.txt.
*/
-public final class NBTInputStream implements Closeable {
+public final class NBTInputStream implements Closeable
+{
private final DataInputStream is;
private int count;
-
+
/**
* Creates a new {@code NBTInputStream}, which will source its data from the specified input stream.
*
@@ -26,7 +27,8 @@ public final class NBTInputStream implements Closeable {
*
* @throws IOException if an I/O error occurs
*/
- public NBTInputStream(final InputStream is) throws IOException {
+ public NBTInputStream(final InputStream is) throws IOException
+ {
this.is = new DataInputStream(is);
}
@@ -37,10 +39,11 @@ public final class NBTInputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- public Tag readTag() throws IOException {
+ public Tag readTag() throws IOException
+ {
return readTag(0, Integer.MAX_VALUE);
}
-
+
/**
* Reads an NBT tag from the stream.
*
@@ -48,7 +51,8 @@ public final class NBTInputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- public Tag readTag(int maxDepth) throws IOException {
+ public Tag readTag(final int maxDepth) throws IOException
+ {
return readTag(0, maxDepth);
}
@@ -61,16 +65,20 @@ public final class NBTInputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private Tag readTag(final int depth, int maxDepth) throws IOException {
- if ((count++) > maxDepth) throw new IOException("Exceeds max depth: " + count);
- final int type = this.is.readByte() & 0xFF;
+ private Tag readTag(final int depth, final int maxDepth) throws IOException
+ {
+ if ((count++) > maxDepth) { throw new IOException("Exceeds max depth: " + count); }
+ final int type = is.readByte() & 0xFF;
String name;
- if (type != NBTConstants.TYPE_END) {
- final int nameLength = this.is.readShort() & 0xFFFF;
+ if (type != NBTConstants.TYPE_END)
+ {
+ final int nameLength = is.readShort() & 0xFFFF;
final byte[] nameBytes = new byte[nameLength];
- this.is.readFully(nameBytes);
+ is.readFully(nameBytes);
name = new String(nameBytes, NBTConstants.CHARSET);
- } else {
+ }
+ else
+ {
name = "";
}
return readTagPayload(type, name, depth, maxDepth);
@@ -87,84 +95,96 @@ public final class NBTInputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private Tag readTagPayload(final int type, final String name, final int depth, int maxDepth) throws IOException {
- if ((count++) > maxDepth) throw new IOException("Exceeds max depth: " + count);
+ private Tag readTagPayload(final int type, final String name, final int depth, final int maxDepth) throws IOException
+ {
+ if ((count++) > maxDepth) { throw new IOException("Exceeds max depth: " + count); }
count++;
- switch (type) {
+ switch (type)
+ {
case NBTConstants.TYPE_END:
- if (depth == 0) {
+ if (depth == 0)
+ {
throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
- } else {
+ }
+ else
+ {
return new EndTag();
}
case NBTConstants.TYPE_BYTE:
- return new ByteTag(name, this.is.readByte());
+ return new ByteTag(name, is.readByte());
case NBTConstants.TYPE_SHORT:
- return new ShortTag(name, this.is.readShort());
+ return new ShortTag(name, is.readShort());
case NBTConstants.TYPE_INT:
- return new IntTag(name, this.is.readInt());
+ return new IntTag(name, is.readInt());
case NBTConstants.TYPE_LONG:
- return new LongTag(name, this.is.readLong());
+ return new LongTag(name, is.readLong());
case NBTConstants.TYPE_FLOAT:
- return new FloatTag(name, this.is.readFloat());
+ return new FloatTag(name, is.readFloat());
case NBTConstants.TYPE_DOUBLE:
- return new DoubleTag(name, this.is.readDouble());
+ return new DoubleTag(name, is.readDouble());
case NBTConstants.TYPE_BYTE_ARRAY:
- int length = this.is.readInt();
-
+ int length = is.readInt();
+
// Max depth
- if ((count += length) > maxDepth) throw new IOException("Exceeds max depth: " + count);
+ if ((count += length) > maxDepth) { throw new IOException("Exceeds max depth: " + count);
//
-
+ }
+
byte[] bytes = new byte[length];
- this.is.readFully(bytes);
+ is.readFully(bytes);
return new ByteArrayTag(name, bytes);
case NBTConstants.TYPE_STRING:
- length = this.is.readShort();
-
+ length = is.readShort();
+
// Max depth
- if ((count += length) > maxDepth) throw new IOException("Exceeds max depth: " + count);
+ if ((count += length) > maxDepth) { throw new IOException("Exceeds max depth: " + count);
//
-
+ }
+
bytes = new byte[length];
- this.is.readFully(bytes);
+ is.readFully(bytes);
return new StringTag(name, new String(bytes, NBTConstants.CHARSET));
case NBTConstants.TYPE_LIST:
- final int childType = this.is.readByte();
- length = this.is.readInt();
-
+ final int childType = is.readByte();
+ length = is.readInt();
+
// Max depth
- if ((count += length) > maxDepth) throw new IOException("Exceeds max depth: " + count);
+ if ((count += length) > maxDepth) { throw new IOException("Exceeds max depth: " + count);
//
-
+ }
+
final List tagList = new ArrayList();
- for (int i = 0; i < length; ++i) {
+ for (int i = 0; i < length; ++i)
+ {
final Tag tag = readTagPayload(childType, "", depth + 1, maxDepth);
- if (tag instanceof EndTag) {
- throw new IOException("TAG_End not permitted in a list.");
- }
+ if (tag instanceof EndTag) { throw new IOException("TAG_End not permitted in a list."); }
tagList.add(tag);
}
return new ListTag(name, NBTUtils.getTypeClass(childType), tagList);
case NBTConstants.TYPE_COMPOUND:
final Map tagMap = new HashMap();
- while (true) {
+ while (true)
+ {
final Tag tag = readTag(depth + 1, maxDepth);
- if (tag instanceof EndTag) {
+ if (tag instanceof EndTag)
+ {
break;
- } else {
+ }
+ else
+ {
tagMap.put(tag.getName(), tag);
}
}
return new CompoundTag(name, tagMap);
case NBTConstants.TYPE_INT_ARRAY:
- length = this.is.readInt();
+ length = is.readInt();
// Max depth
- if ((count += length) > maxDepth) throw new IOException("Exceeds max depth: " + count);
+ if ((count += length) > maxDepth) { throw new IOException("Exceeds max depth: " + count); }
//
final int[] data = new int[length];
- for (int i = 0; i < length; i++) {
- data[i] = this.is.readInt();
+ for (int i = 0; i < length; i++)
+ {
+ data[i] = is.readInt();
}
return new IntArrayTag(name, data);
default:
@@ -173,7 +193,8 @@ public final class NBTInputStream implements Closeable {
}
@Override
- public void close() throws IOException {
- this.is.close();
+ public void close() throws IOException
+ {
+ is.close();
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/NBTOutputStream.java b/src/main/java/com/intellectualcrafters/jnbt/NBTOutputStream.java
index 54a6f895a..2a628aeab 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/NBTOutputStream.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/NBTOutputStream.java
@@ -29,13 +29,14 @@ import java.util.List;
/**
* This class writes NBT , or Named Binary Tag Tag
objects to an
* underlying OutputStream
.
The NBT format was created by Markus Persson, and the
- * specification may be found at
+ * specification may be found at
* @linktourl http://www.minecraft.net/docs/NBT.txt
*
*
* @author Graham Edgecombe
*/
-public final class NBTOutputStream implements Closeable {
+public final class NBTOutputStream implements Closeable
+{
/**
* The output stream.
*/
@@ -48,7 +49,8 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- public NBTOutputStream(final OutputStream os) throws IOException {
+ public NBTOutputStream(final OutputStream os) throws IOException
+ {
this.os = new DataOutputStream(os);
}
@@ -59,16 +61,15 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- public void writeTag(final Tag tag) throws IOException {
+ public void writeTag(final Tag tag) throws IOException
+ {
final int type = NBTUtils.getTypeCode(tag.getClass());
final String name = tag.getName();
final byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
- this.os.writeByte(type);
- this.os.writeShort(nameBytes.length);
- this.os.write(nameBytes);
- if (type == NBTConstants.TYPE_END) {
- throw new IOException("Named TAG_End not permitted.");
- }
+ os.writeByte(type);
+ os.writeShort(nameBytes.length);
+ os.write(nameBytes);
+ if (type == NBTConstants.TYPE_END) { throw new IOException("Named TAG_End not permitted."); }
writeTagPayload(tag);
}
@@ -79,9 +80,11 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private void writeTagPayload(final Tag tag) throws IOException {
+ private void writeTagPayload(final Tag tag) throws IOException
+ {
final int type = NBTUtils.getTypeCode(tag.getClass());
- switch (type) {
+ switch (type)
+ {
case NBTConstants.TYPE_END:
writeEndTagPayload((EndTag) tag);
break;
@@ -130,8 +133,9 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private void writeByteTagPayload(final ByteTag tag) throws IOException {
- this.os.writeByte(tag.getValue());
+ private void writeByteTagPayload(final ByteTag tag) throws IOException
+ {
+ os.writeByte(tag.getValue());
}
/**
@@ -141,10 +145,11 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private void writeByteArrayTagPayload(final ByteArrayTag tag) throws IOException {
+ private void writeByteArrayTagPayload(final ByteArrayTag tag) throws IOException
+ {
final byte[] bytes = tag.getValue();
- this.os.writeInt(bytes.length);
- this.os.write(bytes);
+ os.writeInt(bytes.length);
+ os.write(bytes);
}
/**
@@ -154,11 +159,13 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private void writeCompoundTagPayload(final CompoundTag tag) throws IOException {
- for (final Tag childTag : tag.getValue().values()) {
+ private void writeCompoundTagPayload(final CompoundTag tag) throws IOException
+ {
+ for (final Tag childTag : tag.getValue().values())
+ {
writeTag(childTag);
}
- this.os.writeByte((byte) 0); // end tag - better way?
+ os.writeByte((byte) 0); // end tag - better way?
}
/**
@@ -168,13 +175,15 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private void writeListTagPayload(final ListTag tag) throws IOException {
+ private void writeListTagPayload(final ListTag tag) throws IOException
+ {
final Class extends Tag> clazz = tag.getType();
final List tags = tag.getValue();
final int size = tags.size();
- this.os.writeByte(NBTUtils.getTypeCode(clazz));
- this.os.writeInt(size);
- for (final Tag tag1 : tags) {
+ os.writeByte(NBTUtils.getTypeCode(clazz));
+ os.writeInt(size);
+ for (final Tag tag1 : tags)
+ {
writeTagPayload(tag1);
}
}
@@ -186,10 +195,11 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private void writeStringTagPayload(final StringTag tag) throws IOException {
+ private void writeStringTagPayload(final StringTag tag) throws IOException
+ {
final byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
- this.os.writeShort(bytes.length);
- this.os.write(bytes);
+ os.writeShort(bytes.length);
+ os.write(bytes);
}
/**
@@ -199,8 +209,9 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private void writeDoubleTagPayload(final DoubleTag tag) throws IOException {
- this.os.writeDouble(tag.getValue());
+ private void writeDoubleTagPayload(final DoubleTag tag) throws IOException
+ {
+ os.writeDouble(tag.getValue());
}
/**
@@ -210,8 +221,9 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private void writeFloatTagPayload(final FloatTag tag) throws IOException {
- this.os.writeFloat(tag.getValue());
+ private void writeFloatTagPayload(final FloatTag tag) throws IOException
+ {
+ os.writeFloat(tag.getValue());
}
/**
@@ -221,8 +233,9 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private void writeLongTagPayload(final LongTag tag) throws IOException {
- this.os.writeLong(tag.getValue());
+ private void writeLongTagPayload(final LongTag tag) throws IOException
+ {
+ os.writeLong(tag.getValue());
}
/**
@@ -232,8 +245,9 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private void writeIntTagPayload(final IntTag tag) throws IOException {
- this.os.writeInt(tag.getValue());
+ private void writeIntTagPayload(final IntTag tag) throws IOException
+ {
+ os.writeInt(tag.getValue());
}
/**
@@ -243,8 +257,9 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private void writeShortTagPayload(final ShortTag tag) throws IOException {
- this.os.writeShort(tag.getValue());
+ private void writeShortTagPayload(final ShortTag tag) throws IOException
+ {
+ os.writeShort(tag.getValue());
}
/**
@@ -254,28 +269,33 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
- private void writeEndTagPayload(final EndTag tag) {
+ private void writeEndTagPayload(final EndTag tag)
+ {
/* empty */
}
- private void writeIntArrayTagPayload(final IntArrayTag tag) throws IOException {
+ private void writeIntArrayTagPayload(final IntArrayTag tag) throws IOException
+ {
final int[] data = tag.getValue();
- this.os.writeInt(data.length);
- for (final int element : data) {
- this.os.writeInt(element);
+ os.writeInt(data.length);
+ for (final int element : data)
+ {
+ os.writeInt(element);
}
}
@Override
- public void close() throws IOException {
- this.os.close();
+ public void close() throws IOException
+ {
+ os.close();
}
/**
* Flush output
- * @throws IOException
+ * @throws IOException
*/
- public void flush() throws IOException {
- this.os.flush();
+ public void flush() throws IOException
+ {
+ os.flush();
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java b/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java
index 06b23b22c..a130d525e 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java
@@ -5,12 +5,13 @@ import java.util.Map;
/**
* A class which contains NBT-related utility methods.
*/
-public final class NBTUtils {
+public final class NBTUtils
+{
/**
* Default private constructor.
*/
- private NBTUtils() {
- }
+ private NBTUtils()
+ {}
/**
* Gets the type name of a tag.
@@ -19,32 +20,58 @@ public final class NBTUtils {
*
* @return The type name.
*/
- public static String getTypeName(final Class extends Tag> clazz) {
- if (clazz.equals(ByteArrayTag.class)) {
+ public static String getTypeName(final Class extends Tag> clazz)
+ {
+ if (clazz.equals(ByteArrayTag.class))
+ {
return "TAG_Byte_Array";
- } else if (clazz.equals(ByteTag.class)) {
+ }
+ else if (clazz.equals(ByteTag.class))
+ {
return "TAG_Byte";
- } else if (clazz.equals(CompoundTag.class)) {
+ }
+ else if (clazz.equals(CompoundTag.class))
+ {
return "TAG_Compound";
- } else if (clazz.equals(DoubleTag.class)) {
+ }
+ else if (clazz.equals(DoubleTag.class))
+ {
return "TAG_Double";
- } else if (clazz.equals(EndTag.class)) {
+ }
+ else if (clazz.equals(EndTag.class))
+ {
return "TAG_End";
- } else if (clazz.equals(FloatTag.class)) {
+ }
+ else if (clazz.equals(FloatTag.class))
+ {
return "TAG_Float";
- } else if (clazz.equals(IntTag.class)) {
+ }
+ else if (clazz.equals(IntTag.class))
+ {
return "TAG_Int";
- } else if (clazz.equals(ListTag.class)) {
+ }
+ else if (clazz.equals(ListTag.class))
+ {
return "TAG_List";
- } else if (clazz.equals(LongTag.class)) {
+ }
+ else if (clazz.equals(LongTag.class))
+ {
return "TAG_Long";
- } else if (clazz.equals(ShortTag.class)) {
+ }
+ else if (clazz.equals(ShortTag.class))
+ {
return "TAG_Short";
- } else if (clazz.equals(StringTag.class)) {
+ }
+ else if (clazz.equals(StringTag.class))
+ {
return "TAG_String";
- } else if (clazz.equals(IntArrayTag.class)) {
+ }
+ else if (clazz.equals(IntArrayTag.class))
+ {
return "TAG_Int_Array";
- } else {
+ }
+ else
+ {
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
}
}
@@ -58,32 +85,58 @@ public final class NBTUtils {
*
* @throws IllegalArgumentException if the tag class is invalid.
*/
- public static int getTypeCode(final Class extends Tag> clazz) {
- if (clazz.equals(ByteArrayTag.class)) {
+ public static int getTypeCode(final Class extends Tag> clazz)
+ {
+ if (clazz.equals(ByteArrayTag.class))
+ {
return NBTConstants.TYPE_BYTE_ARRAY;
- } else if (clazz.equals(ByteTag.class)) {
+ }
+ else if (clazz.equals(ByteTag.class))
+ {
return NBTConstants.TYPE_BYTE;
- } else if (clazz.equals(CompoundTag.class)) {
+ }
+ else if (clazz.equals(CompoundTag.class))
+ {
return NBTConstants.TYPE_COMPOUND;
- } else if (clazz.equals(DoubleTag.class)) {
+ }
+ else if (clazz.equals(DoubleTag.class))
+ {
return NBTConstants.TYPE_DOUBLE;
- } else if (clazz.equals(EndTag.class)) {
+ }
+ else if (clazz.equals(EndTag.class))
+ {
return NBTConstants.TYPE_END;
- } else if (clazz.equals(FloatTag.class)) {
+ }
+ else if (clazz.equals(FloatTag.class))
+ {
return NBTConstants.TYPE_FLOAT;
- } else if (clazz.equals(IntTag.class)) {
+ }
+ else if (clazz.equals(IntTag.class))
+ {
return NBTConstants.TYPE_INT;
- } else if (clazz.equals(ListTag.class)) {
+ }
+ else if (clazz.equals(ListTag.class))
+ {
return NBTConstants.TYPE_LIST;
- } else if (clazz.equals(LongTag.class)) {
+ }
+ else if (clazz.equals(LongTag.class))
+ {
return NBTConstants.TYPE_LONG;
- } else if (clazz.equals(ShortTag.class)) {
+ }
+ else if (clazz.equals(ShortTag.class))
+ {
return NBTConstants.TYPE_SHORT;
- } else if (clazz.equals(StringTag.class)) {
+ }
+ else if (clazz.equals(StringTag.class))
+ {
return NBTConstants.TYPE_STRING;
- } else if (clazz.equals(IntArrayTag.class)) {
+ }
+ else if (clazz.equals(IntArrayTag.class))
+ {
return NBTConstants.TYPE_INT_ARRAY;
- } else {
+ }
+ else
+ {
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
}
}
@@ -97,8 +150,10 @@ public final class NBTUtils {
*
* @throws IllegalArgumentException if the tag type is invalid.
*/
- public static Class extends Tag> getTypeClass(final int type) {
- switch (type) {
+ public static Class extends Tag> getTypeClass(final int type)
+ {
+ switch (type)
+ {
case NBTConstants.TYPE_END:
return EndTag.class;
case NBTConstants.TYPE_BYTE:
@@ -138,14 +193,11 @@ public final class NBTUtils {
*
* @return child tag
*/
- public static T getChildTag(final Map items, final String key, final Class expected) throws IllegalArgumentException {
- if (!items.containsKey(key)) {
- throw new IllegalArgumentException("Missing a \"" + key + "\" tag");
- }
+ public static T getChildTag(final Map items, final String key, final Class expected) throws IllegalArgumentException
+ {
+ if (!items.containsKey(key)) { throw new IllegalArgumentException("Missing a \"" + key + "\" tag"); }
final Tag tag = items.get(key);
- if (!expected.isInstance(tag)) {
- throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName());
- }
+ if (!expected.isInstance(tag)) { throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName()); }
return expected.cast(tag);
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/ShortTag.java b/src/main/java/com/intellectualcrafters/jnbt/ShortTag.java
index 5f3b7ec6d..34a1adf9a 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/ShortTag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/ShortTag.java
@@ -23,7 +23,8 @@ package com.intellectualcrafters.jnbt;
/**
* The {@code TAG_Short} tag.
*/
-public final class ShortTag extends Tag {
+public final class ShortTag extends Tag
+{
private final short value;
/**
@@ -31,7 +32,8 @@ public final class ShortTag extends Tag {
*
* @param value the value of the tag
*/
- public ShortTag(final short value) {
+ public ShortTag(final short value)
+ {
super();
this.value = value;
}
@@ -42,23 +44,27 @@ public final class ShortTag extends Tag {
* @param name the name of the tag
* @param value the value of the tag
*/
- public ShortTag(final String name, final short value) {
+ public ShortTag(final String name, final short value)
+ {
super(name);
this.value = value;
}
@Override
- public Short getValue() {
- return this.value;
+ public Short getValue()
+ {
+ return value;
}
@Override
- public String toString() {
+ public String toString()
+ {
final String name = getName();
String append = "";
- if ((name != null) && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
+ if ((name != null) && !name.equals(""))
+ {
+ append = "(\"" + getName() + "\")";
}
- return "TAG_Short" + append + ": " + this.value;
+ return "TAG_Short" + append + ": " + value;
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/StringTag.java b/src/main/java/com/intellectualcrafters/jnbt/StringTag.java
index cb50376a8..e69a75bcc 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/StringTag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/StringTag.java
@@ -5,7 +5,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* The {@code TAG_String} tag.
*/
-public final class StringTag extends Tag {
+public final class StringTag extends Tag
+{
private final String value;
/**
@@ -13,7 +14,8 @@ public final class StringTag extends Tag {
*
* @param value the value of the tag
*/
- public StringTag(final String value) {
+ public StringTag(final String value)
+ {
super();
checkNotNull(value);
this.value = value;
@@ -25,24 +27,28 @@ public final class StringTag extends Tag {
* @param name the name of the tag
* @param value the value of the tag
*/
- public StringTag(final String name, final String value) {
+ public StringTag(final String name, final String value)
+ {
super(name);
checkNotNull(value);
this.value = value;
}
@Override
- public String getValue() {
- return this.value;
+ public String getValue()
+ {
+ return value;
}
@Override
- public String toString() {
+ public String toString()
+ {
final String name = getName();
String append = "";
- if ((name != null) && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
+ if ((name != null) && !name.equals(""))
+ {
+ append = "(\"" + getName() + "\")";
}
- return "TAG_String" + append + ": " + this.value;
+ return "TAG_String" + append + ": " + value;
}
}
diff --git a/src/main/java/com/intellectualcrafters/jnbt/Tag.java b/src/main/java/com/intellectualcrafters/jnbt/Tag.java
index 6fce19169..0c50682ba 100644
--- a/src/main/java/com/intellectualcrafters/jnbt/Tag.java
+++ b/src/main/java/com/intellectualcrafters/jnbt/Tag.java
@@ -23,13 +23,15 @@ package com.intellectualcrafters.jnbt;
/**
* Represents a NBT tag.
*/
-public abstract class Tag {
+public abstract class Tag
+{
private final String name;
/**
* Create a new tag with an empty name.
*/
- Tag() {
+ Tag()
+ {
this("");
}
@@ -38,8 +40,10 @@ public abstract class Tag {
*
* @param name the name
*/
- Tag(String name) {
- if (name == null) {
+ Tag(String name)
+ {
+ if (name == null)
+ {
name = "";
}
this.name = name;
@@ -50,8 +54,9 @@ public abstract class Tag {
*
* @return the name of this tag
*/
- public final String getName() {
- return this.name;
+ public final String getName()
+ {
+ return name;
}
/**
diff --git a/src/main/java/com/intellectualcrafters/json/CDL.java b/src/main/java/com/intellectualcrafters/json/CDL.java
index fb69ce28b..0704da569 100644
--- a/src/main/java/com/intellectualcrafters/json/CDL.java
+++ b/src/main/java/com/intellectualcrafters/json/CDL.java
@@ -4,20 +4,21 @@ package com.intellectualcrafters.json;
* This provides static methods to convert comma delimited text into a JSONArray, and to covert a JSONArray into comma
* delimited text. Comma delimited text is a very popular format for data interchange. It is understood by most
* database, spreadsheet, and organizer programs.
- *
+ *
* Each row of text represents a row in a table or a data record. Each row ends with a NEWLINE character. Each row
* contains one or more values. Values are separated by commas. A value can contain any character except for comma,
* unless is is wrapped in single quotes or double quotes.
- *
+ *
* The first row usually contains the names of the columns.
- *
+ *
* A comma delimited list can be converted into a JSONArray of JSONObjects. The names for the elements in the
* JSONObjects can be taken from the names in the first row.
*
* @author JSON.org
* @version 2014-05-03
*/
-public class CDL {
+public class CDL
+{
/**
* Get the next value. The value can be wrapped in quotes. The value can be empty.
*
@@ -27,28 +28,32 @@ public class CDL {
*
* @throws JSONException if the quoted string is badly formed.
*/
- private static String getValue(final JSONTokener x) throws JSONException {
+ private static String getValue(final JSONTokener x) throws JSONException
+ {
char c;
char q;
StringBuffer sb;
- do {
+ do
+ {
c = x.next();
- } while ((c == ' ') || (c == '\t'));
- switch (c) {
+ }
+ while ((c == ' ') || (c == '\t'));
+ switch (c)
+ {
case 0:
return null;
case '"':
case '\'':
q = c;
sb = new StringBuffer();
- for (;;) {
+ for (;;)
+ {
c = x.next();
- if (c == q) {
+ if (c == q)
+ {
break;
}
- if ((c == 0) || (c == '\n') || (c == '\r')) {
- throw x.syntaxError("Missing close quote '" + q + "'.");
- }
+ if ((c == 0) || (c == '\n') || (c == '\r')) { throw x.syntaxError("Missing close quote '" + q + "'."); }
sb.append(c);
}
return sb.toString();
@@ -70,23 +75,24 @@ public class CDL {
*
* @throws JSONException
*/
- public static JSONArray rowToJSONArray(final JSONTokener x) throws JSONException {
+ public static JSONArray rowToJSONArray(final JSONTokener x) throws JSONException
+ {
final JSONArray ja = new JSONArray();
- for (;;) {
+ for (;;)
+ {
final String value = getValue(x);
char c = x.next();
- if ((value == null) || ((ja.length() == 0) && (value.length() == 0) && (c != ','))) {
- return null;
- }
+ if ((value == null) || ((ja.length() == 0) && (value.length() == 0) && (c != ','))) { return null; }
ja.put(value);
- for (;;) {
- if (c == ',') {
+ for (;;)
+ {
+ if (c == ',')
+ {
break;
}
- if (c != ' ') {
- if ((c == '\n') || (c == '\r') || (c == 0)) {
- return ja;
- }
+ if (c != ' ')
+ {
+ if ((c == '\n') || (c == '\r') || (c == 0)) { return ja; }
throw x.syntaxError("Bad character '" + c + "' (" + (int) c + ").");
}
c = x.next();
@@ -106,7 +112,8 @@ public class CDL {
*
* @throws JSONException
*/
- public static JSONObject rowToJSONObject(final JSONArray names, final JSONTokener x) throws JSONException {
+ public static JSONObject rowToJSONObject(final JSONArray names, final JSONTokener x) throws JSONException
+ {
final JSONArray ja = rowToJSONArray(x);
return ja != null ? ja.toJSONObject(names) : null;
}
@@ -119,26 +126,35 @@ public class CDL {
*
* @return A string ending in NEWLINE.
*/
- public static String rowToString(final JSONArray ja) {
+ public static String rowToString(final JSONArray ja)
+ {
final StringBuilder sb = new StringBuilder();
- for (int i = 0; i < ja.length(); i += 1) {
- if (i > 0) {
+ for (int i = 0; i < ja.length(); i += 1)
+ {
+ if (i > 0)
+ {
sb.append(',');
}
final Object object = ja.opt(i);
- if (object != null) {
+ if (object != null)
+ {
final String string = object.toString();
- if ((string.length() > 0) && ((string.indexOf(',') >= 0) || (string.indexOf('\n') >= 0) || (string.indexOf('\r') >= 0) || (string.indexOf(0) >= 0) || (string.charAt(0) == '"'))) {
+ if ((string.length() > 0) && ((string.indexOf(',') >= 0) || (string.indexOf('\n') >= 0) || (string.indexOf('\r') >= 0) || (string.indexOf(0) >= 0) || (string.charAt(0) == '"')))
+ {
sb.append('"');
final int length = string.length();
- for (int j = 0; j < length; j += 1) {
+ for (int j = 0; j < length; j += 1)
+ {
final char c = string.charAt(j);
- if ((c >= ' ') && (c != '"')) {
+ if ((c >= ' ') && (c != '"'))
+ {
sb.append(c);
}
}
sb.append('"');
- } else {
+ }
+ else
+ {
sb.append(string);
}
}
@@ -156,7 +172,8 @@ public class CDL {
*
* @throws JSONException
*/
- public static JSONArray toJSONArray(final String string) throws JSONException {
+ public static JSONArray toJSONArray(final String string) throws JSONException
+ {
return toJSONArray(new JSONTokener(string));
}
@@ -169,7 +186,8 @@ public class CDL {
*
* @throws JSONException
*/
- public static JSONArray toJSONArray(final JSONTokener x) throws JSONException {
+ public static JSONArray toJSONArray(final JSONTokener x) throws JSONException
+ {
return toJSONArray(rowToJSONArray(x), x);
}
@@ -184,7 +202,8 @@ public class CDL {
*
* @throws JSONException
*/
- public static JSONArray toJSONArray(final JSONArray names, final String string) throws JSONException {
+ public static JSONArray toJSONArray(final JSONArray names, final String string) throws JSONException
+ {
return toJSONArray(names, new JSONTokener(string));
}
@@ -199,21 +218,20 @@ public class CDL {
*
* @throws JSONException
*/
- public static JSONArray toJSONArray(final JSONArray names, final JSONTokener x) throws JSONException {
- if ((names == null) || (names.length() == 0)) {
- return null;
- }
+ public static JSONArray toJSONArray(final JSONArray names, final JSONTokener x) throws JSONException
+ {
+ if ((names == null) || (names.length() == 0)) { return null; }
final JSONArray ja = new JSONArray();
- for (;;) {
+ for (;;)
+ {
final JSONObject jo = rowToJSONObject(names, x);
- if (jo == null) {
+ if (jo == null)
+ {
break;
}
ja.put(jo);
}
- if (ja.length() == 0) {
- return null;
- }
+ if (ja.length() == 0) { return null; }
return ja;
}
@@ -227,13 +245,13 @@ public class CDL {
*
* @throws JSONException
*/
- public static String toString(final JSONArray ja) throws JSONException {
+ public static String toString(final JSONArray ja) throws JSONException
+ {
final JSONObject jo = ja.optJSONObject(0);
- if (jo != null) {
+ if (jo != null)
+ {
final JSONArray names = jo.names();
- if (names != null) {
- return rowToString(names) + toString(names, ja);
- }
+ if (names != null) { return rowToString(names) + toString(names, ja); }
}
return null;
}
@@ -249,14 +267,15 @@ public class CDL {
*
* @throws JSONException
*/
- public static String toString(final JSONArray names, final JSONArray ja) throws JSONException {
- if ((names == null) || (names.length() == 0)) {
- return null;
- }
+ public static String toString(final JSONArray names, final JSONArray ja) throws JSONException
+ {
+ if ((names == null) || (names.length() == 0)) { return null; }
final StringBuilder sb = new StringBuilder();
- for (int i = 0; i < ja.length(); i += 1) {
+ for (int i = 0; i < ja.length(); i += 1)
+ {
final JSONObject jo = ja.optJSONObject(i);
- if (jo != null) {
+ if (jo != null)
+ {
sb.append(rowToString(jo.toJSONArray(names)));
}
}
diff --git a/src/main/java/com/intellectualcrafters/json/Cookie.java b/src/main/java/com/intellectualcrafters/json/Cookie.java
index 13a11c597..52f90895d 100644
--- a/src/main/java/com/intellectualcrafters/json/Cookie.java
+++ b/src/main/java/com/intellectualcrafters/json/Cookie.java
@@ -27,7 +27,8 @@ package com.intellectualcrafters.json;
* @author JSON.org
* @version 2014-05-03
*/
-public class Cookie {
+public class Cookie
+{
/**
* Produce a copy of a string in which the characters '+', '%', '=', ';' and control characters are replaced with
* "%hh". This is a gentle form of URL encoding, attempting to cause as little distortion to the string as possible.
@@ -39,18 +40,23 @@ public class Cookie {
*
* @return The escaped result.
*/
- public static String escape(final String string) {
+ public static String escape(final String string)
+ {
char c;
final String s = string.trim();
final int length = s.length();
final StringBuilder sb = new StringBuilder(length);
- for (int i = 0; i < length; i += 1) {
+ for (int i = 0; i < length; i += 1)
+ {
c = s.charAt(i);
- if ((c < ' ') || (c == '+') || (c == '%') || (c == '=') || (c == ';')) {
+ if ((c < ' ') || (c == '+') || (c == '%') || (c == '=') || (c == ';'))
+ {
sb.append('%');
sb.append(Character.forDigit((char) ((c >>> 4) & 0x0f), 16));
sb.append(Character.forDigit((char) (c & 0x0f), 16));
- } else {
+ }
+ else
+ {
sb.append(c);
}
}
@@ -71,7 +77,8 @@ public class Cookie {
*
* @throws JSONException
*/
- public static JSONObject toJSONObject(final String string) throws JSONException {
+ public static JSONObject toJSONObject(final String string) throws JSONException
+ {
String name;
final JSONObject jo = new JSONObject();
Object value;
@@ -80,15 +87,22 @@ public class Cookie {
x.next('=');
jo.put("value", x.nextTo(';'));
x.next();
- while (x.more()) {
+ while (x.more())
+ {
name = unescape(x.nextTo("=;"));
- if (x.next() != '=') {
- if (name.equals("secure")) {
+ if (x.next() != '=')
+ {
+ if (name.equals("secure"))
+ {
value = Boolean.TRUE;
- } else {
+ }
+ else
+ {
throw x.syntaxError("Missing '=' in cookie parameter.");
}
- } else {
+ }
+ else
+ {
value = unescape(x.nextTo(';'));
x.next();
}
@@ -108,24 +122,29 @@ public class Cookie {
*
* @throws JSONException
*/
- public static String toString(final JSONObject jo) throws JSONException {
+ public static String toString(final JSONObject jo) throws JSONException
+ {
final StringBuilder sb = new StringBuilder();
sb.append(escape(jo.getString("name")));
sb.append("=");
sb.append(escape(jo.getString("value")));
- if (jo.has("expires")) {
+ if (jo.has("expires"))
+ {
sb.append(";expires=");
sb.append(jo.getString("expires"));
}
- if (jo.has("domain")) {
+ if (jo.has("domain"))
+ {
sb.append(";domain=");
sb.append(escape(jo.getString("domain")));
}
- if (jo.has("path")) {
+ if (jo.has("path"))
+ {
sb.append(";path=");
sb.append(escape(jo.getString("path")));
}
- if (jo.optBoolean("secure")) {
+ if (jo.optBoolean("secure"))
+ {
sb.append(";secure");
}
return sb.toString();
@@ -139,17 +158,23 @@ public class Cookie {
*
* @return The unescaped string.
*/
- public static String unescape(final String string) {
+ public static String unescape(final String string)
+ {
final int length = string.length();
final StringBuilder sb = new StringBuilder(length);
- for (int i = 0; i < length; ++i) {
+ for (int i = 0; i < length; ++i)
+ {
char c = string.charAt(i);
- if (c == '+') {
+ if (c == '+')
+ {
c = ' ';
- } else if ((c == '%') && ((i + 2) < length)) {
+ }
+ else if ((c == '%') && ((i + 2) < length))
+ {
final int d = JSONTokener.dehexchar(string.charAt(i + 1));
final int e = JSONTokener.dehexchar(string.charAt(i + 2));
- if ((d >= 0) && (e >= 0)) {
+ if ((d >= 0) && (e >= 0))
+ {
c = (char) ((d * 16) + e);
i += 2;
}
diff --git a/src/main/java/com/intellectualcrafters/json/CookieList.java b/src/main/java/com/intellectualcrafters/json/CookieList.java
index 85553dc13..add20262f 100644
--- a/src/main/java/com/intellectualcrafters/json/CookieList.java
+++ b/src/main/java/com/intellectualcrafters/json/CookieList.java
@@ -8,12 +8,13 @@ import java.util.Iterator;
* @author JSON.org
* @version 2014-05-03
*/
-public class CookieList {
+public class CookieList
+{
/**
* Convert a cookie list into a JSONObject. A cookie list is a sequence of name/value pairs. The names are separated
* from the values by '='. The pairs are separated by ';'. The names and the values will be unescaped, possibly
* converting '+' and '%' sequences.
- *
+ *
* To add a cookie to a cooklist, cookielistJSONObject.put(cookieJSONObject.getString("name"),
* cookieJSONObject.getString("value"));
*
@@ -23,10 +24,12 @@ public class CookieList {
*
* @throws JSONException
*/
- public static JSONObject toJSONObject(final String string) throws JSONException {
+ public static JSONObject toJSONObject(final String string) throws JSONException
+ {
final JSONObject jo = new JSONObject();
final JSONTokener x = new JSONTokener(string);
- while (x.more()) {
+ while (x.more())
+ {
final String name = Cookie.unescape(x.nextTo('='));
x.next('=');
jo.put(name, Cookie.unescape(x.nextTo(';')));
@@ -46,15 +49,19 @@ public class CookieList {
*
* @throws JSONException
*/
- public static String toString(final JSONObject jo) throws JSONException {
+ public static String toString(final JSONObject jo) throws JSONException
+ {
boolean b = false;
final Iterator keys = jo.keys();
String string;
final StringBuilder sb = new StringBuilder();
- while (keys.hasNext()) {
+ while (keys.hasNext())
+ {
string = keys.next();
- if (!jo.isNull(string)) {
- if (b) {
+ if (!jo.isNull(string))
+ {
+ if (b)
+ {
sb.append(';');
}
sb.append(Cookie.escape(string));
diff --git a/src/main/java/com/intellectualcrafters/json/HTTP.java b/src/main/java/com/intellectualcrafters/json/HTTP.java
index 2e5f2b763..01d5e26e9 100644
--- a/src/main/java/com/intellectualcrafters/json/HTTP.java
+++ b/src/main/java/com/intellectualcrafters/json/HTTP.java
@@ -28,31 +28,37 @@ import java.util.Iterator;
* @author JSON.org
* @version 2014-05-03
*/
-public class HTTP {
+public class HTTP
+{
/**
* Carriage return/line feed.
*/
public static final String CRLF = "\r\n";
- public static JSONObject toJSONObject(final String string) throws JSONException {
+ public static JSONObject toJSONObject(final String string) throws JSONException
+ {
final JSONObject jo = new JSONObject();
final HTTPTokener x = new HTTPTokener(string);
String token;
token = x.nextToken();
- if (token.toUpperCase().startsWith("HTTP")) {
+ if (token.toUpperCase().startsWith("HTTP"))
+ {
// Response
jo.put("HTTP-Version", token);
jo.put("Status-Code", x.nextToken());
jo.put("Reason-Phrase", x.nextTo('\0'));
x.next();
- } else {
+ }
+ else
+ {
// Request
jo.put("Method", token);
jo.put("Request-URI", x.nextToken());
jo.put("HTTP-Version", x.nextToken());
}
// Fields
- while (x.more()) {
+ while (x.more())
+ {
final String name = x.nextTo(':');
x.next(':');
jo.put(name, x.nextTo('\0'));
@@ -63,8 +69,8 @@ public class HTTP {
/**
* Convert a JSONObject into an HTTP header. A request header must contain
- *
- *
+ *
+ *
*
* {
* Method: "POST" (for example),
@@ -72,10 +78,10 @@ public class HTTP {
* "HTTP-Version": "HTTP/1.1" (for example)
* }
*
- *
+ *
* A response header must contain
- *
- *
+ *
+ *
*
* {
* "HTTP-Version": "HTTP/1.1" (for example),
@@ -83,7 +89,7 @@ public class HTTP {
* "Reason-Phrase": "OK" (for example)
* }
*
- *
+ *
* Any other members of the JSONObject will be output as HTTP fields. The result will end with two CRLF pairs.
*
* @param jo A JSONObject
@@ -92,17 +98,21 @@ public class HTTP {
*
* @throws JSONException if the object does not contain enough information.
*/
- public static String toString(final JSONObject jo) throws JSONException {
+ public static String toString(final JSONObject jo) throws JSONException
+ {
final Iterator keys = jo.keys();
String string;
final StringBuilder sb = new StringBuilder();
- if (jo.has("Status-Code") && jo.has("Reason-Phrase")) {
+ if (jo.has("Status-Code") && jo.has("Reason-Phrase"))
+ {
sb.append(jo.getString("HTTP-Version"));
sb.append(' ');
sb.append(jo.getString("Status-Code"));
sb.append(' ');
sb.append(jo.getString("Reason-Phrase"));
- } else if (jo.has("Method") && jo.has("Request-URI")) {
+ }
+ else if (jo.has("Method") && jo.has("Request-URI"))
+ {
sb.append(jo.getString("Method"));
sb.append(' ');
sb.append('"');
@@ -110,13 +120,17 @@ public class HTTP {
sb.append('"');
sb.append(' ');
sb.append(jo.getString("HTTP-Version"));
- } else {
+ }
+ else
+ {
throw new JSONException("Not enough material for an HTTP header.");
}
sb.append(CRLF);
- while (keys.hasNext()) {
+ while (keys.hasNext())
+ {
string = keys.next();
- if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) && !"Reason-Phrase".equals(string) && !"Method".equals(string) && !"Request-URI".equals(string) && !jo.isNull(string)) {
+ if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) && !"Reason-Phrase".equals(string) && !"Method".equals(string) && !"Request-URI".equals(string) && !jo.isNull(string))
+ {
sb.append(string);
sb.append(": ");
sb.append(jo.getString(string));
diff --git a/src/main/java/com/intellectualcrafters/json/HTTPTokener.java b/src/main/java/com/intellectualcrafters/json/HTTPTokener.java
index d6bb2cf1e..ad99eae1d 100644
--- a/src/main/java/com/intellectualcrafters/json/HTTPTokener.java
+++ b/src/main/java/com/intellectualcrafters/json/HTTPTokener.java
@@ -6,13 +6,15 @@ package com.intellectualcrafters.json;
* @author JSON.org
* @version 2014-05-03
*/
-public class HTTPTokener extends JSONTokener {
+public class HTTPTokener extends JSONTokener
+{
/**
* Construct an HTTPTokener from a string.
*
* @param string A source string.
*/
- public HTTPTokener(final String string) {
+ public HTTPTokener(final String string)
+ {
super(string);
}
@@ -23,30 +25,30 @@ public class HTTPTokener extends JSONTokener {
*
* @throws JSONException
*/
- public String nextToken() throws JSONException {
+ public String nextToken() throws JSONException
+ {
char c;
char q;
final StringBuilder sb = new StringBuilder();
- do {
+ do
+ {
c = next();
- } while (Character.isWhitespace(c));
- if ((c == '"') || (c == '\'')) {
+ }
+ while (Character.isWhitespace(c));
+ if ((c == '"') || (c == '\''))
+ {
q = c;
- for (;;) {
+ for (;;)
+ {
c = next();
- if (c < ' ') {
- throw syntaxError("Unterminated string.");
- }
- if (c == q) {
- return sb.toString();
- }
+ if (c < ' ') { throw syntaxError("Unterminated string."); }
+ if (c == q) { return sb.toString(); }
sb.append(c);
}
}
- for (;;) {
- if ((c == 0) || Character.isWhitespace(c)) {
- return sb.toString();
- }
+ for (;;)
+ {
+ if ((c == 0) || Character.isWhitespace(c)) { return sb.toString(); }
sb.append(c);
c = next();
}
diff --git a/src/main/java/com/intellectualcrafters/json/JSONArray.java b/src/main/java/com/intellectualcrafters/json/JSONArray.java
index c31b44653..64711cea6 100644
--- a/src/main/java/com/intellectualcrafters/json/JSONArray.java
+++ b/src/main/java/com/intellectualcrafters/json/JSONArray.java
@@ -34,16 +34,16 @@ import java.util.Map;
* accessing the values by index, and put
methods for adding or replacing values. The values can be any of
* these types: Boolean
, JSONArray
, JSONObject
, Number
,
* String
, or the JSONObject.NULL object
.
- *
+ *
* The constructor can convert a JSON text into a Java object. The toString
method converts to JSON text.
- *
+ *
* A get
method returns a value if one can be found, and throws an exception if one cannot be found. An
* opt
method returns a default value instead of throwing an exception, and so is useful for obtaining
* optional values.
- *
+ *
* The generic get()
and opt()
methods return an object which you can cast or query for type.
* There are also typed get
and opt
methods that do type checking and type coercion for you.
- *
+ *
* The texts produced by the toString
methods strictly conform to JSON syntax rules. The constructors are
* more forgiving in the texts they will accept: An extra ,
(comma) may appear
* just before the closing bracket. The null
value will be inserted when there is ,
@@ -56,7 +56,8 @@ import java.util.Map;
* @author JSON.org
* @version 2014-05-03
*/
-public class JSONArray {
+public class JSONArray
+{
/**
* The arrayList where the JSONArray's properties are kept.
*/
@@ -65,8 +66,9 @@ public class JSONArray {
/**
* Construct an empty JSONArray.
*/
- public JSONArray() {
- this.myArrayList = new ArrayList();
+ public JSONArray()
+ {
+ myArrayList = new ArrayList();
}
/**
@@ -76,26 +78,29 @@ public class JSONArray {
*
* @throws JSONException If there is a syntax error.
*/
- public JSONArray(final JSONTokener x) throws JSONException {
+ public JSONArray(final JSONTokener x) throws JSONException
+ {
this();
- if (x.nextClean() != '[') {
- throw x.syntaxError("A JSONArray text must start with '['");
- }
- if (x.nextClean() != ']') {
+ if (x.nextClean() != '[') { throw x.syntaxError("A JSONArray text must start with '['"); }
+ if (x.nextClean() != ']')
+ {
x.back();
- for (;;) {
- if (x.nextClean() == ',') {
+ for (;;)
+ {
+ if (x.nextClean() == ',')
+ {
x.back();
- this.myArrayList.add(JSONObject.NULL);
- } else {
- x.back();
- this.myArrayList.add(x.nextValue());
+ myArrayList.add(JSONObject.NULL);
}
- switch (x.nextClean()) {
+ else
+ {
+ x.back();
+ myArrayList.add(x.nextValue());
+ }
+ switch (x.nextClean())
+ {
case ',':
- if (x.nextClean() == ']') {
- return;
- }
+ if (x.nextClean() == ']') { return; }
x.back();
break;
case ']':
@@ -115,7 +120,8 @@ public class JSONArray {
*
* @throws JSONException If there is a syntax error.
*/
- public JSONArray(final String source) throws JSONException {
+ public JSONArray(final String source) throws JSONException
+ {
this(new JSONTokener(source));
}
@@ -124,11 +130,14 @@ public class JSONArray {
*
* @param collection A Collection.
*/
- public JSONArray(final Collection collection) {
- this.myArrayList = new ArrayList();
- if (collection != null) {
- for (final Object aCollection : collection) {
- this.myArrayList.add(JSONObject.wrap(aCollection));
+ public JSONArray(final Collection collection)
+ {
+ myArrayList = new ArrayList();
+ if (collection != null)
+ {
+ for (final Object aCollection : collection)
+ {
+ myArrayList.add(JSONObject.wrap(aCollection));
}
}
}
@@ -138,14 +147,19 @@ public class JSONArray {
*
* @throws JSONException If not an array.
*/
- public JSONArray(final Object array) throws JSONException {
+ public JSONArray(final Object array) throws JSONException
+ {
this();
- if (array.getClass().isArray()) {
+ if (array.getClass().isArray())
+ {
final int length = Array.getLength(array);
- for (int i = 0; i < length; i += 1) {
+ for (int i = 0; i < length; i += 1)
+ {
this.put(JSONObject.wrap(Array.get(array, i)));
}
- } else {
+ }
+ else
+ {
throw new JSONException("JSONArray initial value should be a string or collection or array.");
}
}
@@ -159,11 +173,10 @@ public class JSONArray {
*
* @throws JSONException If there is no value for the index.
*/
- public Object get(final int index) throws JSONException {
- final Object object = this.opt(index);
- if (object == null) {
- throw new JSONException("JSONArray[" + index + "] not found.");
- }
+ public Object get(final int index) throws JSONException
+ {
+ final Object object = opt(index);
+ if (object == null) { throw new JSONException("JSONArray[" + index + "] not found."); }
return object;
}
@@ -176,13 +189,14 @@ public class JSONArray {
*
* @throws JSONException If there is no value for the index or if the value is not convertible to boolean.
*/
- public boolean getBoolean(final int index) throws JSONException {
- final Object object = this.get(index);
- if (object.equals(Boolean.FALSE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("false"))) {
+ public boolean getBoolean(final int index) throws JSONException
+ {
+ final Object object = get(index);
+ if (object.equals(Boolean.FALSE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("false")))
+ {
return false;
- } else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) {
- return true;
}
+ else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) { return true; }
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
}
@@ -195,11 +209,15 @@ public class JSONArray {
*
* @throws JSONException If the key is not found or if the value cannot be converted to a number.
*/
- public double getDouble(final int index) throws JSONException {
- final Object object = this.get(index);
- try {
+ public double getDouble(final int index) throws JSONException
+ {
+ final Object object = get(index);
+ try
+ {
return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object);
- } catch (final Exception e) {
+ }
+ catch (final Exception e)
+ {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
}
@@ -213,11 +231,15 @@ public class JSONArray {
*
* @throws JSONException If the key is not found or if the value is not a number.
*/
- public int getInt(final int index) throws JSONException {
- final Object object = this.get(index);
- try {
+ public int getInt(final int index) throws JSONException
+ {
+ final Object object = get(index);
+ try
+ {
return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object);
- } catch (final Exception e) {
+ }
+ catch (final Exception e)
+ {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
}
@@ -231,11 +253,10 @@ public class JSONArray {
*
* @throws JSONException If there is no value for the index. or if the value is not a JSONArray
*/
- public JSONArray getJSONArray(final int index) throws JSONException {
- final Object object = this.get(index);
- if (object instanceof JSONArray) {
- return (JSONArray) object;
- }
+ public JSONArray getJSONArray(final int index) throws JSONException
+ {
+ final Object object = get(index);
+ if (object instanceof JSONArray) { return (JSONArray) object; }
throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
}
@@ -248,11 +269,10 @@ public class JSONArray {
*
* @throws JSONException If there is no value for the index or if the value is not a JSONObject
*/
- public JSONObject getJSONObject(final int index) throws JSONException {
- final Object object = this.get(index);
- if (object instanceof JSONObject) {
- return (JSONObject) object;
- }
+ public JSONObject getJSONObject(final int index) throws JSONException
+ {
+ final Object object = get(index);
+ if (object instanceof JSONObject) { return (JSONObject) object; }
throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
}
@@ -265,11 +285,15 @@ public class JSONArray {
*
* @throws JSONException If the key is not found or if the value cannot be converted to a number.
*/
- public long getLong(final int index) throws JSONException {
- final Object object = this.get(index);
- try {
+ public long getLong(final int index) throws JSONException
+ {
+ final Object object = get(index);
+ try
+ {
return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object);
- } catch (final Exception e) {
+ }
+ catch (final Exception e)
+ {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
}
@@ -283,11 +307,10 @@ public class JSONArray {
*
* @throws JSONException If there is no string value for the index.
*/
- public String getString(final int index) throws JSONException {
- final Object object = this.get(index);
- if (object instanceof String) {
- return (String) object;
- }
+ public String getString(final int index) throws JSONException
+ {
+ final Object object = get(index);
+ if (object instanceof String) { return (String) object; }
throw new JSONException("JSONArray[" + index + "] not a string.");
}
@@ -298,8 +321,9 @@ public class JSONArray {
*
* @return true if the value at the index is null, or if there is no value.
*/
- public boolean isNull(final int index) {
- return JSONObject.NULL.equals(this.opt(index));
+ public boolean isNull(final int index)
+ {
+ return JSONObject.NULL.equals(opt(index));
}
/**
@@ -312,14 +336,17 @@ public class JSONArray {
*
* @throws JSONException If the array contains an invalid number.
*/
- public String join(final String separator) throws JSONException {
- final int len = this.length();
+ public String join(final String separator) throws JSONException
+ {
+ final int len = length();
final StringBuilder sb = new StringBuilder();
- for (int i = 0; i < len; i += 1) {
- if (i > 0) {
+ for (int i = 0; i < len; i += 1)
+ {
+ if (i > 0)
+ {
sb.append(separator);
}
- sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
+ sb.append(JSONObject.valueToString(myArrayList.get(i)));
}
return sb.toString();
}
@@ -329,8 +356,9 @@ public class JSONArray {
*
* @return The length (or size).
*/
- public int length() {
- return this.myArrayList.size();
+ public int length()
+ {
+ return myArrayList.size();
}
/**
@@ -340,8 +368,9 @@ public class JSONArray {
*
* @return An object value, or null if there is no object at that index.
*/
- public Object opt(final int index) {
- return ((index < 0) || (index >= this.length())) ? null : this.myArrayList.get(index);
+ public Object opt(final int index)
+ {
+ return ((index < 0) || (index >= length())) ? null : myArrayList.get(index);
}
/**
@@ -352,7 +381,8 @@ public class JSONArray {
*
* @return The truth.
*/
- public boolean optBoolean(final int index) {
+ public boolean optBoolean(final int index)
+ {
return this.optBoolean(index, false);
}
@@ -365,10 +395,14 @@ public class JSONArray {
*
* @return The truth.
*/
- public boolean optBoolean(final int index, final boolean defaultValue) {
- try {
- return this.getBoolean(index);
- } catch (final Exception e) {
+ public boolean optBoolean(final int index, final boolean defaultValue)
+ {
+ try
+ {
+ return getBoolean(index);
+ }
+ catch (final Exception e)
+ {
return defaultValue;
}
}
@@ -381,7 +415,8 @@ public class JSONArray {
*
* @return The value.
*/
- public double optDouble(final int index) {
+ public double optDouble(final int index)
+ {
return this.optDouble(index, Double.NaN);
}
@@ -394,10 +429,14 @@ public class JSONArray {
*
* @return The value.
*/
- public double optDouble(final int index, final double defaultValue) {
- try {
- return this.getDouble(index);
- } catch (final Exception e) {
+ public double optDouble(final int index, final double defaultValue)
+ {
+ try
+ {
+ return getDouble(index);
+ }
+ catch (final Exception e)
+ {
return defaultValue;
}
}
@@ -410,7 +449,8 @@ public class JSONArray {
*
* @return The value.
*/
- public int optInt(final int index) {
+ public int optInt(final int index)
+ {
return this.optInt(index, 0);
}
@@ -423,10 +463,14 @@ public class JSONArray {
*
* @return The value.
*/
- public int optInt(final int index, final int defaultValue) {
- try {
- return this.getInt(index);
- } catch (final Exception e) {
+ public int optInt(final int index, final int defaultValue)
+ {
+ try
+ {
+ return getInt(index);
+ }
+ catch (final Exception e)
+ {
return defaultValue;
}
}
@@ -438,8 +482,9 @@ public class JSONArray {
*
* @return A JSONArray value, or null if the index has no value, or if the value is not a JSONArray.
*/
- public JSONArray optJSONArray(final int index) {
- final Object o = this.opt(index);
+ public JSONArray optJSONArray(final int index)
+ {
+ final Object o = opt(index);
return o instanceof JSONArray ? (JSONArray) o : null;
}
@@ -451,8 +496,9 @@ public class JSONArray {
*
* @return A JSONObject value.
*/
- public JSONObject optJSONObject(final int index) {
- final Object o = this.opt(index);
+ public JSONObject optJSONObject(final int index)
+ {
+ final Object o = opt(index);
return o instanceof JSONObject ? (JSONObject) o : null;
}
@@ -464,7 +510,8 @@ public class JSONArray {
*
* @return The value.
*/
- public long optLong(final int index) {
+ public long optLong(final int index)
+ {
return this.optLong(index, 0);
}
@@ -477,10 +524,14 @@ public class JSONArray {
*
* @return The value.
*/
- public long optLong(final int index, final long defaultValue) {
- try {
- return this.getLong(index);
- } catch (final Exception e) {
+ public long optLong(final int index, final long defaultValue)
+ {
+ try
+ {
+ return getLong(index);
+ }
+ catch (final Exception e)
+ {
return defaultValue;
}
}
@@ -493,7 +544,8 @@ public class JSONArray {
*
* @return A String value.
*/
- public String optString(final int index) {
+ public String optString(final int index)
+ {
return this.optString(index, "");
}
@@ -505,8 +557,9 @@ public class JSONArray {
*
* @return A String value.
*/
- public String optString(final int index, final String defaultValue) {
- final Object object = this.opt(index);
+ public String optString(final int index, final String defaultValue)
+ {
+ final Object object = opt(index);
return JSONObject.NULL.equals(object) ? defaultValue : object.toString();
}
@@ -517,7 +570,8 @@ public class JSONArray {
*
* @return this.
*/
- public JSONArray put(final boolean value) {
+ public JSONArray put(final boolean value)
+ {
this.put(value ? Boolean.TRUE : Boolean.FALSE);
return this;
}
@@ -529,7 +583,8 @@ public class JSONArray {
*
* @return this.
*/
- public JSONArray put(final Collection value) {
+ public JSONArray put(final Collection value)
+ {
this.put(new JSONArray(value));
return this;
}
@@ -543,7 +598,8 @@ public class JSONArray {
*
* @throws JSONException if the value is not finite.
*/
- public JSONArray put(final double value) throws JSONException {
+ public JSONArray put(final double value) throws JSONException
+ {
final Double d = value;
JSONObject.testValidity(d);
this.put(d);
@@ -557,7 +613,8 @@ public class JSONArray {
*
* @return this.
*/
- public JSONArray put(final int value) {
+ public JSONArray put(final int value)
+ {
this.put(new Integer(value));
return this;
}
@@ -569,7 +626,8 @@ public class JSONArray {
*
* @return this.
*/
- public JSONArray put(final long value) {
+ public JSONArray put(final long value)
+ {
this.put(new Long(value));
return this;
}
@@ -581,7 +639,8 @@ public class JSONArray {
*
* @return this.
*/
- public JSONArray put(final Map value) {
+ public JSONArray put(final Map value)
+ {
this.put(new JSONObject(value));
return this;
}
@@ -594,8 +653,9 @@ public class JSONArray {
*
* @return this.
*/
- public JSONArray put(final Object value) {
- this.myArrayList.add(value);
+ public JSONArray put(final Object value)
+ {
+ myArrayList.add(value);
return this;
}
@@ -610,7 +670,8 @@ public class JSONArray {
*
* @throws JSONException If the index is negative.
*/
- public JSONArray put(final int index, final boolean value) throws JSONException {
+ public JSONArray put(final int index, final boolean value) throws JSONException
+ {
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
return this;
}
@@ -625,7 +686,8 @@ public class JSONArray {
*
* @throws JSONException If the index is negative or if the value is not finite.
*/
- public JSONArray put(final int index, final Collection value) throws JSONException {
+ public JSONArray put(final int index, final Collection value) throws JSONException
+ {
this.put(index, new JSONArray(value));
return this;
}
@@ -641,7 +703,8 @@ public class JSONArray {
*
* @throws JSONException If the index is negative or if the value is not finite.
*/
- public JSONArray put(final int index, final double value) throws JSONException {
+ public JSONArray put(final int index, final double value) throws JSONException
+ {
this.put(index, new Double(value));
return this;
}
@@ -657,7 +720,8 @@ public class JSONArray {
*
* @throws JSONException If the index is negative.
*/
- public JSONArray put(final int index, final int value) throws JSONException {
+ public JSONArray put(final int index, final int value) throws JSONException
+ {
this.put(index, new Integer(value));
return this;
}
@@ -673,7 +737,8 @@ public class JSONArray {
*
* @throws JSONException If the index is negative.
*/
- public JSONArray put(final int index, final long value) throws JSONException {
+ public JSONArray put(final int index, final long value) throws JSONException
+ {
this.put(index, new Long(value));
return this;
}
@@ -688,7 +753,8 @@ public class JSONArray {
*
* @throws JSONException If the index is negative or if the the value is an invalid number.
*/
- public JSONArray put(final int index, final Map value) throws JSONException {
+ public JSONArray put(final int index, final Map value) throws JSONException
+ {
this.put(index, new JSONObject(value));
return this;
}
@@ -705,15 +771,18 @@ public class JSONArray {
*
* @throws JSONException If the index is negative or if the the value is an invalid number.
*/
- public JSONArray put(final int index, final Object value) throws JSONException {
+ public JSONArray put(final int index, final Object value) throws JSONException
+ {
JSONObject.testValidity(value);
- if (index < 0) {
- throw new JSONException("JSONArray[" + index + "] not found.");
+ if (index < 0) { throw new JSONException("JSONArray[" + index + "] not found."); }
+ if (index < length())
+ {
+ myArrayList.set(index, value);
}
- if (index < this.length()) {
- this.myArrayList.set(index, value);
- } else {
- while (index != this.length()) {
+ else
+ {
+ while (index != length())
+ {
this.put(JSONObject.NULL);
}
this.put(value);
@@ -728,8 +797,9 @@ public class JSONArray {
*
* @return The value that was associated with the index, or null if there was no value.
*/
- public Object remove(final int index) {
- return (index >= 0) && (index < this.length()) ? this.myArrayList.remove(index) : null;
+ public Object remove(final int index)
+ {
+ return (index >= 0) && (index < length()) ? myArrayList.remove(index) : null;
}
/**
@@ -739,28 +809,24 @@ public class JSONArray {
*
* @return true if they are equal
*/
- public boolean similar(final Object other) {
- if (!(other instanceof JSONArray)) {
- return false;
- }
- final int len = this.length();
- if (len != ((JSONArray) other).length()) {
- return false;
- }
- for (int i = 0; i < len; i += 1) {
- final Object valueThis = this.get(i);
+ public boolean similar(final Object other)
+ {
+ if (!(other instanceof JSONArray)) { return false; }
+ final int len = length();
+ if (len != ((JSONArray) other).length()) { return false; }
+ for (int i = 0; i < len; i += 1)
+ {
+ final Object valueThis = get(i);
final Object valueOther = ((JSONArray) other).get(i);
- if (valueThis instanceof JSONObject) {
- if (!((JSONObject) valueThis).similar(valueOther)) {
- return false;
- }
- } else if (valueThis instanceof JSONArray) {
- if (!((JSONArray) valueThis).similar(valueOther)) {
- return false;
- }
- } else if (!valueThis.equals(valueOther)) {
- return false;
+ if (valueThis instanceof JSONObject)
+ {
+ if (!((JSONObject) valueThis).similar(valueOther)) { return false; }
}
+ else if (valueThis instanceof JSONArray)
+ {
+ if (!((JSONArray) valueThis).similar(valueOther)) { return false; }
+ }
+ else if (!valueThis.equals(valueOther)) { return false; }
}
return true;
}
@@ -774,13 +840,13 @@ public class JSONArray {
*
* @throws JSONException If any of the names are null.
*/
- public JSONObject toJSONObject(final JSONArray names) throws JSONException {
- if ((names == null) || (names.length() == 0) || (this.length() == 0)) {
- return null;
- }
+ public JSONObject toJSONObject(final JSONArray names) throws JSONException
+ {
+ if ((names == null) || (names.length() == 0) || (length() == 0)) { return null; }
final JSONObject jo = new JSONObject();
- for (int i = 0; i < names.length(); i += 1) {
- jo.put(names.getString(i), this.opt(i));
+ for (int i = 0; i < names.length(); i += 1)
+ {
+ jo.put(names.getString(i), opt(i));
}
return jo;
}
@@ -789,16 +855,20 @@ public class JSONArray {
* Make a JSON text of this JSONArray. For compactness, no unnecessary whitespace is added. If it is not possible to
* produce a syntactically correct JSON text then null will be returned instead. This could occur if the array
* contains an invalid number.
- *
+ *
* Warning: This method assumes that the data structure is acyclical.
*
* @return a printable, displayable, transmittable representation of the array.
*/
@Override
- public String toString() {
- try {
+ public String toString()
+ {
+ try
+ {
return this.toString(0);
- } catch (final Exception e) {
+ }
+ catch (final Exception e)
+ {
return null;
}
}
@@ -815,29 +885,32 @@ public class JSONArray {
*
* @throws JSONException
*/
- public String toString(final int indentFactor) throws JSONException {
+ public String toString(final int indentFactor) throws JSONException
+ {
final StringWriter sw = new StringWriter();
- synchronized (sw.getBuffer()) {
+ synchronized (sw.getBuffer())
+ {
return this.write(sw, indentFactor, 0).toString();
}
}
/**
* Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added.
- *
+ *
* Warning: This method assumes that the data structure is acyclical.
*
* @return The writer.
*
* @throws JSONException
*/
- public Writer write(final Writer writer) throws JSONException {
+ public Writer write(final Writer writer) throws JSONException
+ {
return this.write(writer, 0, 0);
}
/**
* Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added.
- *
+ *
* Warning: This method assumes that the data structure is acyclical.
*
* @param indentFactor The number of spaces to add to each level of indentation.
@@ -847,34 +920,45 @@ public class JSONArray {
*
* @throws JSONException
*/
- Writer write(final Writer writer, final int indentFactor, final int indent) throws JSONException {
- try {
+ Writer write(final Writer writer, final int indentFactor, final int indent) throws JSONException
+ {
+ try
+ {
boolean commanate = false;
- final int length = this.length();
+ final int length = length();
writer.write('[');
- if (length == 1) {
- JSONObject.writeValue(writer, this.myArrayList.get(0), indentFactor, indent);
- } else if (length != 0) {
+ if (length == 1)
+ {
+ JSONObject.writeValue(writer, myArrayList.get(0), indentFactor, indent);
+ }
+ else if (length != 0)
+ {
final int newindent = indent + indentFactor;
- for (int i = 0; i < length; i += 1) {
- if (commanate) {
+ for (int i = 0; i < length; i += 1)
+ {
+ if (commanate)
+ {
writer.write(',');
}
- if (indentFactor > 0) {
+ if (indentFactor > 0)
+ {
writer.write('\n');
}
JSONObject.indent(writer, newindent);
- JSONObject.writeValue(writer, this.myArrayList.get(i), indentFactor, newindent);
+ JSONObject.writeValue(writer, myArrayList.get(i), indentFactor, newindent);
commanate = true;
}
- if (indentFactor > 0) {
+ if (indentFactor > 0)
+ {
writer.write('\n');
}
JSONObject.indent(writer, indent);
}
writer.write(']');
return writer;
- } catch (final IOException e) {
+ }
+ catch (final IOException e)
+ {
throw new JSONException(e);
}
}
diff --git a/src/main/java/com/intellectualcrafters/json/JSONException.java b/src/main/java/com/intellectualcrafters/json/JSONException.java
index 090d4e4f7..b30bd7425 100644
--- a/src/main/java/com/intellectualcrafters/json/JSONException.java
+++ b/src/main/java/com/intellectualcrafters/json/JSONException.java
@@ -6,7 +6,8 @@ package com.intellectualcrafters.json;
* @author JSON.org
* @version 2014-05-03
*/
-public class JSONException extends RuntimeException {
+public class JSONException extends RuntimeException
+{
private static final long serialVersionUID = 0;
private Throwable cause;
@@ -15,7 +16,8 @@ public class JSONException extends RuntimeException {
*
* @param message Detail about the reason for the exception.
*/
- public JSONException(final String message) {
+ public JSONException(final String message)
+ {
super(message);
}
@@ -24,7 +26,8 @@ public class JSONException extends RuntimeException {
*
* @param cause The cause.
*/
- public JSONException(final Throwable cause) {
+ public JSONException(final Throwable cause)
+ {
super(cause.getMessage());
this.cause = cause;
}
@@ -35,7 +38,8 @@ public class JSONException extends RuntimeException {
* @return the cause of this exception or null if the cause is nonexistent or unknown.
*/
@Override
- public Throwable getCause() {
- return this.cause;
+ public Throwable getCause()
+ {
+ return cause;
}
}
diff --git a/src/main/java/com/intellectualcrafters/json/JSONML.java b/src/main/java/com/intellectualcrafters/json/JSONML.java
index c63a5670b..0153d1e0c 100644
--- a/src/main/java/com/intellectualcrafters/json/JSONML.java
+++ b/src/main/java/com/intellectualcrafters/json/JSONML.java
@@ -9,7 +9,8 @@ import java.util.Iterator;
* @author JSON.org
* @version 2014-05-03
*/
-public class JSONML {
+public class JSONML
+{
/**
* Parse XML values and store them in a JSONArray.
*
@@ -21,7 +22,8 @@ public class JSONML {
*
* @throws JSONException
*/
- private static Object parse(final XMLTokener x, final boolean arrayForm, final JSONArray ja) throws JSONException {
+ private static Object parse(final XMLTokener x, final boolean arrayForm, final JSONArray ja) throws JSONException
+ {
String attribute;
char c;
String closeTag = null;
@@ -35,149 +37,188 @@ public class JSONML {
//
//
// ... ?>
- while (true) {
- if (!x.more()) {
- throw x.syntaxError("Bad XML");
- }
+ while (true)
+ {
+ if (!x.more()) { throw x.syntaxError("Bad XML"); }
token = x.nextContent();
- if (token == XML.LT) {
+ if (token == XML.LT)
+ {
token = x.nextToken();
- if (token instanceof Character) {
- if (token == XML.SLASH) {
+ if (token instanceof Character)
+ {
+ if (token == XML.SLASH)
+ {
// Close tag
token = x.nextToken();
- if (!(token instanceof String)) {
- throw new JSONException("Expected a closing name instead of '" + token + "'.");
- }
- if (x.nextToken() != XML.GT) {
- throw x.syntaxError("Misshaped close tag");
- }
+ if (!(token instanceof String)) { throw new JSONException("Expected a closing name instead of '" + token + "'."); }
+ if (x.nextToken() != XML.GT) { throw x.syntaxError("Misshaped close tag"); }
return token;
- } else if (token == XML.BANG) {
+ }
+ else if (token == XML.BANG)
+ {
// ");
- } else {
+ }
+ else
+ {
x.back();
}
- } else if (c == '[') {
+ }
+ else if (c == '[')
+ {
token = x.nextToken();
- if (token.equals("CDATA") && (x.next() == '[')) {
- if (ja != null) {
+ if (token.equals("CDATA") && (x.next() == '['))
+ {
+ if (ja != null)
+ {
ja.put(x.nextCDATA());
}
- } else {
+ }
+ else
+ {
throw x.syntaxError("Expected 'CDATA['");
}
- } else {
+ }
+ else
+ {
i = 1;
- do {
+ do
+ {
token = x.nextMeta();
- if (token == null) {
+ if (token == null)
+ {
throw x.syntaxError("Missing '>' after ' 0);
+ }
+ while (i > 0);
}
- } else if (token == XML.QUEST) {
+ }
+ else if (token == XML.QUEST)
+ {
//
x.skipPast("?>");
- } else {
+ }
+ else
+ {
throw x.syntaxError("Misshaped tag");
}
// Open tag <
- } else {
- if (!(token instanceof String)) {
- throw x.syntaxError("Bad tagName '" + token + "'.");
- }
+ }
+ else
+ {
+ if (!(token instanceof String)) { throw x.syntaxError("Bad tagName '" + token + "'."); }
tagName = (String) token;
newja = new JSONArray();
newjo = new JSONObject();
- if (arrayForm) {
+ if (arrayForm)
+ {
newja.put(tagName);
- if (ja != null) {
+ if (ja != null)
+ {
ja.put(newja);
}
- } else {
+ }
+ else
+ {
newjo.put("tagName", tagName);
- if (ja != null) {
+ if (ja != null)
+ {
ja.put(newjo);
}
}
token = null;
- for (;;) {
- if (token == null) {
+ for (;;)
+ {
+ if (token == null)
+ {
token = x.nextToken();
}
- if (token == null) {
- throw x.syntaxError("Misshaped tag");
- }
- if (!(token instanceof String)) {
+ if (token == null) { throw x.syntaxError("Misshaped tag"); }
+ if (!(token instanceof String))
+ {
break;
}
// attribute = value
attribute = (String) token;
- if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) {
- throw x.syntaxError("Reserved attribute.");
- }
+ if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) { throw x.syntaxError("Reserved attribute."); }
token = x.nextToken();
- if (token == XML.EQ) {
+ if (token == XML.EQ)
+ {
token = x.nextToken();
- if (!(token instanceof String)) {
- throw x.syntaxError("Missing value");
- }
+ if (!(token instanceof String)) { throw x.syntaxError("Missing value"); }
newjo.accumulate(attribute, XML.stringToValue((String) token));
token = null;
- } else {
+ }
+ else
+ {
newjo.accumulate(attribute, "");
}
}
- if (arrayForm && (newjo.length() > 0)) {
+ if (arrayForm && (newjo.length() > 0))
+ {
newja.put(newjo);
}
// Empty tag <.../>
- if (token == XML.SLASH) {
- if (x.nextToken() != XML.GT) {
- throw x.syntaxError("Misshaped tag");
- }
- if (ja == null) {
- if (arrayForm) {
+ if (token == XML.SLASH)
+ {
+ if (x.nextToken() != XML.GT) { throw x.syntaxError("Misshaped tag"); }
+ if (ja == null)
+ {
+ if (arrayForm)
+ {
return newja;
- } else {
+ }
+ else
+ {
return newjo;
}
}
// Content, between <...> and
- } else {
- if (token != XML.GT) {
- throw x.syntaxError("Misshaped tag");
- }
+ }
+ else
+ {
+ if (token != XML.GT) { throw x.syntaxError("Misshaped tag"); }
closeTag = (String) parse(x, arrayForm, newja);
- if (closeTag != null) {
- if (!closeTag.equals(tagName)) {
- throw x.syntaxError("Mismatched '" + tagName + "' and '" + closeTag + "'");
- }
+ if (closeTag != null)
+ {
+ if (!closeTag.equals(tagName)) { throw x.syntaxError("Mismatched '" + tagName + "' and '" + closeTag + "'"); }
tagName = null;
- if (!arrayForm && (newja.length() > 0)) {
+ if (!arrayForm && (newja.length() > 0))
+ {
newjo.put("childNodes", newja);
}
- if (ja == null) {
- if (arrayForm) {
+ if (ja == null)
+ {
+ if (arrayForm)
+ {
return newja;
- } else {
+ }
+ else
+ {
return newjo;
}
}
}
}
}
- } else {
- if (ja != null) {
+ }
+ else
+ {
+ if (ja != null)
+ {
ja.put(token instanceof String ? XML.stringToValue((String) token) : token);
}
}
@@ -195,7 +236,8 @@ public class JSONML {
*
* @throws JSONException
*/
- public static JSONArray toJSONArray(final String string) throws JSONException {
+ public static JSONArray toJSONArray(final String string) throws JSONException
+ {
return toJSONArray(new XMLTokener(string));
}
@@ -212,7 +254,8 @@ public class JSONML {
*
* @throws JSONException
*/
- public static JSONArray toJSONArray(final XMLTokener x) throws JSONException {
+ public static JSONArray toJSONArray(final XMLTokener x) throws JSONException
+ {
return (JSONArray) parse(x, true, null);
}
@@ -221,7 +264,7 @@ public class JSONML {
* XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes
* will be in the JSONObject as properties. If the tag contains children, the object will have a "childNodes"
* property which will be an array of strings and JsonML JSONObjects.
- *
+ *
* Comments, prologs, DTDs, and <[ [ ]]>
are ignored.
*
* @param x An XMLTokener of the XML source text.
@@ -230,7 +273,8 @@ public class JSONML {
*
* @throws JSONException
*/
- public static JSONObject toJSONObject(final XMLTokener x) throws JSONException {
+ public static JSONObject toJSONObject(final XMLTokener x) throws JSONException
+ {
return (JSONObject) parse(x, false, null);
}
@@ -239,7 +283,7 @@ public class JSONML {
* XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes
* will be in the JSONObject as properties. If the tag contains children, the object will have a "childNodes"
* property which will be an array of strings and JsonML JSONObjects.
- *
+ *
* Comments, prologs, DTDs, and <[ [ ]]>
are ignored.
*
* @param string The XML source text.
@@ -248,7 +292,8 @@ public class JSONML {
*
* @throws JSONException
*/
- public static JSONObject toJSONObject(final String string) throws JSONException {
+ public static JSONObject toJSONObject(final String string) throws JSONException
+ {
return toJSONObject(new XMLTokener(string));
}
@@ -261,7 +306,8 @@ public class JSONML {
*
* @throws JSONException
*/
- public static String toString(final JSONArray ja) throws JSONException {
+ public static String toString(final JSONArray ja) throws JSONException
+ {
int i;
JSONObject jo;
String key;
@@ -278,16 +324,19 @@ public class JSONML {
sb.append('<');
sb.append(tagName);
object = ja.opt(1);
- if (object instanceof JSONObject) {
+ if (object instanceof JSONObject)
+ {
i = 2;
jo = (JSONObject) object;
// Emit the attributes
keys = jo.keys();
- while (keys.hasNext()) {
+ while (keys.hasNext())
+ {
key = keys.next();
XML.noSpace(key);
value = jo.optString(key);
- if (value != null) {
+ if (value != null)
+ {
sb.append(' ');
sb.append(XML.escape(key));
sb.append('=');
@@ -296,29 +345,42 @@ public class JSONML {
sb.append('"');
}
}
- } else {
+ }
+ else
+ {
i = 1;
}
// Emit content in body
length = ja.length();
- if (i >= length) {
+ if (i >= length)
+ {
sb.append('/');
sb.append('>');
- } else {
+ }
+ else
+ {
sb.append('>');
- do {
+ do
+ {
object = ja.get(i);
i += 1;
- if (object != null) {
- if (object instanceof String) {
+ if (object != null)
+ {
+ if (object instanceof String)
+ {
sb.append(XML.escape(object.toString()));
- } else if (object instanceof JSONObject) {
+ }
+ else if (object instanceof JSONObject)
+ {
sb.append(toString((JSONObject) object));
- } else if (object instanceof JSONArray) {
+ }
+ else if (object instanceof JSONArray)
+ {
sb.append(toString((JSONArray) object));
}
}
- } while (i < length);
+ }
+ while (i < length);
sb.append('<');
sb.append('/');
sb.append(tagName);
@@ -338,7 +400,8 @@ public class JSONML {
*
* @throws JSONException
*/
- public static String toString(final JSONObject jo) throws JSONException {
+ public static String toString(final JSONObject jo) throws JSONException
+ {
final StringBuilder sb = new StringBuilder();
int i;
JSONArray ja;
@@ -350,21 +413,22 @@ public class JSONML {
String value;
// Emit ');
- } else {
+ }
+ else
+ {
sb.append('>');
length = ja.length();
- for (i = 0; i < length; i += 1) {
+ for (i = 0; i < length; i += 1)
+ {
object = ja.get(i);
- if (object != null) {
- if (object instanceof String) {
+ if (object != null)
+ {
+ if (object instanceof String)
+ {
sb.append(XML.escape(object.toString()));
- } else if (object instanceof JSONObject) {
+ }
+ else if (object instanceof JSONObject)
+ {
sb.append(toString((JSONObject) object));
- } else if (object instanceof JSONArray) {
+ }
+ else if (object instanceof JSONArray)
+ {
sb.append(toString((JSONArray) object));
- } else {
+ }
+ else
+ {
sb.append(object.toString());
}
}
diff --git a/src/main/java/com/intellectualcrafters/json/JSONObject.java b/src/main/java/com/intellectualcrafters/json/JSONObject.java
index 3cac13db7..2f126f21d 100644
--- a/src/main/java/com/intellectualcrafters/json/JSONObject.java
+++ b/src/main/java/com/intellectualcrafters/json/JSONObject.java
@@ -27,21 +27,21 @@ import java.util.Set;
* values into a JSON text using the put
and toString
methods. A get
method
* returns a value if one can be found, and throws an exception if one cannot be found. An opt
method
* returns a default value instead of throwing an exception, and so is useful for obtaining optional values.
- *
+ *
* The generic get()
and opt()
methods return an object, which you can cast or query for type.
* There are also typed get
and opt
methods that do type checking and type coercion for you.
* The opt methods differ from the get methods in that they do not throw. Instead, they return a specified value, such
* as null.
- *
+ *
* The put
methods add or replace values in an object. For example,
- *
- *
+ *
+ *
*
* myString = new JSONObject().put("JSON", "Hello, World!").toString();
*
- *
+ *
* produces the string {"JSON": "Hello, World"}
.
- *
+ *
* The texts produced by the toString
methods strictly conform to the JSON syntax rules. The constructors
* are more forgiving in the texts they will accept: An extra