KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > definition > Occurances


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.definition;
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     /**
25      * An unbounded number, zero or more.
26      */

27     public static final Occurances UNBOUNDED = new Occurances("UNBOUNDED")
28     {
29         public boolean inRange(int count)
30         {
31             return true;
32         }
33     };
34
35     /**
36      * Optional, may be zero or one, but not more.
37      */

38
39     public static final Occurances OPTIONAL = new Occurances("OPTIONAL")
40     {
41         public boolean inRange(int count)
42         {
43             return count < 2;
44         }
45     };
46
47     /**
48      * Exactly one is required.
49      */

50
51     public static final Occurances REQUIRED = new Occurances("REQUIRED")
52     {
53         public boolean inRange(int count)
54         {
55             return count == 1;
56         }
57     };
58
59     /**
60      * At least one is required.
61      */

62
63     public static final Occurances ONE_PLUS = new Occurances("ONE_PLUS")
64     {
65         public boolean inRange(int count)
66         {
67             return count > 0;
68         }
69     };
70
71     public static final Occurances NONE = new Occurances("NONE")
72     {
73         public boolean inRange(int count)
74         {
75             return count == 0;
76         }
77     };
78
79     private String JavaDoc _name;
80
81     private Occurances(String JavaDoc name)
82     {
83         _name = name;
84     }
85
86     public String JavaDoc getName()
87     {
88         return _name;
89     }
90
91     public String JavaDoc toString()
92     {
93         return "Occurances[" + _name + "]";
94     }
95
96     /**
97      * Validates that an actual count is in range for the particular Occurances count.
98      *
99      * @param count
100      * the number of items to check. Should be zero or greater.
101      * @return true if count is a valid number in accordance to the range, false otherwise
102      */

103     public abstract boolean inRange(int count);
104
105 }
Popular Tags