147d431f63a66505a645f282416659a9758a91f1cBrett Chabot/* 247d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Copyright 2001-2009 OFFIS, Tammo Freese 347d431f63a66505a645f282416659a9758a91f1cBrett Chabot * 447d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Licensed under the Apache License, Version 2.0 (the "License"); 547d431f63a66505a645f282416659a9758a91f1cBrett Chabot * you may not use this file except in compliance with the License. 647d431f63a66505a645f282416659a9758a91f1cBrett Chabot * You may obtain a copy of the License at 747d431f63a66505a645f282416659a9758a91f1cBrett Chabot * 847d431f63a66505a645f282416659a9758a91f1cBrett Chabot * http://www.apache.org/licenses/LICENSE-2.0 947d431f63a66505a645f282416659a9758a91f1cBrett Chabot * 1047d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Unless required by applicable law or agreed to in writing, software 1147d431f63a66505a645f282416659a9758a91f1cBrett Chabot * distributed under the License is distributed on an "AS IS" BASIS, 1247d431f63a66505a645f282416659a9758a91f1cBrett Chabot * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1347d431f63a66505a645f282416659a9758a91f1cBrett Chabot * See the License for the specific language governing permissions and 1447d431f63a66505a645f282416659a9758a91f1cBrett Chabot * limitations under the License. 1547d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 1647d431f63a66505a645f282416659a9758a91f1cBrett Chabotpackage org.easymock.internal; 1747d431f63a66505a645f282416659a9758a91f1cBrett Chabot 1847d431f63a66505a645f282416659a9758a91f1cBrett Chabotimport java.io.Serializable; 1947d431f63a66505a645f282416659a9758a91f1cBrett Chabot 2047d431f63a66505a645f282416659a9758a91f1cBrett Chabotpublic class Range implements Serializable { 2147d431f63a66505a645f282416659a9758a91f1cBrett Chabot 2247d431f63a66505a645f282416659a9758a91f1cBrett Chabot private static final long serialVersionUID = -6743402320315331536L; 2347d431f63a66505a645f282416659a9758a91f1cBrett Chabot 2447d431f63a66505a645f282416659a9758a91f1cBrett Chabot private final int minimum; 2547d431f63a66505a645f282416659a9758a91f1cBrett Chabot 2647d431f63a66505a645f282416659a9758a91f1cBrett Chabot private final int maximum; 2747d431f63a66505a645f282416659a9758a91f1cBrett Chabot 2847d431f63a66505a645f282416659a9758a91f1cBrett Chabot public Range(int count) { 2947d431f63a66505a645f282416659a9758a91f1cBrett Chabot this(count, count); 3047d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 3147d431f63a66505a645f282416659a9758a91f1cBrett Chabot 3247d431f63a66505a645f282416659a9758a91f1cBrett Chabot public Range(int minimum, int maximum) { 3347d431f63a66505a645f282416659a9758a91f1cBrett Chabot if (!(minimum <= maximum)) { 3447d431f63a66505a645f282416659a9758a91f1cBrett Chabot throw new RuntimeExceptionWrapper(new IllegalArgumentException( 3547d431f63a66505a645f282416659a9758a91f1cBrett Chabot "minimum must be <= maximum")); 3647d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 3747d431f63a66505a645f282416659a9758a91f1cBrett Chabot 3847d431f63a66505a645f282416659a9758a91f1cBrett Chabot if (!(minimum >= 0)) { 3947d431f63a66505a645f282416659a9758a91f1cBrett Chabot throw new RuntimeExceptionWrapper(new IllegalArgumentException( 4047d431f63a66505a645f282416659a9758a91f1cBrett Chabot "minimum must be >= 0")); 4147d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 4247d431f63a66505a645f282416659a9758a91f1cBrett Chabot 4347d431f63a66505a645f282416659a9758a91f1cBrett Chabot if (!(maximum >= 1)) { 4447d431f63a66505a645f282416659a9758a91f1cBrett Chabot throw new RuntimeExceptionWrapper(new IllegalArgumentException( 4547d431f63a66505a645f282416659a9758a91f1cBrett Chabot "maximum must be >= 1")); 4647d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 4747d431f63a66505a645f282416659a9758a91f1cBrett Chabot this.minimum = minimum; 4847d431f63a66505a645f282416659a9758a91f1cBrett Chabot this.maximum = maximum; 4947d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 5047d431f63a66505a645f282416659a9758a91f1cBrett Chabot 5147d431f63a66505a645f282416659a9758a91f1cBrett Chabot public boolean hasFixedCount() { 5247d431f63a66505a645f282416659a9758a91f1cBrett Chabot return minimum == maximum; 5347d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 5447d431f63a66505a645f282416659a9758a91f1cBrett Chabot 5547d431f63a66505a645f282416659a9758a91f1cBrett Chabot public int getMaximum() { 5647d431f63a66505a645f282416659a9758a91f1cBrett Chabot return maximum; 5747d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 5847d431f63a66505a645f282416659a9758a91f1cBrett Chabot 5947d431f63a66505a645f282416659a9758a91f1cBrett Chabot public int getMinimum() { 6047d431f63a66505a645f282416659a9758a91f1cBrett Chabot return minimum; 6147d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 6247d431f63a66505a645f282416659a9758a91f1cBrett Chabot 6347d431f63a66505a645f282416659a9758a91f1cBrett Chabot @Override 6447d431f63a66505a645f282416659a9758a91f1cBrett Chabot public String toString() { 6547d431f63a66505a645f282416659a9758a91f1cBrett Chabot if (hasFixedCount()) { 6647d431f63a66505a645f282416659a9758a91f1cBrett Chabot return "" + minimum; 6747d431f63a66505a645f282416659a9758a91f1cBrett Chabot } else if (hasOpenCount()) { 6847d431f63a66505a645f282416659a9758a91f1cBrett Chabot return "at least " + minimum; 6947d431f63a66505a645f282416659a9758a91f1cBrett Chabot } else { 7047d431f63a66505a645f282416659a9758a91f1cBrett Chabot return "between " + minimum + " and " + maximum; 7147d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 7247d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 7347d431f63a66505a645f282416659a9758a91f1cBrett Chabot 7447d431f63a66505a645f282416659a9758a91f1cBrett Chabot public String expectedCount() { 7547d431f63a66505a645f282416659a9758a91f1cBrett Chabot return "expected: " + this.toString(); 7647d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 7747d431f63a66505a645f282416659a9758a91f1cBrett Chabot 7847d431f63a66505a645f282416659a9758a91f1cBrett Chabot public boolean contains(int count) { 7947d431f63a66505a645f282416659a9758a91f1cBrett Chabot return minimum <= count && count <= maximum; 8047d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 8147d431f63a66505a645f282416659a9758a91f1cBrett Chabot 8247d431f63a66505a645f282416659a9758a91f1cBrett Chabot public boolean hasOpenCount() { 8347d431f63a66505a645f282416659a9758a91f1cBrett Chabot return maximum == Integer.MAX_VALUE; 8447d431f63a66505a645f282416659a9758a91f1cBrett Chabot } 8547d431f63a66505a645f282416659a9758a91f1cBrett Chabot} 86