summaryrefslogtreecommitdiff
path: root/dicore3/command/src/main/java/io/dico/dicore/command/annotation/Range.java
diff options
context:
space:
mode:
Diffstat (limited to 'dicore3/command/src/main/java/io/dico/dicore/command/annotation/Range.java')
-rw-r--r--dicore3/command/src/main/java/io/dico/dicore/command/annotation/Range.java134
1 files changed, 67 insertions, 67 deletions
diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/annotation/Range.java b/dicore3/command/src/main/java/io/dico/dicore/command/annotation/Range.java
index 3fd4160..98aec22 100644
--- a/dicore3/command/src/main/java/io/dico/dicore/command/annotation/Range.java
+++ b/dicore3/command/src/main/java/io/dico/dicore/command/annotation/Range.java
@@ -1,67 +1,67 @@
-package io.dico.dicore.command.annotation;
-
-import io.dico.dicore.command.CommandException;
-import io.dico.dicore.command.Validate;
-import io.dico.dicore.command.parameter.type.ParameterConfig;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.PARAMETER)
-public @interface Range {
- Class<?> MEMORY_CLASS = Memory.class;
- ParameterConfig<Range, Memory> CONFIG = ParameterConfig.getMemoryClassFromField(Range.class);
- Memory DEFAULT = new Memory(-Double.MAX_VALUE, Double.MAX_VALUE, 0);
-
- double min() default -Double.MAX_VALUE;
-
- double max() default Double.MAX_VALUE;
-
- double defaultValue() default 0;
-
- class Memory {
- private final double min;
- private final double max;
- private final double defaultValue;
-
- public Memory(Range range) {
- this(range.min(), range.max(), range.defaultValue());
- }
-
- public Memory(double min, double max, double defaultValue) {
- this.min = min;
- this.max = max;
- this.defaultValue = defaultValue;
- }
-
- public double min() {
- return min;
- }
-
- public double max() {
- return max;
- }
-
- public double defaultValue() {
- return defaultValue;
- }
-
- public void validate(Number x, String failMessage) throws CommandException {
- Validate.isTrue(valid(x), failMessage);
- }
-
- public boolean valid(Number x) {
- double d = x.doubleValue();
- return min <= d && d <= max;
- }
-
- public boolean isDefault() {
- return this == DEFAULT || (min == DEFAULT.min && max == DEFAULT.max && defaultValue == DEFAULT.defaultValue);
- }
-
- }
-
-}
+package io.dico.dicore.command.annotation;
+
+import io.dico.dicore.command.CommandException;
+import io.dico.dicore.command.Validate;
+import io.dico.dicore.command.parameter.type.ParameterConfig;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.PARAMETER)
+public @interface Range {
+ Class<?> MEMORY_CLASS = Memory.class;
+ ParameterConfig<Range, Memory> CONFIG = ParameterConfig.getMemoryClassFromField(Range.class);
+ Memory DEFAULT = new Memory(-Double.MAX_VALUE, Double.MAX_VALUE, 0);
+
+ double min() default -Double.MAX_VALUE;
+
+ double max() default Double.MAX_VALUE;
+
+ double defaultValue() default 0;
+
+ class Memory {
+ private final double min;
+ private final double max;
+ private final double defaultValue;
+
+ public Memory(Range range) {
+ this(range.min(), range.max(), range.defaultValue());
+ }
+
+ public Memory(double min, double max, double defaultValue) {
+ this.min = min;
+ this.max = max;
+ this.defaultValue = defaultValue;
+ }
+
+ public double min() {
+ return min;
+ }
+
+ public double max() {
+ return max;
+ }
+
+ public double defaultValue() {
+ return defaultValue;
+ }
+
+ public void validate(Number x, String failMessage) throws CommandException {
+ Validate.isTrue(valid(x), failMessage);
+ }
+
+ public boolean valid(Number x) {
+ double d = x.doubleValue();
+ return min <= d && d <= max;
+ }
+
+ public boolean isDefault() {
+ return this == DEFAULT || (min == DEFAULT.min && max == DEFAULT.max && defaultValue == DEFAULT.defaultValue);
+ }
+
+ }
+
+}