KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > easymock > internal > Range


1 /*
2  * Copyright (c) 2001-2005 OFFIS. This program is made available under the terms of
3  * the MIT License.
4  */

5 package org.easymock.internal;
6
7 public class Range {
8     private int minimum;
9
10     private int maximum;
11
12     public Range(int count) {
13         this(count, count);
14     }
15
16     public Range(int minimum, int maximum) {
17         if (!(minimum <= maximum)) {
18             throw new RuntimeExceptionWrapper(new IllegalArgumentException JavaDoc(
19                     "minimum must be <= maximum"));
20         }
21
22         if (!(minimum >= 0)) {
23             throw new RuntimeExceptionWrapper(new IllegalArgumentException JavaDoc(
24                     "minimum must be >= 0"));
25         }
26
27         if (!(maximum >= 1)) {
28             throw new RuntimeExceptionWrapper(new IllegalArgumentException JavaDoc(
29                     "maximum must be >= 1"));
30         }
31         this.minimum = minimum;
32         this.maximum = maximum;
33     }
34
35     boolean hasFixedCount() {
36         return minimum == maximum;
37     }
38
39     int getMaximum() {
40         return maximum;
41     }
42
43     int getMinimum() {
44         return minimum;
45     }
46
47     public String JavaDoc toString() {
48         if (hasFixedCount()) {
49             return "" + minimum;
50         } else if (hasOpenCount()) {
51             return "at least " + minimum;
52         } else {
53             return "between " + minimum + " and " + maximum;
54         }
55     }
56
57     public String JavaDoc expectedAndActual(int count) {
58         return "expected: " + this.toString() + ", actual: " + count;
59     }
60
61     boolean contains(int count) {
62         return minimum <= count && count <= maximum;
63     }
64
65     boolean hasOpenCount() {
66         return maximum == Integer.MAX_VALUE;
67     }
68 }
69
Popular Tags