|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Occurances.java | - | 100% | 100% | 100% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.hivemind;
|
|
16 |
|
|
17 |
/**
|
|
18 |
* Identifies the number of contributions allowed to
|
|
19 |
* a configuration extension point.
|
|
20 |
*
|
|
21 |
* @author Howard Lewis Ship
|
|
22 |
*/
|
|
23 |
public abstract class Occurances |
|
24 |
{ |
|
25 |
/**
|
|
26 |
* An unbounded number, zero or more.
|
|
27 |
*/
|
|
28 |
public static final Occurances UNBOUNDED = new Occurances("UNBOUNDED") |
|
29 |
{ |
|
30 | 868 |
public boolean inRange(int count) |
31 |
{ |
|
32 | 868 |
return true; |
33 |
} |
|
34 |
}; |
|
35 |
|
|
36 |
/**
|
|
37 |
* Optional, may be zero or one, but not more.
|
|
38 |
*/
|
|
39 |
|
|
40 |
public static final Occurances OPTIONAL = new Occurances("OPTIONAL") |
|
41 |
{ |
|
42 | 4 |
public boolean inRange(int count) |
43 |
{ |
|
44 | 4 |
return count < 2;
|
45 |
} |
|
46 |
}; |
|
47 |
|
|
48 |
/**
|
|
49 |
* Exactly one is required.
|
|
50 |
*/
|
|
51 |
|
|
52 |
public static final Occurances REQUIRED = new Occurances("REQUIRED") |
|
53 |
{ |
|
54 | 393 |
public boolean inRange(int count) |
55 |
{ |
|
56 | 393 |
return count == 1;
|
57 |
} |
|
58 |
}; |
|
59 |
|
|
60 |
/**
|
|
61 |
* At least one is required.
|
|
62 |
*/
|
|
63 |
|
|
64 |
public static final Occurances ONE_PLUS = new Occurances("ONE_PLUS") |
|
65 |
{ |
|
66 | 13 |
public boolean inRange(int count) |
67 |
{ |
|
68 | 13 |
return count > 0;
|
69 |
} |
|
70 |
}; |
|
71 |
|
|
72 |
public static final Occurances NONE = new Occurances("NONE") |
|
73 |
{ |
|
74 | 2 |
public boolean inRange(int count) |
75 |
{ |
|
76 | 2 |
return count == 0;
|
77 |
} |
|
78 |
}; |
|
79 |
|
|
80 |
private String _name;
|
|
81 |
|
|
82 | 5 |
private Occurances(String name)
|
83 |
{ |
|
84 | 5 |
_name = name; |
85 |
} |
|
86 |
|
|
87 | 4 |
public String getName()
|
88 |
{ |
|
89 | 4 |
return _name;
|
90 |
} |
|
91 |
|
|
92 | 2 |
public String toString()
|
93 |
{ |
|
94 | 2 |
return "Occurances[" + _name + "]"; |
95 |
} |
|
96 |
|
|
97 |
/**
|
|
98 |
* Validates that an actual count is in range for the particular Occurances count.
|
|
99 |
*
|
|
100 |
* @param count the number of items to check. Should be zero or greater.
|
|
101 |
* @returns true if count is a valid number in accordance to the range, false otherwise
|
|
102 |
*/
|
|
103 |
public abstract boolean inRange(int count); |
|
104 |
|
|
105 |
} |
|
106 |
|
|