Generic cleanup of warnings, whitespace and style.

By: Erik Broes <erikbroes@grum.nl>
This commit is contained in:
Bukkit/Spigot
2011-12-25 16:02:30 +01:00
parent 98960fd73e
commit aaab1cba23
257 changed files with 1408 additions and 1152 deletions

View File

@@ -70,12 +70,12 @@ public interface Configuration extends ConfigurationSection {
* @return Configuration source for default values, or null if none exist.
*/
public Configuration getDefaults();
/**
* Gets the {@link ConfigurationOptions} for this {@link Configuration}.
* <p>
* All setters through this method are chainable.
*
*
* @return Options for this configuration
*/
public ConfigurationOptions options();

View File

@@ -7,38 +7,38 @@ public class ConfigurationOptions {
private char pathSeparator = '.';
private boolean copyDefaults = false;
private final Configuration configuration;
protected ConfigurationOptions(Configuration configuration) {
this.configuration = configuration;
}
/**
* Returns the {@link Configuration} that this object is responsible for.
*
*
* @return Parent configuration
*/
public Configuration configuration() {
return configuration;
}
/**
* Gets the char that will be used to separate {@link ConfigurationSection}s
* <p>
* This value does not affect how the {@link Configuration} is stored, only in
* how you access the data. The default value is '.'.
*
*
* @return Path separator
*/
public char pathSeparator() {
return pathSeparator;
}
/**
* Sets the char that will be used to separate {@link ConfigurationSection}s
* <p>
* This value does not affect how the {@link Configuration} is stored, only in
* how you access the data. The default value is '.'.
*
*
* @param value Path separator
* @return This object, for chaining
*/
@@ -46,7 +46,7 @@ public class ConfigurationOptions {
this.pathSeparator = value;
return this;
}
/**
* Checks if the {@link Configuration} should copy values from its default {@link Configuration} directly.
* <p>
@@ -55,13 +55,13 @@ public class ConfigurationOptions {
* are provided by default. As a result, {@link ConfigurationSection#contains(java.lang.String)} will always
* return the same value as {@link ConfigurationSection#isSet(java.lang.String)}.
* The default value is false.
*
*
* @return Whether or not defaults are directly copied
*/
public boolean copyDefaults() {
return copyDefaults;
}
/**
* Sets if the {@link Configuration} should copy values from its default {@link Configuration} directly.
* <p>
@@ -70,7 +70,7 @@ public class ConfigurationOptions {
* are provided by default. As a result, {@link ConfigurationSection#contains(java.lang.String)} will always
* return the same value as {@link ConfigurationSection#isSet(java.lang.String)}.
* The default value is false.
*
*
* @param value Whether or not defaults are directly copied
* @return This object, for chaining
*/

View File

@@ -79,13 +79,13 @@ public interface ConfigurationSection {
* @return Path of this section relative to its root
*/
public String getCurrentPath();
/**
* Gets the name of this individual {@link ConfigurationSection}, in the path.
* <p>
* This will always be the final part of {@link #getCurrentPath()}, unless the
* section is orphaned.
*
*
* @return Name of this section
*/
public String getName();
@@ -146,7 +146,7 @@ public interface ConfigurationSection {
* <p>
* Some implementations may have limitations on what you may store. See their
* individual javadocs for details. No implementations should allow you to store
* {@link Configuration}s or {@link ConfigurationSection}s, please use
* {@link Configuration}s or {@link ConfigurationSection}s, please use
* {@link #createSection(java.lang.String)} for that.
*
* @param path Path of the object to set.
@@ -164,7 +164,7 @@ public interface ConfigurationSection {
* @return Newly created section
*/
public ConfigurationSection createSection(String path);
/**
* Creates a {@link ConfigurationSection} at the specified path, with specified values.
* <p>
@@ -213,7 +213,6 @@ public interface ConfigurationSection {
*/
public boolean isString(String path);
/**
* Gets the requested int by path.
* <p>
@@ -250,7 +249,6 @@ public interface ConfigurationSection {
*/
public boolean isInt(String path);
/**
* Gets the requested boolean by path.
* <p>
@@ -287,7 +285,6 @@ public interface ConfigurationSection {
*/
public boolean isBoolean(String path);
/**
* Gets the requested double by path.
* <p>
@@ -324,7 +321,6 @@ public interface ConfigurationSection {
*/
public boolean isDouble(String path);
/**
* Gets the requested long by path.
* <p>
@@ -361,8 +357,6 @@ public interface ConfigurationSection {
*/
public boolean isLong(String path);
// Java
/**
* Gets the requested List by path.
@@ -374,6 +368,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List.
*/
@SuppressWarnings("rawtypes")
public List getList(String path);
/**
@@ -385,7 +380,8 @@ public interface ConfigurationSection {
* @param path Path of the List to get.
* @return Requested List.
*/
public List getList(String path, List def);
@SuppressWarnings("rawtypes")
public List getList(String path, List<?> def);
/**
* Checks if the specified path is a List.
@@ -400,7 +396,6 @@ public interface ConfigurationSection {
*/
public boolean isList(String path);
/**
* Gets the requested List of String by path.
* <p>
@@ -551,7 +546,6 @@ public interface ConfigurationSection {
*/
public List<Map<String, Object>> getMapList(String path);
// Bukkit
/**
* Gets the requested Vector by path.
@@ -589,7 +583,6 @@ public interface ConfigurationSection {
*/
public boolean isVector(String path);
/**
* Gets the requested OfflinePlayer by path.
* <p>
@@ -626,7 +619,6 @@ public interface ConfigurationSection {
*/
public boolean isOfflinePlayer(String path);
/**
* Gets the requested ItemStack by path.
* <p>
@@ -663,7 +655,6 @@ public interface ConfigurationSection {
*/
public boolean isItemStack(String path);
/**
* Gets the requested ConfigurationSection by path.
* <p>
@@ -688,18 +679,18 @@ public interface ConfigurationSection {
* @return Whether or not the specified path is a ConfigurationSection.
*/
public boolean isConfigurationSection(String path);
/**
* Gets the equivalent {@link ConfigurationSection} from the default {@link Configuration} defined in {@link #getRoot()}.
* <p>
* If the root contains no defaults, or the defaults doesn't contain a value
* for this path, or the value at this path is not a {@link ConfigurationSection} then
* this will return null.
*
*
* @return Equivalent section in root configuration
*/
public ConfigurationSection getDefaultSection();
/**
* Sets the default value in the root at the given path as provided.
* <p>

View File

@@ -3,6 +3,7 @@ package org.bukkit.configuration;
/**
* Exception thrown when attempting to load an invalid {@link Configuration}
*/
@SuppressWarnings("serial")
public class InvalidConfigurationException extends Exception {
/**
* Creates a new instance of InvalidConfigurationException without a message or cause.

View File

@@ -32,7 +32,7 @@ public class MemoryConfiguration extends MemorySection implements Configuration
if (path == null) {
throw new IllegalArgumentException("Path may not be null");
}
if (defaults == null) {
defaults = new MemoryConfiguration();
}
@@ -79,7 +79,7 @@ public class MemoryConfiguration extends MemorySection implements Configuration
if (options == null) {
options = new MemoryConfigurationOptions(this);
}
return options;
}
}

View File

@@ -10,7 +10,7 @@ public class MemoryConfigurationOptions extends ConfigurationOptions {
@Override
public MemoryConfiguration configuration() {
return (MemoryConfiguration)super.configuration();
return (MemoryConfiguration) super.configuration();
}
@Override

View File

@@ -40,7 +40,7 @@ public class MemorySection implements ConfigurationSection {
this.path = "";
this.fullPath = "";
this.parent = null;
this.root = (Configuration)this;
this.root = (Configuration) this;
}
/**
@@ -65,16 +65,16 @@ public class MemorySection implements ConfigurationSection {
if (root == null) {
throw new IllegalArgumentException("Path cannot be orphaned");
}
this.fullPath = createPath(parent, path);
}
public Set<String> getKeys(boolean deep) {
Set<String> result = new LinkedHashSet<String>();
if (getRoot().options().copyDefaults()) {
ConfigurationSection defaults = getDefaultSection();
if (defaults != null) {
result.addAll(defaults.getKeys(deep));
}
@@ -87,10 +87,10 @@ public class MemorySection implements ConfigurationSection {
public Map<String, Object> getValues(boolean deep) {
Map<String, Object> result = new LinkedHashMap<String, Object>();
if (getRoot().options().copyDefaults()) {
ConfigurationSection defaults = getDefaultSection();
if (defaults != null) {
result.putAll(defaults.getValues(deep));
}
@@ -124,7 +124,7 @@ public class MemorySection implements ConfigurationSection {
public String getCurrentPath() {
return fullPath;
}
public String getName() {
return path;
}
@@ -136,32 +136,32 @@ public class MemorySection implements ConfigurationSection {
public ConfigurationSection getParent() {
return parent;
}
public void addDefault(String path, Object value) {
if (path == null) {
throw new IllegalArgumentException("Path cannot be null");
}
if (root == null) {
throw new IllegalStateException("Cannot set default on orphaned section");
} else {
root.addDefault(createPath(this, path), value);
}
}
public ConfigurationSection getDefaultSection() {
if (getRoot() == null) {
return null;
}
Configuration defaults = getRoot().getDefaults();
if (defaults != null) {
if (defaults.isConfigurationSection(getCurrentPath())) {
return defaults.getConfigurationSection(getCurrentPath());
}
}
return null;
}
@@ -169,9 +169,7 @@ public class MemorySection implements ConfigurationSection {
String[] split = path.split(Pattern.quote(Character.toString(getRoot().options().pathSeparator())));
ConfigurationSection section = this;
if (path == null) {
throw new IllegalArgumentException("Path cannot be null");
} else if (path.length() == 0) {
if (path.length() == 0) {
throw new IllegalArgumentException("Cannot set to an empty path");
}
@@ -219,7 +217,7 @@ public class MemorySection implements ConfigurationSection {
for (int i = 0; i < split.length - 1; i++) {
section = section.getConfigurationSection(split[i]);
if (section == null) {
return def;
}
@@ -230,11 +228,8 @@ public class MemorySection implements ConfigurationSection {
if (section == this) {
result = map.get(key);
return (result == null) ? def : result;
} else if (section != null) {
return section.get(key, def);
} else {
return def;
}
return section.get(key, def);
}
public ConfigurationSection createSection(String path) {
@@ -267,13 +262,14 @@ public class MemorySection implements ConfigurationSection {
return section.createSection(key);
}
}
@SuppressWarnings("unchecked")
public ConfigurationSection createSection(String path, Map<String, Object> map) {
ConfigurationSection section = createSection(path);
for(Map.Entry<String, Object> entry : map.entrySet()) {
if(entry.getValue() instanceof Map) {
section.createSection(entry.getKey(), (Map<String, Object>)entry.getValue());
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getValue() instanceof Map) {
section.createSection(entry.getKey(), (Map<String, Object>) entry.getValue());
} else {
section.set(entry.getKey(), entry.getValue());
}
@@ -343,7 +339,7 @@ public class MemorySection implements ConfigurationSection {
}
Object def = getDefault(path);
return getBoolean(path, (def instanceof Boolean) ? (Boolean)def : false);
return getBoolean(path, (def instanceof Boolean) ? (Boolean) def : false);
}
public boolean getBoolean(String path, boolean def) {
@@ -352,7 +348,7 @@ public class MemorySection implements ConfigurationSection {
}
Object val = get(path, def);
return (val instanceof Boolean) ? (Boolean)val : def;
return (val instanceof Boolean) ? (Boolean) val : def;
}
public boolean isBoolean(String path) {
@@ -418,23 +414,25 @@ public class MemorySection implements ConfigurationSection {
return val instanceof Long;
}
// Java
public List getList(String path) {
// Java
@SuppressWarnings("unchecked")
public List<Object> getList(String path) {
if (path == null) {
throw new IllegalArgumentException("Path cannot be null");
}
Object def = getDefault(path);
return getList(path, (def instanceof List) ? (List)def : null);
return getList(path, (def instanceof List) ? (List<Object>) def : null);
}
public List getList(String path, List def) {
@SuppressWarnings("unchecked")
public List<Object> getList(String path, List<?> def) {
if (path == null) {
throw new IllegalArgumentException("Path cannot be null");
}
Object val = get(path, def);
return (val instanceof List) ? (List)val : def;
return (List<Object>) ((val instanceof List) ? val : def);
}
public boolean isList(String path) {
@@ -452,19 +450,19 @@ public class MemorySection implements ConfigurationSection {
}
List<Object> list = getList(path);
if (list == null) {
return null;
}
List<String> result = new ArrayList();
List<String> result = new ArrayList<String>();
for (Object object : list) {
if ((object instanceof String) || (isPrimitiveWrapper(object))) {
result.add(String.valueOf(object));
}
}
return result;
}
@@ -474,37 +472,38 @@ public class MemorySection implements ConfigurationSection {
}
List<Object> list = getList(path);
if (list == null) {
return null;
}
List<Integer> result = new ArrayList();
List<Integer> result = new ArrayList<Integer>();
for (Object object : list) {
if (object instanceof Integer) {
result.add((Integer)object);
result.add((Integer) object);
} else if (object instanceof String) {
try {
result.add(Integer.valueOf((String)object));
} catch (Exception ex) {}
result.add(Integer.valueOf((String) object));
} catch (Exception ex) {
}
} else if (object instanceof Byte) {
result.add((Integer)(int)(byte)(Byte)object);
result.add((Integer) (int) (byte) (Byte) object);
} else if (object instanceof Character) {
result.add((Integer)(int)(char)(Character)object);
result.add((Integer) (int) (char) (Character) object);
} else if (object instanceof Short) {
result.add((Integer)(int)(short)(Short)object);
result.add((Integer) (int) (short) (Short) object);
} else if (object instanceof Integer) {
result.add((Integer)(int)(int)(Integer)object);
result.add((Integer) (int) (int) (Integer) object);
} else if (object instanceof Long) {
result.add((Integer)(int)(long)(Long)object);
result.add((Integer) (int) (long) (Long) object);
} else if (object instanceof Float) {
result.add((Integer)(int)(float)(Float)object);
result.add((Integer) (int) (float) (Float) object);
} else if (object instanceof Double) {
result.add((Integer)(int)(double)(Double)object);
result.add((Integer) (int) (double) (Double) object);
}
}
return result;
}
@@ -514,16 +513,16 @@ public class MemorySection implements ConfigurationSection {
}
List<Object> list = getList(path);
if (list == null) {
return null;
}
List<Boolean> result = new ArrayList();
List<Boolean> result = new ArrayList<Boolean>();
for (Object object : list) {
if (object instanceof Boolean) {
result.add((Boolean)object);
result.add((Boolean) object);
} else if (object instanceof String) {
if (Boolean.TRUE.toString().equals(object)) {
result.add(true);
@@ -532,7 +531,7 @@ public class MemorySection implements ConfigurationSection {
}
}
}
return result;
}
@@ -542,37 +541,38 @@ public class MemorySection implements ConfigurationSection {
}
List<Object> list = getList(path);
if (list == null) {
return null;
}
List<Double> result = new ArrayList();
List<Double> result = new ArrayList<Double>();
for (Object object : list) {
if (object instanceof Double) {
result.add((Double)object);
result.add((Double) object);
} else if (object instanceof String) {
try {
result.add(Double.valueOf((String)object));
} catch (Exception ex) {}
result.add(Double.valueOf((String) object));
} catch (Exception ex) {
}
} else if (object instanceof Byte) {
result.add((Double)(double)(byte)(Byte)object);
result.add((Double) (double) (byte) (Byte) object);
} else if (object instanceof Character) {
result.add((Double)(double)(char)(Character)object);
result.add((Double) (double) (char) (Character) object);
} else if (object instanceof Short) {
result.add((Double)(double)(short)(Short)object);
result.add((Double) (double) (short) (Short) object);
} else if (object instanceof Integer) {
result.add((Double)(double)(int)(Integer)object);
result.add((Double) (double) (int) (Integer) object);
} else if (object instanceof Long) {
result.add((Double)(double)(long)(Long)object);
result.add((Double) (double) (long) (Long) object);
} else if (object instanceof Float) {
result.add((Double)(double)(float)(Float)object);
result.add((Double) (double) (float) (Float) object);
} else if (object instanceof Double) {
result.add((Double)(double)(double)(Double)object);
result.add((Double) (double) (double) (Double) object);
}
}
return result;
}
@@ -582,37 +582,38 @@ public class MemorySection implements ConfigurationSection {
}
List<Object> list = getList(path);
if (list == null) {
return null;
}
List<Float> result = new ArrayList();
List<Float> result = new ArrayList<Float>();
for (Object object : list) {
if (object instanceof Float) {
result.add((Float)object);
result.add((Float) object);
} else if (object instanceof String) {
try {
result.add(Float.valueOf((String)object));
} catch (Exception ex) {}
result.add(Float.valueOf((String) object));
} catch (Exception ex) {
}
} else if (object instanceof Byte) {
result.add((Float)(float)(byte)(Byte)object);
result.add((Float) (float) (byte) (Byte) object);
} else if (object instanceof Character) {
result.add((Float)(float)(char)(Character)object);
result.add((Float) (float) (char) (Character) object);
} else if (object instanceof Short) {
result.add((Float)(float)(short)(Short)object);
result.add((Float) (float) (short) (Short) object);
} else if (object instanceof Integer) {
result.add((Float)(float)(int)(Integer)object);
result.add((Float) (float) (int) (Integer) object);
} else if (object instanceof Long) {
result.add((Float)(float)(long)(Long)object);
result.add((Float) (float) (long) (Long) object);
} else if (object instanceof Float) {
result.add((Float)(float)(float)(Float)object);
result.add((Float) (float) (float) (Float) object);
} else if (object instanceof Double) {
result.add((Float)(float)(double)(Double)object);
result.add((Float) (float) (double) (Double) object);
}
}
return result;
}
@@ -622,37 +623,38 @@ public class MemorySection implements ConfigurationSection {
}
List<Object> list = getList(path);
if (list == null) {
return null;
}
List<Long> result = new ArrayList();
List<Long> result = new ArrayList<Long>();
for (Object object : list) {
if (object instanceof Long) {
result.add((Long)object);
result.add((Long) object);
} else if (object instanceof String) {
try {
result.add(Long.valueOf((String)object));
} catch (Exception ex) {}
result.add(Long.valueOf((String) object));
} catch (Exception ex) {
}
} else if (object instanceof Byte) {
result.add((Long)(long)(byte)(Byte)object);
result.add((Long) (long) (byte) (Byte) object);
} else if (object instanceof Character) {
result.add((Long)(long)(char)(Character)object);
result.add((Long) (long) (char) (Character) object);
} else if (object instanceof Short) {
result.add((Long)(long)(short)(Short)object);
result.add((Long) (long) (short) (Short) object);
} else if (object instanceof Integer) {
result.add((Long)(long)(int)(Integer)object);
result.add((Long) (long) (int) (Integer) object);
} else if (object instanceof Long) {
result.add((Long)(long)(long)(Long)object);
result.add((Long) (long) (long) (Long) object);
} else if (object instanceof Float) {
result.add((Long)(long)(float)(Float)object);
result.add((Long) (long) (float) (Float) object);
} else if (object instanceof Double) {
result.add((Long)(long)(double)(Double)object);
result.add((Long) (long) (double) (Double) object);
}
}
return result;
}
@@ -662,37 +664,38 @@ public class MemorySection implements ConfigurationSection {
}
List<Object> list = getList(path);
if (list == null) {
return null;
}
List<Byte> result = new ArrayList();
List<Byte> result = new ArrayList<Byte>();
for (Object object : list) {
if (object instanceof Byte) {
result.add((Byte)object);
result.add((Byte) object);
} else if (object instanceof String) {
try {
result.add(Byte.valueOf((String)object));
} catch (Exception ex) {}
result.add(Byte.valueOf((String) object));
} catch (Exception ex) {
}
} else if (object instanceof Byte) {
result.add((Byte)(byte)(byte)(Byte)object);
result.add((Byte) (byte) (byte) (Byte) object);
} else if (object instanceof Character) {
result.add((Byte)(byte)(char)(Character)object);
result.add((Byte) (byte) (char) (Character) object);
} else if (object instanceof Short) {
result.add((Byte)(byte)(short)(Short)object);
result.add((Byte) (byte) (short) (Short) object);
} else if (object instanceof Integer) {
result.add((Byte)(byte)(int)(Integer)object);
result.add((Byte) (byte) (int) (Integer) object);
} else if (object instanceof Long) {
result.add((Byte)(byte)(long)(Long)object);
result.add((Byte) (byte) (long) (Long) object);
} else if (object instanceof Float) {
result.add((Byte)(byte)(float)(Float)object);
result.add((Byte) (byte) (float) (Float) object);
} else if (object instanceof Double) {
result.add((Byte)(byte)(double)(Double)object);
result.add((Byte) (byte) (double) (Double) object);
}
}
return result;
}
@@ -702,39 +705,39 @@ public class MemorySection implements ConfigurationSection {
}
List<Object> list = getList(path);
if (list == null) {
return null;
}
List<Character> result = new ArrayList();
List<Character> result = new ArrayList<Character>();
for (Object object : list) {
if (object instanceof Character) {
result.add((Character)object);
result.add((Character) object);
} else if (object instanceof String) {
String str = (String)object;
String str = (String) object;
if (str.length() == 1) {
result.add(str.charAt(0));
}
} else if (object instanceof Byte) {
result.add((Character)(char)(byte)(Byte)object);
result.add((Character) (char) (byte) (Byte) object);
} else if (object instanceof Character) {
result.add((Character)(char)(char)(Character)object);
result.add((Character) (char) (char) (Character) object);
} else if (object instanceof Short) {
result.add((Character)(char)(short)(Short)object);
result.add((Character) (char) (short) (Short) object);
} else if (object instanceof Integer) {
result.add((Character)(char)(int)(Integer)object);
result.add((Character) (char) (int) (Integer) object);
} else if (object instanceof Long) {
result.add((Character)(char)(long)(Long)object);
result.add((Character) (char) (long) (Long) object);
} else if (object instanceof Float) {
result.add((Character)(char)(float)(Float)object);
result.add((Character) (char) (float) (Float) object);
} else if (object instanceof Double) {
result.add((Character)(char)(double)(Double)object);
result.add((Character) (char) (double) (Double) object);
}
}
return result;
}
@@ -744,65 +747,67 @@ public class MemorySection implements ConfigurationSection {
}
List<Object> list = getList(path);
if (list == null) {
return null;
}
List<Short> result = new ArrayList();
List<Short> result = new ArrayList<Short>();
for (Object object : list) {
if (object instanceof Short) {
result.add((Short)object);
result.add((Short) object);
} else if (object instanceof String) {
try {
result.add(Short.valueOf((String)object));
} catch (Exception ex) {}
result.add(Short.valueOf((String) object));
} catch (Exception ex) {
}
} else if (object instanceof Byte) {
result.add((Short)(short)(byte)(Byte)object);
result.add((Short) (short) (byte) (Byte) object);
} else if (object instanceof Character) {
result.add((Short)(short)(char)(Character)object);
result.add((Short) (short) (char) (Character) object);
} else if (object instanceof Short) {
result.add((Short)(short)(short)(Short)object);
result.add((Short) (short) (short) (Short) object);
} else if (object instanceof Integer) {
result.add((Short)(short)(int)(Integer)object);
result.add((Short) (short) (int) (Integer) object);
} else if (object instanceof Long) {
result.add((Short)(short)(long)(Long)object);
result.add((Short) (short) (long) (Long) object);
} else if (object instanceof Float) {
result.add((Short)(short)(float)(Float)object);
result.add((Short) (short) (float) (Float) object);
} else if (object instanceof Double) {
result.add((Short)(short)(double)(Double)object);
result.add((Short) (short) (double) (Double) object);
}
}
return result;
}
@SuppressWarnings("unchecked")
public List<Map<String, Object>> getMapList(String path) {
if (path == null) {
throw new IllegalArgumentException("Path cannot be null");
}
List<Object> list = getList(path);
List<Map<String, Object>> result = new ArrayList();
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
for (Object object : list) {
if (object instanceof Map) {
result.add((Map<String, Object>)object);
result.add((Map<String, Object>) object);
}
}
return result;
}
// Bukkit
// Bukkit
public Vector getVector(String path) {
if (path == null) {
throw new IllegalArgumentException("Path cannot be null");
}
Object def = getDefault(path);
return getVector(path, (def instanceof Vector) ? (Vector)def : null);
return getVector(path, (def instanceof Vector) ? (Vector) def : null);
}
public Vector getVector(String path, Vector def) {
@@ -811,7 +816,7 @@ public class MemorySection implements ConfigurationSection {
}
Object val = get(path, def);
return (val instanceof Vector) ? (Vector)val : def;
return (val instanceof Vector) ? (Vector) val : def;
}
public boolean isVector(String path) {
@@ -829,7 +834,7 @@ public class MemorySection implements ConfigurationSection {
}
Object def = getDefault(path);
return getOfflinePlayer(path, (def instanceof OfflinePlayer) ? (OfflinePlayer)def : null);
return getOfflinePlayer(path, (def instanceof OfflinePlayer) ? (OfflinePlayer) def : null);
}
public OfflinePlayer getOfflinePlayer(String path, OfflinePlayer def) {
@@ -838,7 +843,7 @@ public class MemorySection implements ConfigurationSection {
}
Object val = get(path, def);
return (val instanceof OfflinePlayer) ? (OfflinePlayer)val : def;
return (val instanceof OfflinePlayer) ? (OfflinePlayer) val : def;
}
public boolean isOfflinePlayer(String path) {
@@ -856,7 +861,7 @@ public class MemorySection implements ConfigurationSection {
}
Object def = getDefault(path);
return getItemStack(path, (def instanceof ItemStack) ? (ItemStack)def : null);
return getItemStack(path, (def instanceof ItemStack) ? (ItemStack) def : null);
}
public ItemStack getItemStack(String path, ItemStack def) {
@@ -865,7 +870,7 @@ public class MemorySection implements ConfigurationSection {
}
Object val = get(path, def);
return (val instanceof ItemStack) ? (ItemStack)val : def;
return (val instanceof ItemStack) ? (ItemStack) val : def;
}
public boolean isItemStack(String path) {
@@ -881,11 +886,12 @@ public class MemorySection implements ConfigurationSection {
if (path == null) {
throw new IllegalArgumentException("Path cannot be null");
}
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;
}
@@ -903,7 +909,7 @@ public class MemorySection implements ConfigurationSection {
if (input == null) {
throw new IllegalArgumentException("Cannot store null");
}
if (isPrimitiveWrapper(input) || isNaturallyStorable(input)) {
return input;
} else if (input instanceof ConfigurationSerializable) {
@@ -912,14 +918,14 @@ public class MemorySection implements ConfigurationSection {
throw new IllegalArgumentException("Cannot store " + input + " into " + this + ", unsupported class");
}
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 isNaturallyStorable(Object input) {
return input instanceof List || input instanceof Iterable ||
input instanceof String || input instanceof File ||
@@ -937,13 +943,13 @@ public class MemorySection implements ConfigurationSection {
protected void mapChildrenKeys(Set<String> output, ConfigurationSection section, boolean deep) {
if (section instanceof MemorySection) {
MemorySection sec = (MemorySection)section;
MemorySection sec = (MemorySection) section;
for (Map.Entry<String, Object> entry : sec.map.entrySet()) {
output.add(createPath(section, entry.getKey(), this));
if ((deep) && (entry.getValue() instanceof ConfigurationSection)) {
ConfigurationSection subsection = (ConfigurationSection)entry.getValue();
ConfigurationSection subsection = (ConfigurationSection) entry.getValue();
mapChildrenKeys(output, subsection, deep);
}
}
@@ -958,14 +964,14 @@ public class MemorySection implements ConfigurationSection {
protected void mapChildrenValues(Map<String, Object> output, ConfigurationSection section, boolean deep) {
if (section instanceof MemorySection) {
MemorySection sec = (MemorySection)section;
MemorySection sec = (MemorySection) section;
for (Map.Entry<String, Object> entry : sec.map.entrySet()) {
output.put(createPath(section, entry.getKey(), this), entry.getValue());
if (entry.getValue() instanceof ConfigurationSection) {
if (deep) {
mapChildrenValues(output, (ConfigurationSection)entry.getValue(), deep);
mapChildrenValues(output, (ConfigurationSection) entry.getValue(), deep);
}
}
}
@@ -982,7 +988,7 @@ public class MemorySection implements ConfigurationSection {
* Creates a full path to the given {@link ConfigurationSection} from its root {@link Configuration}.
* <p>
* You may use this method for any given {@link ConfigurationSection}, not only {@link MemorySection}.
*
*
* @param section Section to create a path for.
* @param key Name of the specified section.
* @return Full path of the section from its root.
@@ -991,12 +997,11 @@ public class MemorySection implements ConfigurationSection {
return createPath(section, key, (section == null) ? null : section.getRoot());
}
/**
* Creates a relative path to the given {@link ConfigurationSection} from the given relative section.
* <p>
* You may use this method for any given {@link ConfigurationSection}, not only {@link MemorySection}.
*
*
* @param section Section to create a path for.
* @param key Name of the specified section.
* @param relativeTo Section to create the path relative to.
@@ -1022,21 +1027,21 @@ public class MemorySection implements ConfigurationSection {
builder.append(key);
}
return builder.toString();
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName());
builder.append("[path='");
builder.append(getCurrentPath());
builder.append("', root='");
builder.append(root.getClass().getSimpleName());
builder.append("']");
return builder.toString();
}
}

View File

@@ -48,7 +48,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
if (file == null) {
throw new IllegalArgumentException("File cannot be null");
}
Files.createParentDirs(file);
String data = saveToString();
@@ -76,7 +76,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
if (file == null) {
throw new IllegalArgumentException("File cannot be null");
}
save(new File(file));
}
@@ -108,7 +108,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
load(new FileInputStream(file));
}
/**
* Loads this {@link FileConfiguration} from the specified stream.
* <p>
@@ -124,7 +124,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
if (stream == null) {
throw new IllegalArgumentException("Stream cannot be null");
}
InputStreamReader reader = new InputStreamReader(stream);
StringBuilder builder = new StringBuilder();
BufferedReader input = new BufferedReader(reader);
@@ -178,13 +178,13 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* @throws IllegalArgumentException Thrown if contents is null.
*/
public abstract void loadFromString(String contents) throws InvalidConfigurationException;
/**
* Compiles the header for this {@link FileConfiguration} and returns the result.
* <p>
* This will use the header from {@link #options()} -> {@link FileConfigurationOptions#header()},
* respecting the rules of {@link FileConfigurationOptions#copyHeader()} if set.
*
*
* @return Compiled header
*/
protected abstract String buildHeader();
@@ -194,7 +194,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
if (options == null) {
options = new FileConfigurationOptions(this);
}
return (FileConfigurationOptions)options;
return (FileConfigurationOptions) options;
}
}

View File

@@ -8,14 +8,14 @@ import org.bukkit.configuration.*;
public class FileConfigurationOptions extends MemoryConfigurationOptions {
private String header = null;
private boolean copyHeader = true;
protected FileConfigurationOptions(MemoryConfiguration configuration) {
super(configuration);
}
@Override
public FileConfiguration configuration() {
return (FileConfiguration)super.configuration();
return (FileConfiguration) super.configuration();
}
@Override
@@ -29,7 +29,7 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
super.pathSeparator(value);
return this;
}
/**
* Gets the header that will be applied to the top of the saved output.
* <p>
@@ -40,13 +40,13 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
* <p>
* Null is a valid value which will indicate that no header is to be applied.
* The default value is null.
*
*
* @return Header
*/
public String header() {
return header;
}
/**
* Sets the header that will be applied to the top of the saved output.
* <p>
@@ -56,8 +56,8 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
* but you may include one if you wish for extra spacing.
* <p>
* Null is a valid value which will indicate that no header is to be applied.
* The default value is null.
*
*
* @param value New header
* @return This object, for chaining
*/
@@ -65,7 +65,7 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
this.header = value;
return this;
}
/**
* Gets whether or not the header should be copied from a default source.
* <p>
@@ -78,13 +78,13 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
* specified in this configuration will be used.
* <p>
* Defaults to true.
*
*
* @return Whether or not to copy the header
*/
public boolean copyHeader() {
return copyHeader;
}
/**
* Sets whether or not the header should be copied from a default source.
* <p>
@@ -97,13 +97,13 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
* specified in this configuration will be used.
* <p>
* Defaults to true.
*
*
* @param value Whether or not to copy the header
* @return This object, for chaining
*/
public FileConfigurationOptions copyHeader(boolean value) {
copyHeader = value;
return this;
}
}

View File

@@ -4,14 +4,14 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.yaml.snakeyaml.DumperOptions;
@@ -33,20 +33,20 @@ public class YamlConfiguration extends FileConfiguration {
@Override
public String saveToString() {
Map<String, Object> output = new LinkedHashMap<String, Object>();
yamlOptions.setIndent(options().indent());
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
serializeValues(output, getValues(false));
String header = buildHeader();
String dump = yaml.dump(output);
if (dump.equals(BLANK_CONFIG)) {
dump = "";
}
return header + dump;
}
@@ -55,45 +55,47 @@ public class YamlConfiguration extends FileConfiguration {
if (contents == null) {
throw new IllegalArgumentException("Contents cannot be null");
}
Map<Object, Object> input = (Map<Object, Object>)yaml.load(contents);
@SuppressWarnings("unchecked")
Map<Object, Object> input = (Map<Object, Object>) yaml.load(contents);
int size = (input == null) ? 0 : input.size();
Map<String, Object> result = new LinkedHashMap<String, Object>(size);
if (size > 0) {
for (Map.Entry<Object, Object> entry : input.entrySet()) {
result.put(entry.getKey().toString(), entry.getValue());
}
}
String header = parseHeader(contents);
if (header.length() > 0) {
options().header(header);
}
deserializeValues(result, this);
}
protected void deserializeValues(Map<String, Object> input, ConfigurationSection section) throws InvalidConfigurationException {
if (input == null) {
return;
}
for (Map.Entry<String, Object> entry : input.entrySet()) {
Object value = entry.getValue();
if (value instanceof Map) {
Map<Object, Object> subinput = (Map<Object, Object>)value;
@SuppressWarnings("unchecked")
Map<Object, Object> subinput = (Map<Object, Object>) value;
int size = (subinput == null) ? 0 : subinput.size();
Map<String, Object> subvalues = new LinkedHashMap<String, Object>(size);
if (size > 0) {
for (Map.Entry<Object, Object> subentry : subinput.entrySet()) {
subvalues.put(subentry.getKey().toString(), subentry.getValue());
}
}
if (subvalues.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
try {
ConfigurationSerializable serializable = ConfigurationSerialization.deserializeObject(subvalues);
@@ -110,51 +112,51 @@ public class YamlConfiguration extends FileConfiguration {
}
}
}
protected void serializeValues(Map<String, Object> output, Map<String, Object> input) {
if (input == null) {
return;
}
for (Map.Entry<String, Object> entry : input.entrySet()) {
Object value = entry.getValue();
if (value instanceof ConfigurationSection) {
ConfigurationSection subsection = (ConfigurationSection)entry.getValue();
ConfigurationSection subsection = (ConfigurationSection) entry.getValue();
Map<String, Object> subvalues = new LinkedHashMap<String, Object>();
serializeValues(subvalues, subsection.getValues(false));
value = subvalues;
} else if (value instanceof ConfigurationSerializable) {
ConfigurationSerializable serializable = (ConfigurationSerializable)value;
ConfigurationSerializable serializable = (ConfigurationSerializable) value;
Map<String, Object> subvalues = new LinkedHashMap<String, Object>();
subvalues.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
serializeValues(subvalues, serializable.serialize());
value = subvalues;
} else if ((!isPrimitiveWrapper(value)) && (!isNaturallyStorable(value))) {
throw new IllegalStateException("Configuration contains non-serializable values, cannot process");
}
if (value != null) {
output.put(entry.getKey(), value);
}
}
}
protected String parseHeader(String input) {
String[] lines = input.split("\r?\n", -1);
StringBuilder result = new StringBuilder();
boolean readingHeader = true;
for (int i = 0; (i < lines.length) && (readingHeader); i++) {
String line = lines[i];
if (line.startsWith(COMMENT_PREFIX)) {
if (i > 0) {
result.append("\n");
}
if (line.length() > COMMENT_PREFIX.length()) {
result.append(line.substring(COMMENT_PREFIX.length()));
}
@@ -164,44 +166,45 @@ public class YamlConfiguration extends FileConfiguration {
readingHeader = false;
}
}
return result.toString();
}
@Override
protected String buildHeader() {
String header = options().header();
if (options().copyHeader()) {
Configuration def = getDefaults();
if ((def != null) && (def instanceof FileConfiguration)) {
FileConfiguration filedefaults = (FileConfiguration)def;
FileConfiguration filedefaults = (FileConfiguration) def;
String defaultsHeader = filedefaults.buildHeader();
if ((defaultsHeader != null) && (defaultsHeader.length() > 0)) {
return defaultsHeader;
}
}
}
if (header == null) {
return "";
}
StringBuilder builder = new StringBuilder();
String[] lines = header.split("\r?\n", -1);
boolean startedHeader = false;
for (int i = lines.length - 1; i >= 0; i--) {
builder.insert(0, "\n");
if ((startedHeader) || (lines[i].length() != 0)) {
builder.insert(0, lines[i]);
builder.insert(0, COMMENT_PREFIX);
startedHeader = true;
}
}
return builder.toString();
}
@@ -210,16 +213,16 @@ public class YamlConfiguration extends FileConfiguration {
if (options == null) {
options = new YamlConfigurationOptions(this);
}
return (YamlConfigurationOptions)options;
return (YamlConfigurationOptions) options;
}
/**
* Creates a new {@link YamlConfiguration}, loading from the given file.
* <p>
* Any errors loading the Configuration will be logged and then ignored.
* If the specified input is not a valid config, a blank config will be returned.
*
*
* @param file Input file
* @return Resulting configuration
* @throws IllegalArgumentException Thrown is file is null
@@ -228,9 +231,9 @@ public class YamlConfiguration extends FileConfiguration {
if (file == null) {
throw new IllegalArgumentException("File cannot be null");
}
YamlConfiguration config = new YamlConfiguration();
try {
config.load(file);
} catch (FileNotFoundException ex) {
@@ -245,16 +248,16 @@ public class YamlConfiguration extends FileConfiguration {
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file + ": " + ex.getCause().getClass(), ex);
}
}
return config;
}
/**
* Creates a new {@link YamlConfiguration}, loading from the given stream.
* <p>
* Any errors loading the Configuration will be logged and then ignored.
* If the specified input is not a valid config, a blank config will be returned.
*
*
* @param stream Input stream
* @return Resulting configuration
* @throws IllegalArgumentException Thrown is stream is null
@@ -263,9 +266,9 @@ public class YamlConfiguration extends FileConfiguration {
if (stream == null) {
throw new IllegalArgumentException("Stream cannot be null");
}
YamlConfiguration config = new YamlConfiguration();
try {
config.load(stream);
} catch (IOException ex) {
@@ -279,7 +282,7 @@ public class YamlConfiguration extends FileConfiguration {
Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration: " + ex.getCause().getClass(), ex);
}
}
return config;
}
}

View File

@@ -5,14 +5,14 @@ package org.bukkit.configuration.file;
*/
public class YamlConfigurationOptions extends FileConfigurationOptions {
private int indent = 2;
protected YamlConfigurationOptions(YamlConfiguration configuration) {
super(configuration);
}
@Override
public YamlConfiguration configuration() {
return (YamlConfiguration)super.configuration();
return (YamlConfiguration) super.configuration();
}
@Override
@@ -38,23 +38,23 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
super.copyHeader(value);
return this;
}
/**
* Gets how much spaces should be used to indent each line.
* <p>
* The minimum value this may be is 2, and the maximum is 9.
*
*
* @return How much to indent by
*/
public int indent() {
return indent;
}
/**
* Sets how much spaces should be used to indent each line.
* <p>
* The minimum value this may be is 2, and the maximum is 9.
*
*
* @param value New indent
* @return This object, for chaining
*/
@@ -62,7 +62,7 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
if ((indent < 2) || (value > 9)) {
throw new IllegalArgumentException("Indent must be between 1 and 10 characters");
}
this.indent = value;
return this;
}

View File

@@ -7,9 +7,11 @@ import java.util.Map;
* <p>
* These objects MUST implement one of the following, in addition to the methods
* as defined by this interface:
* - A static method "deserialize" that accepts a single {@link Map<String, Object>} and returns the class.
* - A static method "valueOf" that accepts a single {@link Map<String, Object>} and returns the class.
* - A constructor that accepts a single {@link Map<String, Object>}.
* <ul>
* <li>A static method "deserialize" that accepts a single {@link Map<String, Object>} and returns the class.</li>
* <li>A static method "valueOf" that accepts a single {@link Map<String, Object>} and returns the class.</li>
* <li>A constructor that accepts a single {@link Map<String, Object>}.</li>
* </ul>
*/
public interface ConfigurationSerializable {
/**
@@ -17,7 +19,7 @@ public interface ConfigurationSerializable {
* <p>
* This class must provide a method to restore this class, as defined in the
* {@link ConfigurationSerializable} interface javadocs.
*
*
* @return Map containing the current state of this class
*/
public Map<String, Object> serialize();

View File

@@ -17,27 +17,27 @@ public class ConfigurationSerialization {
public static final String SERIALIZED_TYPE_KEY = "==";
private final Class<? extends ConfigurationSerializable> clazz;
private static Map<String, Class<? extends ConfigurationSerializable>> aliases = new HashMap<String, Class<? extends ConfigurationSerializable>>();
static {
registerClass(Vector.class);
registerClass(BlockVector.class);
}
protected ConfigurationSerialization(Class<? extends ConfigurationSerializable> clazz) {
this.clazz = clazz;
}
protected Method getMethod(String name, boolean isStatic) {
try {
Method method = clazz.getDeclaredMethod(name, Map.class);
if (!ConfigurationSerializable.class.isAssignableFrom(method.getReturnType())) {
return null;
}
if (Modifier.isStatic(method.getModifiers()) != isStatic) {
return null;
}
return method;
} catch (NoSuchMethodException ex) {
return null;
@@ -45,7 +45,7 @@ public class ConfigurationSerialization {
return null;
}
}
protected Constructor<? extends ConfigurationSerializable> getConstructor() {
try {
return clazz.getConstructor(Map.class);
@@ -55,11 +55,11 @@ public class ConfigurationSerialization {
return null;
}
}
protected ConfigurationSerializable deserializeViaMethod(Method method, Map<String, Object> args) {
try {
ConfigurationSerializable result = (ConfigurationSerializable)method.invoke(null, args);
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 {
@@ -68,55 +68,55 @@ public class ConfigurationSerialization {
} catch (Throwable ex) {
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE, "Could not call method '" + method.toString() + "' of " + clazz + " for deserialization", ex);
}
return null;
}
protected ConfigurationSerializable deserializeViaCtor(Constructor<? extends ConfigurationSerializable> ctor, Map<String, Object> args) {
try {
return ctor.newInstance(args);
} catch (Throwable ex) {
Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE, "Could not call constructor '" + ctor.toString() + "' of " + clazz + " for deserialization", ex);
}
return null;
}
public ConfigurationSerializable deserialize(Map<String, Object> args) {
if (args == null) {
throw new IllegalArgumentException("Args must not be null");
}
ConfigurationSerializable result = null;
Method method = null;
if (result == null) {
method = getMethod("deserialize", true);
if (method != null) {
result = deserializeViaMethod(method, args);
}
}
if (result == null) {
method = getMethod("valueOf", true);
if (method != null) {
result = deserializeViaMethod(method, args);
}
}
if (result == null) {
Constructor<? extends ConfigurationSerializable> constructor = getConstructor();
if (constructor != null) {
result = deserializeViaCtor(constructor, args);
}
}
return result;
}
/**
* Attempts to deserialize the given arguments into a new instance of the given class.
* <p>
@@ -125,7 +125,7 @@ public class ConfigurationSerialization {
* <p>
* If a new instance could not be made, an example being the class not fully implementing
* the interface, null will be returned.
*
*
* @param args Arguments for deserialization
* @param clazz Class to deserialize into
* @return New instance of the specified class
@@ -133,7 +133,7 @@ public class ConfigurationSerialization {
public static ConfigurationSerializable deserializeObject(Map<String, Object> args, Class<? extends ConfigurationSerializable> clazz) {
return new ConfigurationSerialization(clazz).deserialize(args);
}
/**
* Attempts to deserialize the given arguments into a new instance of the given class.
* <p>
@@ -142,17 +142,17 @@ public class ConfigurationSerialization {
* <p>
* If a new instance could not be made, an example being the class not fully implementing
* the interface, null will be returned.
*
*
* @param args Arguments for deserialization
* @return New instance of the specified class
*/
public static ConfigurationSerializable deserializeObject(Map<String, Object> args) {
Class<? extends ConfigurationSerializable> clazz = null;
if (args.containsKey(SERIALIZED_TYPE_KEY)) {
try {
String alias = (String)args.get(SERIALIZED_TYPE_KEY);
String alias = (String) args.get(SERIALIZED_TYPE_KEY);
if (alias == null) {
throw new IllegalArgumentException("Specified class does not exist ('" + alias + ")'");
} else {
@@ -165,71 +165,73 @@ public class ConfigurationSerialization {
} else {
throw new IllegalArgumentException("Args doesn't contain type key ('" + SERIALIZED_TYPE_KEY + "')");
}
return new ConfigurationSerialization(clazz).deserialize(args);
}
/**
* Registers the given {@link ConfigurationSerializable} class by its alias
*
*
* @param clazz Class to register
*/
public static void registerClass(Class<? extends ConfigurationSerializable> clazz) {
DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
if (delegate == null ) {
if (delegate == null) {
registerClass(clazz, getAlias(clazz));
registerClass(clazz, clazz.getName());
}
}
/**
* Registers the given alias to the specified {@link ConfigurationSerializable} class
*
*
* @param clazz Class to register
* @param alias Alias to register as
*/
public static void registerClass(Class<? extends ConfigurationSerializable> clazz, String alias) {
aliases.put(alias, clazz);
}
/**
* Unregisters the specified alias to a {@link ConfigurationSerializable}
*
*
* @param alias Alias to unregister
*/
public static void unregisterClass(String alias) {
aliases.remove(alias);
}
/**
* Unregisters any aliases for the specified {@link ConfigurationSerializable} class
*
*
* @param clazz Class to unregister
*/
public static void unregisterClass(Class<? extends ConfigurationSerializable> clazz) {
while (aliases.values().remove(clazz));
while (aliases.values().remove(clazz)) {
;
}
}
/**
* Attempts to get a registered {@link ConfigurationSerializable} class by its alias
*
*
* @param alias Alias of the serializable
* @return Registered class, or null if not found
*/
public static Class<? extends ConfigurationSerializable> getClassByAlias(String alias) {
return aliases.get(alias);
}
/**
* Gets the correct alias for the given {@link ConfigurationSerializable} class
*
*
* @param clazz Class to get alias for
* @return Alias to use for the class
*/
public static String getAlias(Class<? extends ConfigurationSerializable> clazz) {
DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);
if (delegate != null) {
if ((delegate.value() == null) || (delegate.value() == clazz)) {
delegate = null;
@@ -237,7 +239,7 @@ public class ConfigurationSerialization {
return getAlias(delegate.value());
}
}
if (delegate == null) {
SerializableAs alias = clazz.getAnnotation(SerializableAs.class);
@@ -245,7 +247,7 @@ public class ConfigurationSerialization {
return alias.value();
}
}
return clazz.getName();
}
}

View File

@@ -14,7 +14,7 @@ import java.lang.annotation.Target;
public @interface DelegateDeserialization {
/**
* Which class should be used as a delegate for this classes deserialization
*
*
* @return Delegate class
*/
public Class<? extends ConfigurationSerializable> value();

View File

@@ -21,7 +21,7 @@ public @interface SerializableAs {
* <p>
* This name MUST be unique. We recommend using names such as "MyPluginThing" instead of
* "Thing".
*
*
* @return Name to serialize the class as.
*/
public String value();