1 /*
2 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
128 throw new IllegalArgumentException("Minimum value must be less than maximum value");
129 }
130 return new ValueRange(min, min, max, max);
131 }
132
133 /**
134 * Obtains a variable value range.
135 * <p>
136 * This factory obtains a range where the minimum value is fixed and the maximum value may vary.
137 * For example, the ISO day-of-month always starts at 1, but ends between 28 and 31.
138 *
139 * @param min the minimum value
140 * @param maxSmallest the smallest maximum value
141 * @param maxLargest the largest maximum value
142 * @return the ValueRange for min, smallest max, largest max, not null
143 * @throws IllegalArgumentException if
144 * the minimum is greater than the smallest maximum,
145 * or the smallest maximum is greater than the largest maximum
146 */
147 public static ValueRange of(long min, long maxSmallest, long maxLargest) {
148 return of(min, min, maxSmallest, maxLargest);
149 }
150
151 /**
152 * Obtains a fully variable value range.
153 * <p>
154 * This factory obtains a range where both the minimum and maximum value may vary.
155 *
156 * @param minSmallest the smallest minimum value
157 * @param minLargest the largest minimum value
158 * @param maxSmallest the smallest maximum value
159 * @param maxLargest the largest maximum value
160 * @return the ValueRange for smallest min, largest min, smallest max, largest max, not null
161 * @throws IllegalArgumentException if
162 * the smallest minimum is greater than the smallest maximum,
163 * or the smallest maximum is greater than the largest maximum
164 * or the largest minimum is greater than the largest maximum
165 */
166 public static ValueRange of(long minSmallest, long minLargest, long maxSmallest, long maxLargest) {
167 if (minSmallest > minLargest) {
168 throw new IllegalArgumentException("Smallest minimum value must be less than largest minimum value");
169 }
170 if (maxSmallest > maxLargest) {
171 throw new IllegalArgumentException("Smallest maximum value must be less than largest maximum value");
172 }
173 if (minLargest > maxLargest) {
174 throw new IllegalArgumentException("Minimum value must be less than maximum value");
175 }
176 return new ValueRange(minSmallest, minLargest, maxSmallest, maxLargest);
177 }
178
179 /**
180 * Restrictive constructor.
181 *
182 * @param minSmallest the smallest minimum value
183 * @param minLargest the largest minimum value
184 * @param maxSmallest the smallest minimum value
185 * @param maxLargest the largest minimum value
186 */
187 private ValueRange(long minSmallest, long minLargest, long maxSmallest, long maxLargest) {
188 this.minSmallest = minSmallest;
189 this.minLargest = minLargest;
190 this.maxSmallest = maxSmallest;
191 this.maxLargest = maxLargest;
192 }
193
194 //-----------------------------------------------------------------------
|
1 /*
2 * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
128 throw new IllegalArgumentException("Minimum value must be less than maximum value");
129 }
130 return new ValueRange(min, min, max, max);
131 }
132
133 /**
134 * Obtains a variable value range.
135 * <p>
136 * This factory obtains a range where the minimum value is fixed and the maximum value may vary.
137 * For example, the ISO day-of-month always starts at 1, but ends between 28 and 31.
138 *
139 * @param min the minimum value
140 * @param maxSmallest the smallest maximum value
141 * @param maxLargest the largest maximum value
142 * @return the ValueRange for min, smallest max, largest max, not null
143 * @throws IllegalArgumentException if
144 * the minimum is greater than the smallest maximum,
145 * or the smallest maximum is greater than the largest maximum
146 */
147 public static ValueRange of(long min, long maxSmallest, long maxLargest) {
148 if (min > maxSmallest) {
149 throw new IllegalArgumentException("Minimum value must be less than smallest maximum value");
150 }
151 return of(min, min, maxSmallest, maxLargest);
152 }
153
154 /**
155 * Obtains a fully variable value range.
156 * <p>
157 * This factory obtains a range where both the minimum and maximum value may vary.
158 *
159 * @param minSmallest the smallest minimum value
160 * @param minLargest the largest minimum value
161 * @param maxSmallest the smallest maximum value
162 * @param maxLargest the largest maximum value
163 * @return the ValueRange for smallest min, largest min, smallest max, largest max, not null
164 * @throws IllegalArgumentException if
165 * the smallest minimum is greater than the smallest maximum,
166 * or the smallest maximum is greater than the largest maximum,
167 * or the largest minimum is greater than the largest maximum,
168 * or the smallest minimum is greater than the largest minimum
169 */
170 public static ValueRange of(long minSmallest, long minLargest, long maxSmallest, long maxLargest) {
171 if (minSmallest > minLargest) {
172 throw new IllegalArgumentException("Smallest minimum value must be less than largest minimum value");
173 }
174 if (maxSmallest > maxLargest) {
175 throw new IllegalArgumentException("Smallest maximum value must be less than largest maximum value");
176 }
177 if (minLargest > maxLargest) {
178 throw new IllegalArgumentException("Largest minimum value must be less than largest maximum value");
179 }
180 if (minSmallest > maxSmallest) {
181 throw new IllegalArgumentException("Smallest minimum value must be less than smallest maximum value");
182 }
183 return new ValueRange(minSmallest, minLargest, maxSmallest, maxLargest);
184 }
185
186 /**
187 * Restrictive constructor.
188 *
189 * @param minSmallest the smallest minimum value
190 * @param minLargest the largest minimum value
191 * @param maxSmallest the smallest minimum value
192 * @param maxLargest the largest minimum value
193 */
194 private ValueRange(long minSmallest, long minLargest, long maxSmallest, long maxLargest) {
195 this.minSmallest = minSmallest;
196 this.minLargest = minLargest;
197 this.maxSmallest = maxSmallest;
198 this.maxLargest = maxLargest;
199 }
200
201 //-----------------------------------------------------------------------
|