diff --git a/core/src/main/java/io/github/almightysatan/jaskl/annotation/Validate.java b/core/src/main/java/io/github/almightysatan/jaskl/annotation/Validate.java index d6c842b..8f47d8a 100644 --- a/core/src/main/java/io/github/almightysatan/jaskl/annotation/Validate.java +++ b/core/src/main/java/io/github/almightysatan/jaskl/annotation/Validate.java @@ -55,6 +55,30 @@ public interface Validate { @interface DoubleNegative { } + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface DoubleGreater { + double value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface DoubleGreaterOrEqual { + double value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface DoubleLess { + double value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface DoubleLessOrEqual { + double value(); + } + @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @interface FloatNotZero { @@ -80,6 +104,30 @@ public interface Validate { @interface FloatNegative { } + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface FloatGreater { + float value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface FloatGreaterOrEqual { + float value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface FloatLess { + float value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface FloatLessOrEqual { + float value(); + } + @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @interface IntegerNotZero { @@ -105,6 +153,30 @@ public interface Validate { @interface IntegerNegative { } + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface IntegerGreater { + int value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface IntegerGreaterOrEqual { + int value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface IntegerLess { + int value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface IntegerLessOrEqual { + int value(); + } + @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @interface LongNotZero { @@ -130,6 +202,128 @@ public interface Validate { @interface LongNegative { } + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface LongGreater { + long value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface LongGreaterOrEqual { + long value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface LongLess { + long value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface LongLessOrEqual { + long value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigIntegerNotZero { + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigIntegerNotPositive { + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigIntegerNotNegative { + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigIntegerPositive { + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigIntegerNegative { + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigIntegerGreater { + String value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigIntegerGreaterOrEqual { + String value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigIntegerLess { + String value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigIntegerLessOrEqual { + String value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigDecimalNotZero { + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigDecimalNotPositive { + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigDecimalNotNegative { + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigDecimalPositive { + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigDecimalNegative { + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigDecimalGreater { + String value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigDecimalGreaterOrEqual { + String value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigDecimalLess { + String value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + @interface BigDecimalLessOrEqual { + String value(); + } + @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @interface StringNotEmpty { diff --git a/core/src/main/java/io/github/almightysatan/jaskl/impl/AnnotationManagerImpl.java b/core/src/main/java/io/github/almightysatan/jaskl/impl/AnnotationManagerImpl.java index c3ce16f..809cee3 100644 --- a/core/src/main/java/io/github/almightysatan/jaskl/impl/AnnotationManagerImpl.java +++ b/core/src/main/java/io/github/almightysatan/jaskl/impl/AnnotationManagerImpl.java @@ -29,6 +29,8 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.lang.reflect.ParameterizedType; +import java.math.BigDecimal; +import java.math.BigInteger; import java.util.*; import java.util.function.Function; @@ -376,21 +378,55 @@ private void registerDefaultAnnotations() { this.addValidator(Validate.DoubleNotNegative.class, Validator.DOUBLE_NOT_NEGATIVE); this.addValidator(Validate.DoublePositive.class, Validator.DOUBLE_POSITIVE); this.addValidator(Validate.DoubleNegative.class, Validator.DOUBLE_NEGATIVE); + this.addValidatorFunction(Validate.DoubleGreater.class, annotation -> Validator.doubleGreater(annotation.value())); + this.addValidatorFunction(Validate.DoubleGreaterOrEqual.class, annotation -> Validator.doubleGreaterOrEqual(annotation.value())); + this.addValidatorFunction(Validate.DoubleLess.class, annotation -> Validator.doubleLess(annotation.value())); + this.addValidatorFunction(Validate.DoubleLessOrEqual.class, annotation -> Validator.doubleLessOrEqual(annotation.value())); this.addValidator(Validate.FloatNotZero.class, Validator.FLOAT_NOT_ZERO); this.addValidator(Validate.FloatNotPositive.class, Validator.FLOAT_NOT_POSITIVE); this.addValidator(Validate.FloatNotNegative.class, Validator.FLOAT_NOT_NEGATIVE); this.addValidator(Validate.FloatPositive.class, Validator.FLOAT_POSITIVE); this.addValidator(Validate.FloatNegative.class, Validator.FLOAT_NEGATIVE); + this.addValidatorFunction(Validate.FloatGreater.class, annotation -> Validator.floatGreater(annotation.value())); + this.addValidatorFunction(Validate.FloatGreaterOrEqual.class, annotation -> Validator.floatGreaterOrEqual(annotation.value())); + this.addValidatorFunction(Validate.FloatLess.class, annotation -> Validator.floatLess(annotation.value())); + this.addValidatorFunction(Validate.FloatLessOrEqual.class, annotation -> Validator.floatLessOrEqual(annotation.value())); this.addValidator(Validate.IntegerNotZero.class, Validator.INTEGER_NOT_ZERO); this.addValidator(Validate.IntegerNotPositive.class, Validator.INTEGER_NOT_POSITIVE); this.addValidator(Validate.IntegerNotNegative.class, Validator.INTEGER_NOT_NEGATIVE); this.addValidator(Validate.IntegerPositive.class, Validator.INTEGER_POSITIVE); this.addValidator(Validate.IntegerNegative.class, Validator.INTEGER_NEGATIVE); + this.addValidatorFunction(Validate.IntegerGreater.class, annotation -> Validator.integerGreater(annotation.value())); + this.addValidatorFunction(Validate.IntegerGreaterOrEqual.class, annotation -> Validator.integerGreaterOrEqual(annotation.value())); + this.addValidatorFunction(Validate.IntegerLess.class, annotation -> Validator.integerLess(annotation.value())); + this.addValidatorFunction(Validate.IntegerLessOrEqual.class, annotation -> Validator.integerLessOrEqual(annotation.value())); this.addValidator(Validate.LongNotZero.class, Validator.LONG_NOT_ZERO); this.addValidator(Validate.LongNotPositive.class, Validator.LONG_NOT_POSITIVE); this.addValidator(Validate.LongNotNegative.class, Validator.LONG_NOT_NEGATIVE); this.addValidator(Validate.LongPositive.class, Validator.LONG_POSITIVE); this.addValidator(Validate.LongNegative.class, Validator.LONG_NEGATIVE); + this.addValidatorFunction(Validate.LongGreater.class, annotation -> Validator.longGreater(annotation.value())); + this.addValidatorFunction(Validate.LongGreaterOrEqual.class, annotation -> Validator.longGreaterOrEqual(annotation.value())); + this.addValidatorFunction(Validate.LongLess.class, annotation -> Validator.longLess(annotation.value())); + this.addValidatorFunction(Validate.LongLessOrEqual.class, annotation -> Validator.longLessOrEqual(annotation.value())); + this.addValidator(Validate.BigIntegerNotZero.class, Validator.INTEGER_NOT_ZERO); + this.addValidator(Validate.BigIntegerNotPositive.class, Validator.INTEGER_NOT_POSITIVE); + this.addValidator(Validate.BigIntegerNotNegative.class, Validator.INTEGER_NOT_NEGATIVE); + this.addValidator(Validate.BigIntegerPositive.class, Validator.INTEGER_POSITIVE); + this.addValidator(Validate.BigIntegerNegative.class, Validator.INTEGER_NEGATIVE); + this.addValidatorFunction(Validate.BigIntegerGreater.class, annotation -> Validator.bigIntegerGreater(new BigInteger(annotation.value()))); + this.addValidatorFunction(Validate.BigIntegerGreaterOrEqual.class, annotation -> Validator.bigIntegerGreaterOrEqual(new BigInteger(annotation.value()))); + this.addValidatorFunction(Validate.BigIntegerLess.class, annotation -> Validator.bigIntegerLess(new BigInteger(annotation.value()))); + this.addValidatorFunction(Validate.BigIntegerLessOrEqual.class, annotation -> Validator.bigIntegerLessOrEqual(new BigInteger(annotation.value()))); + this.addValidator(Validate.BigDecimalNotZero.class, Validator.INTEGER_NOT_ZERO); + this.addValidator(Validate.BigDecimalNotPositive.class, Validator.INTEGER_NOT_POSITIVE); + this.addValidator(Validate.BigDecimalNotNegative.class, Validator.INTEGER_NOT_NEGATIVE); + this.addValidator(Validate.BigDecimalPositive.class, Validator.INTEGER_POSITIVE); + this.addValidator(Validate.BigDecimalNegative.class, Validator.INTEGER_NEGATIVE); + this.addValidatorFunction(Validate.BigDecimalGreater.class, annotation -> Validator.bigDecimalGreater(new BigDecimal(annotation.value()))); + this.addValidatorFunction(Validate.BigDecimalGreaterOrEqual.class, annotation -> Validator.bigDecimalGreaterOrEqual(new BigDecimal(annotation.value()))); + this.addValidatorFunction(Validate.BigDecimalLess.class, annotation -> Validator.bigDecimalLess(new BigDecimal(annotation.value()))); + this.addValidatorFunction(Validate.BigDecimalLessOrEqual.class, annotation -> Validator.bigDecimalLessOrEqual(new BigDecimal(annotation.value()))); this.addValidator(Validate.StringNotEmpty.class, Validator.STRING_NOT_EMPTY); this.addValidatorFunction(Validate.StringMinLength.class, annotation -> Validator.stringMinLength(annotation.value())); this.addValidatorFunction(Validate.StringMaxLength.class, annotation -> Validator.stringMaxLength(annotation.value()));