]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Robert M. Fuhrer (rfuhrer@watson.ibm.com), IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets; | |
12 | ||
13 | import java.util.Iterator; | |
14 | ||
15 | import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType; | |
16 | ||
17 | public class TypeSetUnion extends TypeSet { | |
18 | private TypeSet fLHS; | |
19 | private TypeSet fRHS; | |
20 | ||
21 | public TypeSetUnion(TypeSet lhs, TypeSet rhs) { | |
22 | super(lhs.getTypeSetEnvironment()); | |
23 | fLHS= lhs; | |
24 | fRHS= rhs; | |
25 | } | |
26 | ||
27 | /* (non-Javadoc) | |
28 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#isUniverse() | |
29 | */ | |
30 | @Override | |
31 | public boolean isUniverse() { | |
32 | if (fLHS.isUniverse() || fRHS.isUniverse()) | |
33 | return true; | |
34 | if (fLHS.isSingleton() && fRHS.isSingleton()) | |
35 | return false; | |
36 | throw new IllegalStateException("unimplemented"); //$NON-NLS-1$ | |
37 | } | |
38 | ||
39 | /* (non-Javadoc) | |
40 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#makeClone() | |
41 | */ | |
42 | @Override | |
43 | public TypeSet makeClone() { | |
44 | return new TypeSetUnion(fLHS.makeClone(), fRHS.makeClone()); | |
45 | } | |
46 | ||
47 | /* (non-Javadoc) | |
48 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#isEmpty() | |
49 | */ | |
50 | @Override | |
51 | public boolean isEmpty() { | |
52 | return fLHS.isEmpty() && fRHS.isEmpty(); | |
53 | } | |
54 | ||
55 | /* (non-Javadoc) | |
56 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#contains(TType) | |
57 | */ | |
58 | @Override | |
59 | public boolean contains(TType t) { | |
60 | return fLHS.contains(t) || fRHS.contains(t); | |
61 | } | |
62 | ||
63 | /* (non-Javadoc) | |
64 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#containsAll(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet) | |
65 | */ | |
66 | @Override | |
67 | public boolean containsAll(TypeSet s) { | |
68 | return fLHS.containsAll(s) || fRHS.containsAll(s); | |
69 | } | |
70 | ||
71 | /* (non-Javadoc) | |
72 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#anyMember() | |
73 | */ | |
74 | @Override | |
75 | public TType anyMember() { | |
76 | return fLHS.anyMember(); | |
77 | } | |
78 | ||
79 | /* (non-Javadoc) | |
80 | * @see java.lang.Object#equals(java.lang.Object) | |
81 | */ | |
82 | @Override | |
83 | public boolean equals(Object o) { | |
84 | if (o instanceof TypeSetUnion) { | |
85 | TypeSetUnion other= (TypeSetUnion) o; | |
86 | return other.fLHS.equals(fLHS) && other.fRHS.equals(fRHS); | |
87 | } else | |
88 | return false; | |
89 | } | |
90 | ||
91 | @Override | |
92 | public int hashCode() { | |
93 | return fLHS.hashCode() * 37 + fRHS.hashCode(); | |
94 | } | |
95 | ||
96 | /* (non-Javadoc) | |
97 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#upperBound() | |
98 | */ | |
99 | @Override | |
100 | public TypeSet upperBound() { | |
101 | throw new IllegalStateException("unimplemented"); //$NON-NLS-1$ | |
102 | } | |
103 | ||
104 | /* (non-Javadoc) | |
105 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#lowerBound() | |
106 | */ | |
107 | @Override | |
108 | public TypeSet lowerBound() { | |
109 | throw new IllegalStateException("unimplemented"); //$NON-NLS-1$ | |
110 | } | |
111 | ||
112 | /* (non-Javadoc) | |
113 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#iterator() | |
114 | */ | |
115 | @Override | |
116 | public Iterator<TType> iterator() { | |
117 | throw new IllegalStateException("unimplemented"); //$NON-NLS-1$ | |
118 | } | |
119 | /* (non-Javadoc) | |
120 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#isSingleton() | |
121 | */ | |
122 | @Override | |
123 | public boolean isSingleton() { | |
124 | return fLHS.isSingleton() && fRHS.isSingleton() && fLHS.anyMember().equals(fRHS.anyMember()); | |
125 | } | |
126 | ||
127 | /* (non-Javadoc) | |
128 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#hasUniqueLowerBound() | |
129 | */ | |
130 | @Override | |
131 | public boolean hasUniqueLowerBound() { | |
132 | return false; | |
133 | } | |
134 | ||
135 | /* (non-Javadoc) | |
136 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#hasUniqueUpperBound() | |
137 | */ | |
138 | @Override | |
139 | public boolean hasUniqueUpperBound() { | |
140 | return false; | |
141 | } | |
142 | ||
143 | /* (non-Javadoc) | |
144 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#uniqueLowerBound() | |
145 | */ | |
146 | @Override | |
147 | public TType uniqueLowerBound() { | |
148 | return null; | |
149 | } | |
150 | ||
151 | /* (non-Javadoc) | |
152 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#uniqueUpperBound() | |
153 | */ | |
154 | @Override | |
155 | public TType uniqueUpperBound() { | |
156 | return null; | |
157 | } | |
158 | ||
159 | /* (non-Javadoc) | |
160 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#enumerate() | |
161 | */ | |
162 | @Override | |
163 | public EnumeratedTypeSet enumerate() { | |
164 | EnumeratedTypeSet result= fLHS.enumerate(); | |
165 | ||
166 | result.addAll(fRHS.enumerate()); | |
167 | return result; | |
168 | } | |
169 | ||
170 | @Override | |
171 | public String toString() { | |
172 | return "<" + fID + ": union(" + fLHS + "," + fRHS + ")>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ | |
173 | } | |
174 | } |