1 package xdoclet.sdk.xgg.binding;
2
3
4 /***
5 * Holder for the fine grained cardinality of a Child.
6 *
7 * @author <a href="mailto:letiemble at users.sourceforge.net">Laurent Etiemble</a>
8 * @created 6 mai 2003
9 * @version $Revision: 1.1 $
10 */
11 public class Cardinality {
12 private int _max;
13 private int _min;
14
15 /***Constant for ONE cardinality. Used for min and max cardinality. */
16 public final static int ONE = 1;
17 /*** Constant for UNBOUNDED cardinality. Used for max cardinality. */
18 public final static int UNBOUNDED = -1;
19 /*** Constant for ZERO cardinality. Used for min cardinality. */
20 public final static int ZERO = 0;
21
22
23 /***
24 * Constructor for the Cardinality object
25 *
26 * @param min Minimum cardinality
27 * @param max Maximum cardinality
28 */
29 public Cardinality(int min, int max) {
30 _min = min;
31 _max = max;
32 }
33
34
35 /***
36 * Gets the maximum cardinality
37 *
38 * @return The maximum cardinality
39 */
40 public int getMax() {
41 return _max;
42 }
43
44
45 /***
46 * Gets the minimum cardinality
47 *
48 * @return The minimum cardinality
49 */
50 public int getMin() {
51 return _min;
52 }
53
54
55 /***
56 * Return whether or not the maximum cardinality is higher than ONE
57 *
58 * @return True if the maximum cardinality is higher than ONE
59 */
60 public boolean isMany() {
61 return (_max == Cardinality.UNBOUNDED) || (_max > Cardinality.ONE);
62 }
63
64
65 /*** Make sure the maximum cardinality is always greater or equal than the minimum cardinality */
66 public void normalize() {
67 if ((_max != Cardinality.UNBOUNDED) && (_min > _max)) {
68 _max = _min;
69 }
70 }
71
72
73 /***
74 * Sets the maximum cardinality
75 *
76 * @param max The maximum cardinality
77 */
78 public void setMax(int max) {
79 this._max = max;
80 }
81
82
83
84 /***
85 * Sets the minimum cardinality
86 *
87 * @param min The minimum cardinality
88 */
89 public void setMin(int min) {
90 this._min = min;
91 }
92
93
94 /***
95 * Implementation of the toString method
96 *
97 * @return String representation
98 */
99 public String toString() {
100 StringBuffer buffer = new StringBuffer();
101
102 buffer.append("(");
103 buffer.append(_min);
104 buffer.append("..");
105 if (_max == Cardinality.UNBOUNDED) {
106 buffer.append("*");
107 } else {
108 buffer.append(_max);
109 }
110 buffer.append(")");
111
112 return buffer.toString();
113 }
114 }
This page was automatically generated by Maven