You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add additional Validators and accept Validators of super types (#9)
* Add validators for BigInteger and BigDecimal
* Add validators for number comparison
* Add more validators for strings
* Accept validators of super types
* Add annotations
@@ -62,6 +64,14 @@ public interface Validator<T> {
62
64
63
65
Validator<Double> DOUBLE_NEGATIVE = value -> { if (value >= 0) thrownewValidationException("should be negative"); };
64
66
67
+
static@NotNullValidator<Double> doubleGreater(doubleother) { returnvalue -> { if (value > other) thrownewValidationException("should be greater than " + other); }; }
68
+
69
+
static@NotNullValidator<Double> doubleGreaterOrEqual(doubleother) { returnvalue -> { if (value >= other) thrownewValidationException("should be greater than or equal to " + other); }; }
70
+
71
+
static@NotNullValidator<Double> doubleLess(doubleother) { returnvalue -> { if (value < other) thrownewValidationException("should be less than " + other); }; }
72
+
73
+
static@NotNullValidator<Double> doubleLessOrEqual(doubleother) { returnvalue -> { if (value <= other) thrownewValidationException("should be less than or equal to " + other); }; }
74
+
65
75
Validator<Float> FLOAT_NOT_ZERO = value -> { if (value == 0) thrownewValidationException("should not be 0"); };
66
76
67
77
Validator<Float> FLOAT_NOT_POSITIVE = value -> { if (value > 0) thrownewValidationException("should not be positive"); };
@@ -72,6 +82,14 @@ public interface Validator<T> {
72
82
73
83
Validator<Float> FLOAT_NEGATIVE = value -> { if (value >= 0) thrownewValidationException("should be negative"); };
74
84
85
+
static@NotNullValidator<Float> floatGreater(floatother) { returnvalue -> { if (value > other) thrownewValidationException("should be greater than " + other); }; }
86
+
87
+
static@NotNullValidator<Float> floatGreaterOrEqual(floatother) { returnvalue -> { if (value >= other) thrownewValidationException("should be greater than or equal to " + other); }; }
88
+
89
+
static@NotNullValidator<Float> floatLess(floatother) { returnvalue -> { if (value < other) thrownewValidationException("should be less than " + other); }; }
90
+
91
+
static@NotNullValidator<Float> floatLessOrEqual(floatother) { returnvalue -> { if (value <= other) thrownewValidationException("should be less than or equal to " + other); }; }
92
+
75
93
Validator<Integer> INTEGER_NOT_ZERO = value -> { if (value == 0) thrownewValidationException("should not be 0"); };
76
94
77
95
Validator<Integer> INTEGER_NOT_POSITIVE = value -> { if (value > 0) thrownewValidationException("should not be positive"); };
@@ -82,6 +100,14 @@ public interface Validator<T> {
82
100
83
101
Validator<Integer> INTEGER_NEGATIVE = value -> { if (value >= 0) thrownewValidationException("should be negative"); };
84
102
103
+
static@NotNullValidator<Integer> integerGreater(intother) { returnvalue -> { if (value > other) thrownewValidationException("should be greater than " + other); }; }
104
+
105
+
static@NotNullValidator<Integer> integerGreaterOrEqual(intother) { returnvalue -> { if (value >= other) thrownewValidationException("should be greater than or equal to " + other); }; }
106
+
107
+
static@NotNullValidator<Integer> integerLess(intother) { returnvalue -> { if (value < other) thrownewValidationException("should be less than " + other); }; }
108
+
109
+
static@NotNullValidator<Integer> integerLessOrEqual(intother) { returnvalue -> { if (value <= other) thrownewValidationException("should be less than or equal to " + other); }; }
110
+
85
111
Validator<Long> LONG_NOT_ZERO = value -> { if (value == 0) thrownewValidationException("should not be 0"); };
86
112
87
113
Validator<Long> LONG_NOT_POSITIVE = value -> { if (value > 0) thrownewValidationException("should not be positive"); };
@@ -92,8 +118,70 @@ public interface Validator<T> {
92
118
93
119
Validator<Long> LONG_NEGATIVE = value -> { if (value >= 0) thrownewValidationException("should be negative"); };
94
120
121
+
static@NotNullValidator<Long> longGreater(longother) { returnvalue -> { if (value > other) thrownewValidationException("should be greater than " + other); }; }
122
+
123
+
static@NotNullValidator<Long> longGreaterOrEqual(longother) { returnvalue -> { if (value >= other) thrownewValidationException("should be greater than or equal to " + other); }; }
124
+
125
+
static@NotNullValidator<Long> longLess(longother) { returnvalue -> { if (value < other) thrownewValidationException("should be less than " + other); }; }
126
+
127
+
static@NotNullValidator<Long> longLessOrEqual(longother) { returnvalue -> { if (value <= other) thrownewValidationException("should be less than or equal to " + other); }; }
128
+
129
+
Validator<BigInteger> BIG_INTEGER_NOT_ZERO = value -> { if (value.signum() == 0) thrownewValidationException("should not be 0"); };
130
+
131
+
Validator<BigInteger> BIG_INTEGER_NOT_POSITIVE = value -> { if (value.signum() == 1) thrownewValidationException("should not be positive"); };
132
+
133
+
Validator<BigInteger> BIG_INTEGER_NOT_NEGATIVE = value -> { if (value.signum() == -1) thrownewValidationException("should not be negative"); };
134
+
135
+
Validator<BigInteger> BIG_INTEGER_POSITIVE = value -> { if (value.signum() != 1) thrownewValidationException("should be positive"); };
136
+
137
+
Validator<BigInteger> BIG_INTEGER_NEGATIVE = value -> { if (value.signum() != -1) thrownewValidationException("should be negative"); };
138
+
139
+
static@NotNullValidator<BigInteger> bigIntegerGreater(BigIntegerother) { returnvalue -> { if (value.compareTo(other) < 1) thrownewValidationException("should be greater than " + other); }; }
140
+
141
+
static@NotNullValidator<BigInteger> bigIntegerGreaterOrEqual(BigIntegerother) { returnvalue -> { if (value.compareTo(other) < 0) thrownewValidationException("should be greater than or equal to " + other); }; }
142
+
143
+
static@NotNullValidator<BigInteger> bigIntegerLess(BigIntegerother) { returnvalue -> { if (value.compareTo(other) > -1) thrownewValidationException("should be less than " + other); }; }
144
+
145
+
static@NotNullValidator<BigInteger> bigIntegerLessOrEqual(BigIntegerother) { returnvalue -> { if (value.compareTo(other) > 0) thrownewValidationException("should be less than or equal to " + other); }; }
146
+
147
+
Validator<BigDecimal> BIG_DECIMAL_NOT_ZERO = value -> { if (value.signum() == 0) thrownewValidationException("should not be 0"); };
148
+
149
+
Validator<BigDecimal> BIG_DECIMAL_NOT_POSITIVE = value -> { if (value.signum() == 1) thrownewValidationException("should not be positive"); };
150
+
151
+
Validator<BigDecimal> BIG_DECIMAL_NOT_NEGATIVE = value -> { if (value.signum() == -1) thrownewValidationException("should not be negative"); };
152
+
153
+
Validator<BigDecimal> BIG_DECIMAL_POSITIVE = value -> { if (value.signum() != 1) thrownewValidationException("should be positive"); };
154
+
155
+
Validator<BigDecimal> BIG_DECIMAL_NEGATIVE = value -> { if (value.signum() != -1) thrownewValidationException("should be negative"); };
156
+
157
+
static@NotNullValidator<BigDecimal> bigDecimalGreater(BigDecimalother) { returnvalue -> { if (value.compareTo(other) < 1) thrownewValidationException("should be greater than " + other); }; }
158
+
159
+
static@NotNullValidator<BigDecimal> bigDecimalGreaterOrEqual(BigDecimalother) { returnvalue -> { if (value.compareTo(other) < 0) thrownewValidationException("should be greater than or equal to " + other); }; }
160
+
161
+
static@NotNullValidator<BigDecimal> bigDecimalLess(BigDecimalother) { returnvalue -> { if (value.compareTo(other) > -1) thrownewValidationException("should be less than " + other); }; }
162
+
163
+
static@NotNullValidator<BigDecimal> bigDecimalLessOrEqual(BigDecimalother) { returnvalue -> { if (value.compareTo(other) > 0) thrownewValidationException("should be less than or equal to " + other); }; }
164
+
95
165
Validator<String> STRING_NOT_EMPTY = value -> { if (value.isEmpty()) thrownewValidationException("should not be empty"); };
96
166
167
+
Validator<String> STRING_ALPHABETIC = value -> {
168
+
for (charc : value.toCharArray())
169
+
if ((c < 0x41 || c > 0x5A) && (c < 0x61 || c > 0x7A))
170
+
thrownewValidationException("should only contain alphabetic characters");
171
+
};
172
+
173
+
Validator<String> STRING_NUMERIC = value -> {
174
+
for (charc : value.toCharArray())
175
+
if (c < 0x30 || c > 0x39)
176
+
thrownewValidationException("should only contain numbers");
177
+
};
178
+
179
+
Validator<String> STRING_ALPHANUMERIC = value -> {
180
+
for (charc : value.toCharArray())
181
+
if ((c < 0x41 || c > 0x5A) && (c < 0x61 || c > 0x7A) && (c < 0x30 || c > 0x39))
182
+
thrownewValidationException("should only contain alphanumeric characters");
183
+
};
184
+
97
185
static@NotNullValidator<String> stringMinLength(intsize) { returnvalue -> { if (value.length() < size) thrownewValidationException("should be at least " + size + " characters long"); };}
98
186
99
187
static@NotNullValidator<String> stringMaxLength(intsize) { returnvalue -> { if (value.length() > size) thrownewValidationException("should not be longer than " + size + " characters"); };}
@@ -104,15 +192,15 @@ public interface Validator<T> {
104
192
105
193
static <T> @NotNullValidator<List<T>> listMaxSize(intsize) { returnvalue -> { if (value.size() > size) thrownewValidationException("should not have more than " + size + " entries"); };}
0 commit comments