-
Notifications
You must be signed in to change notification settings - Fork 37
/
ValueRangeFactory.java
155 lines (139 loc) · 6.33 KB
/
ValueRangeFactory.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.optaplanner.core.api.domain.valuerange;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalUnit;
import org.optaplanner.core.impl.domain.valuerange.buildin.bigdecimal.BigDecimalValueRange;
import org.optaplanner.core.impl.domain.valuerange.buildin.biginteger.BigIntegerValueRange;
import org.optaplanner.core.impl.domain.valuerange.buildin.primboolean.BooleanValueRange;
import org.optaplanner.core.impl.domain.valuerange.buildin.primdouble.DoubleValueRange;
import org.optaplanner.core.impl.domain.valuerange.buildin.primint.IntValueRange;
import org.optaplanner.core.impl.domain.valuerange.buildin.primlong.LongValueRange;
import org.optaplanner.core.impl.domain.valuerange.buildin.temporal.TemporalValueRange;
/**
* Factory for {@link ValueRange}.
*/
public class ValueRangeFactory {
/**
* Build a {@link CountableValueRange} of both {@code boolean} values.
* @return never null
*/
public static CountableValueRange<Boolean> createBooleanValueRange() {
return new BooleanValueRange();
}
/**
* Build a {@link CountableValueRange} of all {@code int} values between 2 bounds.
* @param from inclusive minimum
* @param to exclusive maximum, {@code >= from}
* @return never null
*/
public static CountableValueRange<Integer> createIntValueRange(int from, int to) {
return new IntValueRange(from, to);
}
/**
* Build a {@link CountableValueRange} of a subset of {@code int} values between 2 bounds.
* @param from inclusive minimum
* @param to exclusive maximum, {@code >= from}
* @param incrementUnit {@code > 0}
* @return never null
*/
public static CountableValueRange<Integer> createIntValueRange(int from, int to, int incrementUnit) {
return new IntValueRange(from, to, incrementUnit);
}
/**
* Build a {@link CountableValueRange} of all {@code long} values between 2 bounds.
* @param from inclusive minimum
* @param to exclusive maximum, {@code >= from}
* @return never null
*/
public static CountableValueRange<Long> createLongValueRange(long from, long to) {
return new LongValueRange(from, to);
}
/**
* Build a {@link CountableValueRange} of a subset of {@code long} values between 2 bounds.
* @param from inclusive minimum
* @param to exclusive maximum, {@code >= from}
* @param incrementUnit {@code > 0}
* @return never null
*/
public static CountableValueRange<Long> createLongValueRange(long from, long to, long incrementUnit) {
return new LongValueRange(from, to, incrementUnit);
}
/**
* Build an uncountable {@link ValueRange} of all {@code double} values between 2 bounds.
* @param from inclusive minimum
* @param to exclusive maximum, {@code >= from}
* @return never null
*/
public static ValueRange<Double> createDoubleValueRange(double from, double to) {
return new DoubleValueRange(from, to);
}
/**
* Build a {@link CountableValueRange} of all {@link BigInteger} values between 2 bounds.
* @param from inclusive minimum
* @param to exclusive maximum, {@code >= from}
* @return never null
*/
public static CountableValueRange<BigInteger> createBigIntegerValueRange(BigInteger from, BigInteger to) {
return new BigIntegerValueRange(from, to);
}
/**
* Build a {@link CountableValueRange} of a subset of {@link BigInteger} values between 2 bounds.
* @param from inclusive minimum
* @param to exclusive maximum, {@code >= from}
* @param incrementUnit {@code > 0}
* @return never null
*/
public static CountableValueRange<BigInteger> createBigIntegerValueRange(BigInteger from, BigInteger to, BigInteger incrementUnit) {
return new BigIntegerValueRange(from, to, incrementUnit);
}
/**
* Build a {@link CountableValueRange} of all {@link BigDecimal} values (of a specific scale) between 2 bounds.
* All parameters must have the same {@link BigDecimal#scale()}.
* @param from inclusive minimum
* @param to exclusive maximum, {@code >= from}
* @return never null
*/
public static CountableValueRange<BigDecimal> createBigDecimalValueRange(BigDecimal from, BigDecimal to) {
return new BigDecimalValueRange(from, to);
}
/**
* Build a {@link CountableValueRange} of a subset of {@link BigDecimal} values (of a specific scale) between 2 bounds.
* All parameters must have the same {@link BigDecimal#scale()}.
* @param from inclusive minimum
* @param to exclusive maximum, {@code >= from}
* @param incrementUnit {@code > 0}
* @return never null
*/
public static CountableValueRange<BigDecimal> createBigDecimalValueRange(BigDecimal from, BigDecimal to, BigDecimal incrementUnit) {
return new BigDecimalValueRange(from, to, incrementUnit);
}
/**
* Build a {@link CountableValueRange} of a subset of {@link Temporal} values (such as {@link LocalDate} or {@link LocalDateTime}) between 2 bounds.
* All parameters must have the same {@link TemporalUnit}.
* @param from never null, inclusive minimum
* @param to never null, exclusive maximum, {@code >= from}
* @param incrementUnitAmount {@code > 0}
* @param incrementUnitType never null, must be {@link Temporal#isSupported(TemporalUnit) supported} by {@code from} and {@code to}
*/
public static CountableValueRange<Temporal> createTemporalRange(Temporal from, Temporal to, long incrementUnitAmount, TemporalUnit incrementUnitType) {
return new TemporalValueRange(from, to, incrementUnitAmount, incrementUnitType);
}
}