-
Notifications
You must be signed in to change notification settings - Fork 34
/
LocalDateTimeProp.java
84 lines (67 loc) · 2.69 KB
/
LocalDateTimeProp.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
78
79
80
81
82
83
84
package org.yarnandtail.andhow.property;
import org.yarnandtail.andhow.api.*;
import org.yarnandtail.andhow.valid.LocalDateTimeValidator;
import org.yarnandtail.andhow.valuetype.LocalDateTimeType;
import java.time.LocalDateTime;
import java.util.List;
/**
* A {@link java.time.LocalDateTime} configuration Property
* <p>
* Parsing values from strings is done by the {@link LocalDateTimeType}, which parses values using
* the {@link java.time.LocalDateTime#parse(CharSequence)} method, so the format
* follows that specification, which looks like this:
* <ul>
* <li>{@code 2007-12-03T00:00}</li>
* <li>{@code 2007-12-03T23:15:30}</li>
* <li>{@code 2007-12-03T23:15:30.123}</li>
* <li>{@code 2007-12-03T23:15:30.123456789}</li>
* </ul>
* <p>
* Before parsing String values, the {@link TrimToNullTrimmer} is applied by default.
*/
public class LocalDateTimeProp extends PropertyBase<LocalDateTime> {
public LocalDateTimeProp(
LocalDateTime defaultValue, boolean required, String shortDesc, List<Validator<LocalDateTime>> validators,
List<Name> aliases, PropertyType paramType, ValueType<LocalDateTime> 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 LocalDateTimeProp.builder()...series of builder methods...build();}
* <p>
* @return The builder instance that can be chained
*/
public static LocalDateTimeBuilder builder() {
return new LocalDateTimeBuilder();
}
public static class LocalDateTimeBuilder extends PropertyBuilderBase<LocalDateTimeBuilder, LocalDateTimeProp, LocalDateTime> {
public LocalDateTimeBuilder() {
instance = this;
valueType(LocalDateTimeType.instance());
trimmer(TrimToNullTrimmer.instance());
}
@Override
public LocalDateTimeProp build() {
return new LocalDateTimeProp(_defaultValue, _nonNull, _desc, _validators,
_aliases, PropertyType.SINGLE_NAME_VALUE, _valueType, _trimmer, _helpText);
}
public LocalDateTimeBuilder before(LocalDateTime reference) {
validation(new LocalDateTimeValidator.Before(reference));
return instance;
}
public LocalDateTimeBuilder sameOrBefore(LocalDateTime reference) {
validation(new LocalDateTimeValidator.SameTimeOrBefore(reference));
return instance;
}
public LocalDateTimeBuilder after(LocalDateTime reference) {
validation(new LocalDateTimeValidator.After(reference));
return instance;
}
public LocalDateTimeBuilder sameOrAfter(LocalDateTime reference) {
validation(new LocalDateTimeValidator.SameTimeOrAfter(reference));
return instance;
}
}
}