Refactored and fixed several config related things (javadocs, and warnings)
This commit is contained in:
@@ -2,7 +2,7 @@ package com.seibel.distanthorizons.core.config;
|
||||
|
||||
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
|
||||
|
||||
// TODO: Make this intergrate with the config system
|
||||
// TODO: Make this integrate with the config system
|
||||
public class AppliedConfigState<T>
|
||||
{
|
||||
final ConfigEntry<T> entry;
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.*;
|
||||
// Init the config after singletons have been blinded
|
||||
public class ConfigBase
|
||||
{
|
||||
/** Our own config instance, don't modify */
|
||||
/** Our own config instance, don't modify unless you are the DH mod */
|
||||
public static ConfigBase INSTANCE;
|
||||
public ConfigFileHandling configFileINSTANCE;
|
||||
|
||||
@@ -31,24 +31,27 @@ public class ConfigBase
|
||||
public final String modName;
|
||||
public final int configVersion;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* What the config works with
|
||||
*
|
||||
* Enum
|
||||
* Boolean
|
||||
* Byte
|
||||
* Integer
|
||||
* Double
|
||||
* Short
|
||||
* Long
|
||||
* Float
|
||||
* String
|
||||
*
|
||||
* // Below, "T" should be a value from above
|
||||
* List<T>
|
||||
* ArrayList<T>
|
||||
* Map<String, T>
|
||||
* HashMap<String, T>
|
||||
* What the config works with
|
||||
* <br>
|
||||
* <br> {@link Enum}
|
||||
* <br> {@link Boolean}
|
||||
* <br> {@link Byte}
|
||||
* <br> {@link Integer}
|
||||
* <br> {@link Double}
|
||||
* <br> {@link Short}
|
||||
* <br> {@link Long}
|
||||
* <br> {@link Float}
|
||||
* <br> {@link String}
|
||||
* <br>
|
||||
* <br> // Below, "T" should be a value from above
|
||||
* <br> // Note: This is not checked, so we trust that you are doing the right thing
|
||||
* <br> List<T>
|
||||
* <br> ArrayList<T>
|
||||
* <br> Map<String, T>
|
||||
* <br> HashMap<String, T>
|
||||
*/
|
||||
public static final List<Class<?>> acceptableInputs = new ArrayList<Class<?>>()
|
||||
{{
|
||||
@@ -102,7 +105,7 @@ public class ConfigBase
|
||||
}
|
||||
catch (IllegalAccessException exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
LOGGER.warn(exception);
|
||||
}
|
||||
|
||||
AbstractConfigType<?, ?> entry = entries.get(entries.size() - 1);
|
||||
@@ -151,10 +154,11 @@ public class ConfigBase
|
||||
* @param checkEnums Checks if all the lang for the enum's exist
|
||||
*/
|
||||
// This is just to re-format the lang or check if there is something in the lang that is missing
|
||||
@SuppressWarnings("unchecked")
|
||||
public String generateLang(boolean onlyShowNew, boolean checkEnums)
|
||||
{
|
||||
ILangWrapper langWrapper = SingletonInjector.INSTANCE.get(ILangWrapper.class);
|
||||
List<Class<? extends Enum>> enumList = new ArrayList<>();
|
||||
List<Class<? extends Enum<?>>> enumList = new ArrayList<>();
|
||||
|
||||
String generatedLang = "";
|
||||
|
||||
@@ -168,7 +172,7 @@ public class ConfigBase
|
||||
|
||||
if (checkEnums && entry.getType().isEnum() && !enumList.contains(entry.getType()))
|
||||
{ // Put it in an enum list to work with at the end
|
||||
enumList.add((Class<? extends Enum>) entry.getType());
|
||||
enumList.add((Class<? extends Enum<?>>) entry.getType());
|
||||
}
|
||||
if (!onlyShowNew || langWrapper.langExists(entryPrefix))
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.Map;
|
||||
public class NumberUtil
|
||||
{
|
||||
// Is there no better way of doing this?
|
||||
public static Map<Class, Number> minValues = new HashMap<Class, Number>()
|
||||
public static Map<Class<?>, Number> minValues = new HashMap<Class<?>, Number>()
|
||||
{{
|
||||
put(Byte.class, Byte.MIN_VALUE);
|
||||
put(Short.class, Short.MIN_VALUE);
|
||||
@@ -22,7 +22,7 @@ public class NumberUtil
|
||||
put(Double.class, Double.MIN_VALUE);
|
||||
put(Float.class, Float.MIN_VALUE);
|
||||
}};
|
||||
public static Map<Class, Number> maxValues = new HashMap<Class, Number>()
|
||||
public static Map<Class<?>, Number> maxValues = new HashMap<Class<?>, Number>()
|
||||
{{
|
||||
put(Byte.class, Byte.MAX_VALUE);
|
||||
put(Short.class, Short.MAX_VALUE);
|
||||
@@ -32,11 +32,11 @@ public class NumberUtil
|
||||
put(Float.class, Float.MAX_VALUE);
|
||||
}};
|
||||
|
||||
public static Number getMinimum(Class c)
|
||||
public static Number getMinimum(Class<?> c)
|
||||
{
|
||||
return minValues.get(c);
|
||||
}
|
||||
public static Number getMaximum(Class c)
|
||||
public static Number getMaximum(Class<?> c)
|
||||
{
|
||||
return maxValues.get(c);
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class NumberUtil
|
||||
{
|
||||
if (a.getClass() != b.getClass())
|
||||
return false;
|
||||
Class typeClass = a.getClass();
|
||||
Class<?> typeClass = a.getClass();
|
||||
|
||||
if (typeClass == Byte.class) return a.byteValue() > b.byteValue();
|
||||
if (typeClass == Short.class) return a.shortValue() > b.shortValue();
|
||||
@@ -62,7 +62,7 @@ public class NumberUtil
|
||||
{
|
||||
if (a.getClass() != b.getClass())
|
||||
return false;
|
||||
Class typeClass = a.getClass();
|
||||
Class<?> typeClass = a.getClass();
|
||||
|
||||
if (typeClass == Byte.class) return a.byteValue() < b.byteValue();
|
||||
if (typeClass == Short.class) return a.shortValue() < b.shortValue();
|
||||
|
||||
+3
-1
@@ -116,9 +116,11 @@ public class ConfigTypeConverters
|
||||
Map<String, Object> mapObject = (Map<String, Object>) item;
|
||||
Config jsonObject = Config.inMemory();
|
||||
|
||||
Object[] keyArray = mapObject.keySet().toArray();
|
||||
|
||||
for (int i = 0; i < mapObject.size(); i++)
|
||||
{
|
||||
jsonObject.add(mapObject.keySet().toArray()[i].toString(), mapObject.get(mapObject.keySet().toArray()[i]));
|
||||
jsonObject.add(keyArray[i].toString(), mapObject.get(keyArray[i]));
|
||||
}
|
||||
|
||||
return JsonFormat.minimalInstance().createWriter().writeToString(jsonObject);
|
||||
|
||||
+4
-1
@@ -8,8 +8,9 @@ import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance
|
||||
*
|
||||
* @author coolGi
|
||||
*/
|
||||
// Note for devs: The "S" is the class that is extending this
|
||||
public abstract class AbstractConfigType<T, S>
|
||||
{ // The S is the class that is extending this
|
||||
{
|
||||
public String category = ""; // This should only be set once in the init
|
||||
public String name; // This should only be set once in the init
|
||||
protected T value;
|
||||
@@ -74,11 +75,13 @@ public abstract class AbstractConfigType<T, S>
|
||||
|
||||
|
||||
// Put this into your own builder
|
||||
@SuppressWarnings("unchecked")
|
||||
public S setAppearance(EConfigEntryAppearance newAppearance)
|
||||
{
|
||||
this.tmpAppearance = newAppearance;
|
||||
return (S) this;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public S set(T newValue)
|
||||
{
|
||||
this.tmpValue = newValue;
|
||||
|
||||
@@ -8,12 +8,12 @@ import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance
|
||||
*
|
||||
* @author coolGi
|
||||
*/
|
||||
public class ConfigCategory extends AbstractConfigType<Class, ConfigCategory>
|
||||
public class ConfigCategory extends AbstractConfigType<Class<?>, ConfigCategory>
|
||||
{
|
||||
/** This should not be set by anything other than the config system itself */
|
||||
public String destination; // Where the category goes to
|
||||
|
||||
private ConfigCategory(EConfigEntryAppearance appearance, Class value, String destination)
|
||||
private ConfigCategory(EConfigEntryAppearance appearance, Class<?> value, String destination)
|
||||
{
|
||||
super(appearance, value);
|
||||
this.destination = destination;
|
||||
@@ -32,7 +32,7 @@ public class ConfigCategory extends AbstractConfigType<Class, ConfigCategory>
|
||||
return value;
|
||||
}
|
||||
|
||||
public static class Builder extends AbstractConfigType.Builder<Class, Builder>
|
||||
public static class Builder extends AbstractConfigType.Builder<Class<?>, Builder>
|
||||
{
|
||||
private String tmpDestination = null;
|
||||
|
||||
|
||||
+4
-4
@@ -8,9 +8,9 @@ import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance
|
||||
*
|
||||
* @author coolGi
|
||||
*/
|
||||
public class ConfigLinkedEntry extends AbstractConfigType<AbstractConfigType, ConfigLinkedEntry>
|
||||
public class ConfigLinkedEntry extends AbstractConfigType<AbstractConfigType<?, ?>, ConfigLinkedEntry>
|
||||
{
|
||||
public ConfigLinkedEntry(AbstractConfigType value)
|
||||
public ConfigLinkedEntry(AbstractConfigType<?, ?> value)
|
||||
{
|
||||
super(EConfigEntryAppearance.ONLY_IN_GUI, value);
|
||||
}
|
||||
@@ -21,10 +21,10 @@ public class ConfigLinkedEntry extends AbstractConfigType<AbstractConfigType, Co
|
||||
|
||||
/** Value shouldn't be changed after creation */
|
||||
@Override
|
||||
public void set(AbstractConfigType newValue) { }
|
||||
public void set(AbstractConfigType<?, ?> newValue) { }
|
||||
|
||||
|
||||
public static class Builder extends AbstractConfigType.Builder<AbstractConfigType, Builder>
|
||||
public static class Builder extends AbstractConfigType.Builder<AbstractConfigType<?, ?>, Builder>
|
||||
{
|
||||
/** Appearance shouldn't be changed */
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user