-
Notifications
You must be signed in to change notification settings - Fork 34
/
IntProp.java
77 lines (60 loc) · 2.2 KB
/
IntProp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package org.yarnandtail.andhow.property;
import org.yarnandtail.andhow.api.*;
import org.yarnandtail.andhow.valid.IntValidator;
import org.yarnandtail.andhow.valuetype.IntType;
import java.util.List;
/**
* An {@link Integer} configuration Property
* <p>
* Parsing values from strings is done by the {@link IntType}, which parses values using the
* {@link Integer#parseInt(String)}. Note that the {@code parseInt} accepts integer numbers
* with the option of a leading '+' or '-'.
* <p>
* Before parsing String values, the {@link TrimToNullTrimmer} is applied by default.
*/
public class IntProp extends PropertyBase<Integer> {
public IntProp(
Integer defaultValue, boolean required, String shortDesc, List<Validator<Integer>> validators,
List<Name> aliases, PropertyType paramType, ValueType<Integer> valueType, Trimmer trimmer,
String helpText) {
super(defaultValue, required, shortDesc, validators, aliases, paramType, valueType, trimmer, helpText);
}
/**
* A chainable builder for this property that should terminate with {@code build()}
* <p>
* Use as {@code IntProp.builder()...series of builder methods...build();}
* <p>
* @return The builder instance that can be chained
*/
public static IntBuilder builder() {
return new IntBuilder();
}
public static class IntBuilder extends PropertyBuilderBase<IntBuilder, IntProp, Integer> {
public IntBuilder() {
instance = this;
valueType(IntType.instance());
trimmer(TrimToNullTrimmer.instance());
}
@Override
public IntProp build() {
return new IntProp(_defaultValue, _nonNull, _desc, _validators,
_aliases, PropertyType.SINGLE_NAME_VALUE, _valueType, _trimmer, _helpText);
}
public IntBuilder greaterThan(int reference) {
validation(new IntValidator.GreaterThan(reference));
return instance;
}
public IntBuilder greaterThanOrEqualTo(int reference) {
validation(new IntValidator.GreaterThanOrEqualTo(reference));
return instance;
}
public IntBuilder lessThan(int reference) {
validation(new IntValidator.LessThan(reference));
return instance;
}
public IntBuilder lessThanOrEqualTo(int reference) {
validation(new IntValidator.LessThanOrEqualTo(reference));
return instance;
}
}
}