|
Lines 1-7
Link Here
|
| 1 |
/** |
1 |
/** |
| 2 |
* <copyright> |
2 |
* <copyright> |
| 3 |
* |
3 |
* |
| 4 |
* Copyright (c) 2002, 2006 IBM Corporation and others. |
4 |
* Copyright (c) 2002, 2007 IBM Corporation and others. |
| 5 |
* All rights reserved. This program and the accompanying materials |
5 |
* All rights reserved. This program and the accompanying materials |
| 6 |
* are made available under the terms of the Eclipse Public License v1.0 |
6 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 7 |
* which accompanies this distribution, and is available at |
7 |
* which accompanies this distribution, and is available at |
|
Lines 17-47
Link Here
|
| 17 |
|
17 |
|
| 18 |
package org.eclipse.emf.query.conditions.eobjects; |
18 |
package org.eclipse.emf.query.conditions.eobjects; |
| 19 |
|
19 |
|
| 20 |
import java.util.ArrayList; |
|
|
| 21 |
import java.util.Collections; |
20 |
import java.util.Collections; |
| 22 |
import java.util.List; |
21 |
import java.util.List; |
| 23 |
|
22 |
|
| 24 |
import org.eclipse.emf.common.util.AbstractEnumerator; |
23 |
import org.eclipse.emf.common.util.Enumerator; |
| 25 |
|
24 |
|
| 26 |
/** |
25 |
/** |
| 27 |
* An enumerator for the kinds of relatioships between EClasses/types. It is |
26 |
* An enumerator for the kinds of relationships between EClasses/types. It is |
| 28 |
* primarily used by <code>EObjectTypeRelationCondition</code> to check for |
27 |
* primarily used by <code>EObjectTypeRelationCondition</code> to check for |
| 29 |
* relations between EObjects |
28 |
* relations between EObjects |
| 30 |
*/ |
29 |
*/ |
| 31 |
public final class TypeRelation |
30 |
public enum TypeRelation |
| 32 |
extends AbstractEnumerator { |
31 |
implements Enumerator { |
| 33 |
|
|
|
| 34 |
private static int valueCounter; |
| 35 |
|
| 36 |
private static final List values = new ArrayList(); |
| 37 |
|
32 |
|
| 38 |
/** |
33 |
/** |
| 39 |
* A <code>TypeRelation</code> enumeration literal used to denote an |
34 |
* A <code>TypeRelation</code> enumeration literal used to denote an |
| 40 |
* undefined relationship between two types which means the two types could |
35 |
* undefined relationship between two types which means the two types could |
| 41 |
* or could not be related at all. |
36 |
* or could not be related at all. |
| 42 |
*/ |
37 |
*/ |
| 43 |
public static final TypeRelation UNDEFINED_LITERAL = new TypeRelation( |
38 |
UNDEFINED_LITERAL("UNDEFINED"), //$NON-NLS-1$ |
| 44 |
"UNDEFINED"); //$NON-NLS-1$ |
|
|
| 45 |
|
39 |
|
| 46 |
/** |
40 |
/** |
| 47 |
* A <code>TypeRelation</code> enumeration literal used to denote the |
41 |
* A <code>TypeRelation</code> enumeration literal used to denote the |
|
Lines 49-56
Link Here
|
| 49 |
* this relationship, in other words, either type could be a parent of |
43 |
* this relationship, in other words, either type could be a parent of |
| 50 |
* another, or they could be the same. |
44 |
* another, or they could be the same. |
| 51 |
*/ |
45 |
*/ |
| 52 |
public static final TypeRelation RELATED_TYPE_LITERAL = new TypeRelation( |
46 |
RELATED_TYPE_LITERAL("RELATED_TYPE"), //$NON-NLS-1$ |
| 53 |
"RELATED_TYPE"); //$NON-NLS-1$ |
|
|
| 54 |
|
47 |
|
| 55 |
/** |
48 |
/** |
| 56 |
* A <code>TypeRelation</code> enumeration literal used to denote the |
49 |
* A <code>TypeRelation</code> enumeration literal used to denote the |
|
Lines 58-128
Link Here
|
| 58 |
* this relationship, in other words, either type should not be a parent of |
51 |
* this relationship, in other words, either type should not be a parent of |
| 59 |
* the other, nor they should be the same. |
52 |
* the other, nor they should be the same. |
| 60 |
*/ |
53 |
*/ |
| 61 |
public static final TypeRelation UNRELATED_TYPE_LITERAL = new TypeRelation( |
54 |
UNRELATED_TYPE_LITERAL("UNRELATED_TYPE"), //$NON-NLS-1$ |
| 62 |
"UNRELATED_TYPE"); //$NON-NLS-1$ |
|
|
| 63 |
|
55 |
|
| 64 |
/** |
56 |
/** |
| 65 |
* A <code>TypeRelation</code> enumeration literal used to denote that two |
57 |
* A <code>TypeRelation</code> enumeration literal used to denote that two |
| 66 |
* types are exactly the same. |
58 |
* types are exactly the same. |
| 67 |
*/ |
59 |
*/ |
| 68 |
public static final TypeRelation SAMETYPE_LITERAL = new TypeRelation( |
60 |
SAMETYPE_LITERAL("SAMETYPE"), //$NON-NLS-1$ |
| 69 |
"SAMETYPE"); //$NON-NLS-1$ |
|
|
| 70 |
|
61 |
|
| 71 |
/** |
62 |
/** |
| 72 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
63 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
| 73 |
* type is a base type of another. |
64 |
* type is a base type of another. |
| 74 |
*/ |
65 |
*/ |
| 75 |
public static final TypeRelation BASETYPE_LITERAL = new TypeRelation( |
66 |
BASETYPE_LITERAL("BASETYPE"), //$NON-NLS-1$ |
| 76 |
"BASETYPE"); //$NON-NLS-1$ |
|
|
| 77 |
|
67 |
|
| 78 |
/** |
68 |
/** |
| 79 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
69 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
| 80 |
* type is a sub type of another. |
70 |
* type is a sub type of another. |
| 81 |
*/ |
71 |
*/ |
| 82 |
public static final TypeRelation SUBTYPE_LITERAL = new TypeRelation( |
72 |
SUBTYPE_LITERAL("SUBTYPE"), //$NON-NLS-1$ |
| 83 |
"SUBTYPE"); //$NON-NLS-1$ |
|
|
| 84 |
|
73 |
|
| 85 |
/** |
74 |
/** |
| 86 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
75 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
| 87 |
* type is a direct super type of another. |
76 |
* type is a direct super type of another. |
| 88 |
*/ |
77 |
*/ |
| 89 |
public static final TypeRelation DIRECT_BASETYPE_LITERAL = new TypeRelation( |
78 |
DIRECT_BASETYPE_LITERAL("DIRECT_BASETYPE"), //$NON-NLS-1$ |
| 90 |
"DIRECT_BASETYPE"); //$NON-NLS-1$ |
|
|
| 91 |
|
79 |
|
| 92 |
/** |
80 |
/** |
| 93 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
81 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
| 94 |
* type is a direct sub type of another. |
82 |
* type is a direct sub type of another. |
| 95 |
*/ |
83 |
*/ |
| 96 |
public static final TypeRelation DIRECT_SUBTYPE_LITERAL = new TypeRelation( |
84 |
DIRECT_SUBTYPE_LITERAL("DIRECT_SUBTYPE"), //$NON-NLS-1$ |
| 97 |
"DIRECT_SUBTYPE"); //$NON-NLS-1$ |
|
|
| 98 |
|
85 |
|
| 99 |
/** |
86 |
/** |
| 100 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
87 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
| 101 |
* type is either the same or a direct sub type of another. |
88 |
* type is either the same or a direct sub type of another. |
| 102 |
*/ |
89 |
*/ |
| 103 |
public static final TypeRelation SAMETYPE_OR_DIRECT_SUBTYPE_LITERAL = new TypeRelation( |
90 |
SAMETYPE_OR_DIRECT_SUBTYPE_LITERAL("SAMETYPE_OR_DIRECT_SUBTYPE"), //$NON-NLS-1$ |
| 104 |
"SAMETYPE_OR_DIRECT_SUBTYPE"); //$NON-NLS-1$ |
|
|
| 105 |
|
91 |
|
| 106 |
/** |
92 |
/** |
| 107 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
93 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
| 108 |
* type is either the same or a direct base type of another. |
94 |
* type is either the same or a direct base type of another. |
| 109 |
*/ |
95 |
*/ |
| 110 |
public static final TypeRelation SAMETYPE_OR_DIRECT_BASETYPE_LITERAL = new TypeRelation( |
96 |
SAMETYPE_OR_DIRECT_BASETYPE_LITERAL("SAMETYPE_OR_DIRECT_BASETYPE"), //$NON-NLS-1$ |
| 111 |
"SAMETYPE_OR_DIRECT_BASETYPE"); //$NON-NLS-1$ |
|
|
| 112 |
|
97 |
|
| 113 |
/** |
98 |
/** |
| 114 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
99 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
| 115 |
* type is either the same or a sub type of another. |
100 |
* type is either the same or a sub type of another. |
| 116 |
*/ |
101 |
*/ |
| 117 |
public static final TypeRelation SAMETYPE_OR_SUBTYPE_LITERAL = new TypeRelation( |
102 |
SAMETYPE_OR_SUBTYPE_LITERAL("SAMETYPE_OR_SUBTYPE"), //$NON-NLS-1$ |
| 118 |
"SAMETYPE_OR_SUBTYPE"); //$NON-NLS-1$ |
|
|
| 119 |
|
103 |
|
| 120 |
/** |
104 |
/** |
| 121 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
105 |
* A <code>TypeRelation</code> enumeration literal used to denote that one |
| 122 |
* type is either the same or a super type of another. |
106 |
* type is either the same or a super type of another. |
| 123 |
*/ |
107 |
*/ |
| 124 |
public static final TypeRelation SAMETYPE_OR_BASETYPE_LITERAL = new TypeRelation( |
108 |
SAMETYPE_OR_BASETYPE_LITERAL("SAMETYPE_OR_BASETYPE"); //$NON-NLS-1$ |
| 125 |
"SAMETYPE_OR_BASETYPE"); //$NON-NLS-1$ |
|
|
| 126 |
|
109 |
|
| 127 |
/** |
110 |
/** |
| 128 |
* The integer value of the UNDEFINED_LITERAL <code>TypeRelation</code> |
111 |
* The integer value of the UNDEFINED_LITERAL <code>TypeRelation</code> |
|
Lines 201-217
Link Here
|
| 201 |
public static final int SAMETYPE_OR_BASETYPE = SAMETYPE_OR_BASETYPE_LITERAL |
184 |
public static final int SAMETYPE_OR_BASETYPE = SAMETYPE_OR_BASETYPE_LITERAL |
| 202 |
.getValue(); |
185 |
.getValue(); |
| 203 |
|
186 |
|
|
|
187 |
private static final List<TypeRelation> values = java.util.Arrays.asList(values()); |
| 188 |
|
| 204 |
/** |
189 |
/** |
| 205 |
* An immutable list of the enumeration literals declared by this enumerator |
190 |
* An immutable list of the enumeration literals declared by this enumerator |
| 206 |
*/ |
191 |
*/ |
| 207 |
public static final List VALUES = Collections.unmodifiableList(values); |
192 |
public static final List<TypeRelation> VALUES = Collections.unmodifiableList(values); |
| 208 |
|
|
|
| 209 |
private static final TypeRelation[] VALUES_ARRAY = (TypeRelation[]) VALUES |
| 210 |
.toArray(new TypeRelation[VALUES.size()]); |
| 211 |
|
193 |
|
|
|
194 |
private final String name; |
| 195 |
|
| 212 |
private TypeRelation(String name) { |
196 |
private TypeRelation(String name) { |
| 213 |
super(valueCounter++, name); |
197 |
this.name = name; |
| 214 |
values.add(this); |
|
|
| 215 |
} |
198 |
} |
| 216 |
|
199 |
|
| 217 |
/** |
200 |
/** |
|
Lines 221-234
Link Here
|
| 221 |
* @param value |
204 |
* @param value |
| 222 |
* An integer representing the value of a |
205 |
* An integer representing the value of a |
| 223 |
* <code>TypeRelation</code> enumeration literal |
206 |
* <code>TypeRelation</code> enumeration literal |
| 224 |
* @return TypeRelation the <code>TypeRelation</code> having this name or |
207 |
* @return the <code>TypeRelation</code> having this name or |
| 225 |
* null if the name is not recognised |
208 |
* null if the name is not recognized |
| 226 |
*/ |
209 |
*/ |
| 227 |
public static TypeRelation get(int value) { |
210 |
public static TypeRelation get(int value) { |
| 228 |
if (value >= VALUES_ARRAY.length || value < 0) { |
211 |
if (value >= VALUES.size() || value < 0) { |
| 229 |
return null; |
212 |
return null; |
| 230 |
} |
213 |
} |
| 231 |
return VALUES_ARRAY[value]; |
214 |
return VALUES.get(value); |
| 232 |
} |
215 |
} |
| 233 |
|
216 |
|
| 234 |
/** |
217 |
/** |
|
Lines 238-250
Link Here
|
| 238 |
* @param name |
221 |
* @param name |
| 239 |
* A string representing the name of a <code>TypeRelation</code> |
222 |
* A string representing the name of a <code>TypeRelation</code> |
| 240 |
* enumeration literal |
223 |
* enumeration literal |
| 241 |
* @return TypeRelation the <code>TypeRelation</code> having this name or |
224 |
* @return the <code>TypeRelation</code> having this name or |
| 242 |
* <code>null</code> if the name is not recognised |
225 |
* <code>null</code> if the name is not recognized |
| 243 |
*/ |
226 |
*/ |
| 244 |
public static TypeRelation get(String name) { |
227 |
public static TypeRelation get(String name) { |
| 245 |
for (int i = 0; i < VALUES_ARRAY.length; ++i) { |
228 |
for (TypeRelation next : VALUES) { |
| 246 |
if (VALUES_ARRAY[i].getName().equals(name)) { |
229 |
if (next.getName().equals(name)) { |
| 247 |
return VALUES_ARRAY[i]; |
230 |
return next; |
| 248 |
} |
231 |
} |
| 249 |
} |
232 |
} |
| 250 |
return null; |
233 |
return null; |
|
Lines 253-264
Link Here
|
| 253 |
/** |
236 |
/** |
| 254 |
* Answers how many enumeration literals declared by this enumerator. |
237 |
* Answers how many enumeration literals declared by this enumerator. |
| 255 |
* |
238 |
* |
| 256 |
* @return int The total count of all enumeration literals declared by this |
239 |
* @return The total count of all enumeration literals declared by this |
| 257 |
* enumerator |
240 |
* enumerator |
| 258 |
*/ |
241 |
*/ |
| 259 |
public static int getTotalCount() { |
242 |
public static int getTotalCount() { |
| 260 |
return VALUES_ARRAY.length; |
243 |
return VALUES.size(); |
| 261 |
} |
244 |
} |
| 262 |
|
245 |
|
|
|
246 |
public String getLiteral() { |
| 247 |
return getName(); |
| 248 |
} |
| 249 |
|
| 250 |
public String getName() { |
| 251 |
return name; |
| 252 |
} |
| 253 |
|
| 254 |
public int getValue() { |
| 255 |
return ordinal(); |
| 256 |
} |
| 263 |
} |
257 |
} |
| 264 |
|
258 |
|