Skip to content

Commit 84ad801

Browse files
committed
BVAL-616 Extracting @PositiveOrZero/@NegativeOrZero from @Positive/@Negative
1 parent 3406490 commit 84ad801

File tree

4 files changed

+136
-18
lines changed

4 files changed

+136
-18
lines changed

src/main/java/javax/validation/constraints/Negative.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import javax.validation.constraints.Negative.List;
2525

2626
/**
27-
* The annotated element must be a negative number.
27+
* The annotated element must be a strictly negative number (i.e. 0 is considered as an invalid value).
2828
* <p>
2929
* Supported types are:
3030
* <ul>
@@ -52,14 +52,6 @@
5252

5353
Class<? extends Payload>[] payload() default { };
5454

55-
/**
56-
* Whether the annotated element must be strictly negative (0 is considered as an invalid value) or not (0 is a
57-
* valid value).
58-
*
59-
* @return whether the annotated element must be strictly negative
60-
*/
61-
boolean strict() default false;
62-
6355
/**
6456
* Defines several {@link Negative} constraints on the same element.
6557
*
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Bean Validation API
3+
*
4+
* License: Apache License, Version 2.0
5+
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
6+
*/
7+
package javax.validation.constraints;
8+
9+
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
10+
import static java.lang.annotation.ElementType.CONSTRUCTOR;
11+
import static java.lang.annotation.ElementType.FIELD;
12+
import static java.lang.annotation.ElementType.METHOD;
13+
import static java.lang.annotation.ElementType.PARAMETER;
14+
import static java.lang.annotation.ElementType.TYPE_USE;
15+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
16+
17+
import java.lang.annotation.Documented;
18+
import java.lang.annotation.Repeatable;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.Target;
21+
22+
import javax.validation.Constraint;
23+
import javax.validation.Payload;
24+
import javax.validation.constraints.NegativeOrZero.List;
25+
26+
/**
27+
* The annotated element must be a negative number or 0.
28+
* <p>
29+
* Supported types are:
30+
* <ul>
31+
* <li>{@code BigDecimal}</li>
32+
* <li>{@code BigInteger}</li>
33+
* <li>{@code byte}, {@code short}, {@code int}, {@code long}, {@code float}, {@code double} and their respective
34+
* wrappers</li>
35+
* </ul>
36+
* <p>
37+
* {@code null} elements are considered valid.
38+
*
39+
* @author Gunnar Morling
40+
* @since 2.0
41+
*/
42+
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
43+
@Retention(RUNTIME)
44+
@Repeatable(List.class)
45+
@Documented
46+
@Constraint(validatedBy = { })
47+
public @interface NegativeOrZero {
48+
49+
String message() default "{javax.validation.constraints.NegativeOrZero.message}";
50+
51+
Class<?>[] groups() default { };
52+
53+
Class<? extends Payload>[] payload() default { };
54+
55+
/**
56+
* Defines several {@link NegativeOrZero} constraints on the same element.
57+
*
58+
* @see NegativeOrZero
59+
*/
60+
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
61+
@Retention(RUNTIME)
62+
@Documented
63+
@interface List {
64+
65+
NegativeOrZero[] value();
66+
}
67+
}

src/main/java/javax/validation/constraints/Positive.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import javax.validation.constraints.Positive.List;
2525

2626
/**
27-
* The annotated element must be a positive number.
27+
* The annotated element must be a strictly positive number (i.e. 0 is considered as an invalid value).
2828
* <p>
2929
* Supported types are:
3030
* <ul>
@@ -52,14 +52,6 @@
5252

5353
Class<? extends Payload>[] payload() default { };
5454

55-
/**
56-
* Whether the annotated element must be strictly positive (0 is considered as an invalid value) or not (0 is a
57-
* valid value).
58-
*
59-
* @return whether the annotated element must be strictly positive
60-
*/
61-
boolean strict() default false;
62-
6355
/**
6456
* Defines several {@link Positive} constraints on the same element.
6557
*
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Bean Validation API
3+
*
4+
* License: Apache License, Version 2.0
5+
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
6+
*/
7+
package javax.validation.constraints;
8+
9+
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
10+
import static java.lang.annotation.ElementType.CONSTRUCTOR;
11+
import static java.lang.annotation.ElementType.FIELD;
12+
import static java.lang.annotation.ElementType.METHOD;
13+
import static java.lang.annotation.ElementType.PARAMETER;
14+
import static java.lang.annotation.ElementType.TYPE_USE;
15+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
16+
17+
import java.lang.annotation.Documented;
18+
import java.lang.annotation.Repeatable;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.Target;
21+
22+
import javax.validation.Constraint;
23+
import javax.validation.Payload;
24+
import javax.validation.constraints.PositiveOrZero.List;
25+
26+
/**
27+
* The annotated element must be a positive number or 0.
28+
* <p>
29+
* Supported types are:
30+
* <ul>
31+
* <li>{@code BigDecimal}</li>
32+
* <li>{@code BigInteger}</li>
33+
* <li>{@code byte}, {@code short}, {@code int}, {@code long}, {@code float}, {@code double} and their respective
34+
* wrappers</li>
35+
* </ul>
36+
* <p>
37+
* {@code null} elements are considered valid.
38+
*
39+
* @author Gunnar Morling
40+
* @since 2.0
41+
*/
42+
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
43+
@Retention(RUNTIME)
44+
@Repeatable(List.class)
45+
@Documented
46+
@Constraint(validatedBy = { })
47+
public @interface PositiveOrZero {
48+
49+
String message() default "{javax.validation.constraints.PositiveOrZero.message}";
50+
51+
Class<?>[] groups() default { };
52+
53+
Class<? extends Payload>[] payload() default { };
54+
55+
/**
56+
* Defines several {@link PositiveOrZero} constraints on the same element.
57+
*
58+
* @see PositiveOrZero
59+
*/
60+
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
61+
@Retention(RUNTIME)
62+
@Documented
63+
@interface List {
64+
65+
PositiveOrZero[] value();
66+
}
67+
}

0 commit comments

Comments
 (0)