From 0f196f59c6a4cb76ab8409da62ff1f35505f94a8 Mon Sep 17 00:00:00 2001 From: Dico Karssiens Date: Sun, 11 Nov 2018 14:06:45 +0000 Subject: Changes I made before breaking my local repository. Hoping this works. --- .../command/parameter/type/ParameterConfig.java | 160 ++++++++++----------- 1 file changed, 80 insertions(+), 80 deletions(-) (limited to 'dicore3/command/src/main/java/io/dico/dicore/command/parameter/type/ParameterConfig.java') diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/parameter/type/ParameterConfig.java b/dicore3/command/src/main/java/io/dico/dicore/command/parameter/type/ParameterConfig.java index dbd7590..d33932b 100644 --- a/dicore3/command/src/main/java/io/dico/dicore/command/parameter/type/ParameterConfig.java +++ b/dicore3/command/src/main/java/io/dico/dicore/command/parameter/type/ParameterConfig.java @@ -1,80 +1,80 @@ -package io.dico.dicore.command.parameter.type; - -import io.dico.dicore.Reflection; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; - -/** - * This class serves the purpose of having annotated parameter configurations (such as ranges for number parameters). - * Such configurations must be possible to obtain without using annotations, and as such, there should be a class conveying the information - * that is separate from the annotation itself. This class acts as a bridge from the annotation to said class conveying the information. - * - * @param the annotation type for parameters - * @param the object type that holds the information required in memory - */ -public abstract class ParameterConfig implements Comparable> { - private final Class annotationClass; - // protected final TParamInfo defaultValue; - - public ParameterConfig(Class annotationClass/*, TParamInfo defaultValue*/) { - this.annotationClass = annotationClass; - //this.defaultValue = defaultValue; - } - - public final Class getAnnotationClass() { - return annotationClass; - } - /* - public TParamInfo getDefaultValue() { - return defaultValue; - }*/ - - protected abstract TParamInfo toParameterInfo(TAnnotation annotation); - - public TParamInfo getParameterInfo(Annotation annotation) { - //noinspection unchecked - return toParameterInfo((TAnnotation) annotation); - } - - public static ParameterConfig - includeMemoryClass(Class annotationClass, Class memoryClass) { - Constructor constructor; - //TParamInfo defaultValue; - try { - constructor = memoryClass.getConstructor(annotationClass); - //defaultValue = Reflection.getStaticFieldValue(annotationClass, "DEFAULT"); - } catch (NoSuchMethodException | IllegalArgumentException ex) { - throw new IllegalArgumentException(ex); - } - /* - if (defaultValue == null) try { - defaultValue = memoryClass.newInstance(); - } catch (IllegalAccessException | InstantiationException ex) { - throw new IllegalArgumentException("Failed to get a default value for the param info", ex); - }*/ - - return new ParameterConfig(annotationClass/*, defaultValue*/) { - - @Override - public TParamInfo toParameterInfo(TAnnotation annotation) { - try { - return constructor.newInstance(annotation); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - }; - } - - public static ParameterConfig getMemoryClassFromField(Class annotationClass) { - return ParameterConfig.includeMemoryClass(annotationClass, Reflection.getStaticFieldValue(annotationClass, "MEMORY_CLASS")); - } - - @Override - public int compareTo(ParameterConfig o) { - return 0; - } - -} - +package io.dico.dicore.command.parameter.type; + +import io.dico.dicore.Reflection; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; + +/** + * This class serves the purpose of having annotated parameter configurations (such as ranges for number parameters). + * Such configurations must be possible to obtain without using annotations, and as such, there should be a class conveying the information + * that is separate from the annotation itself. This class acts as a bridge from the annotation to said class conveying the information. + * + * @param the annotation type for parameters + * @param the object type that holds the information required in memory + */ +public abstract class ParameterConfig implements Comparable> { + private final Class annotationClass; + // protected final TParamInfo defaultValue; + + public ParameterConfig(Class annotationClass/*, TParamInfo defaultValue*/) { + this.annotationClass = annotationClass; + //this.defaultValue = defaultValue; + } + + public final Class getAnnotationClass() { + return annotationClass; + } + /* + public TParamInfo getDefaultValue() { + return defaultValue; + }*/ + + protected abstract TParamInfo toParameterInfo(TAnnotation annotation); + + public TParamInfo getParameterInfo(Annotation annotation) { + //noinspection unchecked + return toParameterInfo((TAnnotation) annotation); + } + + public static ParameterConfig + includeMemoryClass(Class annotationClass, Class memoryClass) { + Constructor constructor; + //TParamInfo defaultValue; + try { + constructor = memoryClass.getConstructor(annotationClass); + //defaultValue = Reflection.getStaticFieldValue(annotationClass, "DEFAULT"); + } catch (NoSuchMethodException | IllegalArgumentException ex) { + throw new IllegalArgumentException(ex); + } + /* + if (defaultValue == null) try { + defaultValue = memoryClass.newInstance(); + } catch (IllegalAccessException | InstantiationException ex) { + throw new IllegalArgumentException("Failed to get a default value for the param info", ex); + }*/ + + return new ParameterConfig(annotationClass/*, defaultValue*/) { + + @Override + public TParamInfo toParameterInfo(TAnnotation annotation) { + try { + return constructor.newInstance(annotation); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + }; + } + + public static ParameterConfig getMemoryClassFromField(Class annotationClass) { + return ParameterConfig.includeMemoryClass(annotationClass, Reflection.getStaticFieldValue(annotationClass, "MEMORY_CLASS")); + } + + @Override + public int compareTo(ParameterConfig o) { + return 0; + } + +} + -- cgit v1.2.3