01: // Copyright 2004, 2005 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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 a configuration extension point.
19: *
20: * @author Howard Lewis Ship
21: */
22: public abstract class Occurances {
23: /**
24: * An unbounded number, zero or more.
25: */
26: public static final Occurances UNBOUNDED = new Occurances(
27: "UNBOUNDED") {
28: public boolean inRange(int count) {
29: return true;
30: }
31: };
32:
33: /**
34: * Optional, may be zero or one, but not more.
35: */
36:
37: public static final Occurances OPTIONAL = new Occurances("OPTIONAL") {
38: public boolean inRange(int count) {
39: return count < 2;
40: }
41: };
42:
43: /**
44: * Exactly one is required.
45: */
46:
47: public static final Occurances REQUIRED = new Occurances("REQUIRED") {
48: public boolean inRange(int count) {
49: return count == 1;
50: }
51: };
52:
53: /**
54: * At least one is required.
55: */
56:
57: public static final Occurances ONE_PLUS = new Occurances("ONE_PLUS") {
58: public boolean inRange(int count) {
59: return count > 0;
60: }
61: };
62:
63: public static final Occurances NONE = new Occurances("NONE") {
64: public boolean inRange(int count) {
65: return count == 0;
66: }
67: };
68:
69: private String _name;
70:
71: private Occurances(String name) {
72: _name = name;
73: }
74:
75: public String getName() {
76: return _name;
77: }
78:
79: public String toString() {
80: return "Occurances[" + _name + "]";
81: }
82:
83: /**
84: * Validates that an actual count is in range for the particular Occurances count.
85: *
86: * @param count
87: * the number of items to check. Should be zero or greater.
88: * @return true if count is a valid number in accordance to the range, false otherwise
89: */
90: public abstract boolean inRange(int count);
91:
92: }
|