01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.sdlctools.types.enterprisemodel;
16:
17: /** Datatype representing cardinality of the selector */
18: public final class AssociationRoleCardinality {
19: /** Constant describing the empty attribute stereotype */
20: public final static AssociationRoleCardinality EMPTY = new AssociationRoleCardinality(
21: "");
22: /** Constant describing the 'singular' cardinality where there can be one and only one associate in the role */
23: public final static AssociationRoleCardinality ONE = new AssociationRoleCardinality(
24: "ONE");
25: /** Constant describing the 'singular' cardinality where there can be zero or one associate in the role */
26: public final static AssociationRoleCardinality ZERO_OR_ONE = new AssociationRoleCardinality(
27: "ZERO_OR_ONE");
28: /** Constant describing the 'plural' cardinality where there can be any number of associates in the role */
29: public final static AssociationRoleCardinality ZERO_TO_MANY = new AssociationRoleCardinality(
30: "ZERO_TO_MANY");
31: /** Constant describing the 'plural' cardinality where there can be one or more associates in the role */
32: public final static AssociationRoleCardinality ONE_TO_MANY = new AssociationRoleCardinality(
33: "ONE_TO_MANY");
34:
35: /** Subset of cardinalities representing all of them */
36: public final static AssociationRoleCardinality[] ALL_CARDINALITIES = new AssociationRoleCardinality[] {
37: ONE, ZERO_OR_ONE, ZERO_TO_MANY, ONE_TO_MANY };
38: /** Subset of cardinalities representing singular ones */
39: public final static AssociationRoleCardinality[] SINGULAR_CARDINALITIES = new AssociationRoleCardinality[] {
40: ONE, ZERO_OR_ONE };
41: /** Subset of cardinalities representing plural ones */
42: public final static AssociationRoleCardinality[] PLURAL_CARDINALITIES = new AssociationRoleCardinality[] {
43: ZERO_TO_MANY, ONE_TO_MANY };
44:
45: /* AssociationRoleCardinality name storage */
46: protected String mValue;
47:
48: /** Creates an instance of the datatype carrying an empty value */
49: public static AssociationRoleCardinality createEmpty() {
50: return EMPTY;
51: }
52:
53: /* Private constructor. Restricts construction from outside */
54: private AssociationRoleCardinality(String pValue) {
55: mValue = pValue;
56: }
57:
58: /** Indicates whether some other object is "equal to" this one
59: * @return true if this object is the same as the obj argument; false otherwise. */
60: public boolean equals(Object pOtherObject) {
61: if (pOtherObject == null)
62: return false;
63: if ((pOtherObject instanceof AssociationRoleCardinality) == false)
64: return false;
65: return ((AssociationRoleCardinality) pOtherObject).mValue
66: .equals(mValue);
67: }
68:
69: /** Returns true if this datatype contains an empty value */
70: public boolean isEmpty() {
71: return this == EMPTY;
72: }
73:
74: /** Returns true if this datatype contains plural cardinality */
75: public boolean isPlural() {
76: return this == ZERO_TO_MANY || this == ONE_TO_MANY;
77: }
78:
79: /** Returns true if this datatype contains singular cardinality */
80: public boolean isSingular() {
81: return this == ONE || this == ZERO_OR_ONE;
82: }
83:
84: /** Returns true if this datatype contains mandatory cardinality */
85: public boolean isMandatory() {
86: return this == ONE || this == ONE_TO_MANY;
87: }
88:
89: /** Returns true if this datatype contains optional cardinality */
90: public boolean isOptional() {
91: return this == ZERO_TO_MANY || this == ZERO_OR_ONE;
92: }
93:
94: /** Returns human readable representation of the value */
95: public String toString() {
96: return mValue;
97: }
98:
99: }
|