1 | /* |
2 | * Copyright 2006-2007 the original author or authors. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | |
17 | package org.springframework.batch.item.file.transform; |
18 | |
19 | import org.springframework.util.Assert; |
20 | |
21 | /** |
22 | * A class to represent ranges. A Range can have minimum/maximum values from |
23 | * interval <1,Integer.MAX_VALUE-1> A Range can be unbounded at maximum |
24 | * side. This can be specified by passing {@link Range#UPPER_BORDER_NOT_DEFINED}} as max |
25 | * value or using constructor {@link #Range(int)}. |
26 | * |
27 | * @author peter.zozom |
28 | */ |
29 | public class Range { |
30 | |
31 | public final static int UPPER_BORDER_NOT_DEFINED = Integer.MAX_VALUE; |
32 | |
33 | final private int min; |
34 | final private int max; |
35 | |
36 | public Range(int min) { |
37 | this(min,UPPER_BORDER_NOT_DEFINED); |
38 | } |
39 | |
40 | public Range(int min, int max) { |
41 | checkMinMaxValues(min, max); |
42 | this.min = min; |
43 | this.max = max; |
44 | } |
45 | |
46 | public int getMax() { |
47 | return max; |
48 | } |
49 | |
50 | public int getMin() { |
51 | return min; |
52 | } |
53 | |
54 | public boolean hasMaxValue() { |
55 | return max != UPPER_BORDER_NOT_DEFINED; |
56 | } |
57 | |
58 | public String toString() { |
59 | return hasMaxValue() ? min + "-" + max : String.valueOf(min); |
60 | } |
61 | |
62 | private void checkMinMaxValues(int min, int max) { |
63 | Assert.isTrue(min>0, "Min value must be higher than zero"); |
64 | Assert.isTrue(min<=max, "Min value should be lower or equal to max value"); |
65 | } |
66 | } |