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
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;
13 import java.util.Iterator;
15 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType;
17 public class TypeSetUnion extends TypeSet {
21 public TypeSetUnion(TypeSet lhs, TypeSet rhs) {
22 super(lhs.getTypeSetEnvironment());
28 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#isUniverse()
31 public boolean isUniverse() {
32 if (fLHS.isUniverse() || fRHS.isUniverse())
34 if (fLHS.isSingleton() && fRHS.isSingleton())
36 throw new IllegalStateException("unimplemented"); //$NON-NLS-1$
40 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#makeClone()
43 public TypeSet makeClone() {
44 return new TypeSetUnion(fLHS.makeClone(), fRHS.makeClone());
48 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#isEmpty()
51 public boolean isEmpty() {
52 return fLHS.isEmpty() && fRHS.isEmpty();
56 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#contains(TType)
59 public boolean contains(TType t) {
60 return fLHS.contains(t) || fRHS.contains(t);
64 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#containsAll(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet)
67 public boolean containsAll(TypeSet s) {
68 return fLHS.containsAll(s) || fRHS.containsAll(s);
72 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#anyMember()
75 public TType anyMember() {
76 return fLHS.anyMember();
80 * @see java.lang.Object#equals(java.lang.Object)
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);
92 public int hashCode() {
93 return fLHS.hashCode() * 37 + fRHS.hashCode();
97 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#upperBound()
100 public TypeSet upperBound() {
101 throw new IllegalStateException("unimplemented"); //$NON-NLS-1$
105 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#lowerBound()
108 public TypeSet lowerBound() {
109 throw new IllegalStateException("unimplemented"); //$NON-NLS-1$
113 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#iterator()
116 public Iterator<TType> iterator() {
117 throw new IllegalStateException("unimplemented"); //$NON-NLS-1$
120 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#isSingleton()
123 public boolean isSingleton() {
124 return fLHS.isSingleton() && fRHS.isSingleton() && fLHS.anyMember().equals(fRHS.anyMember());
128 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#hasUniqueLowerBound()
131 public boolean hasUniqueLowerBound() {
136 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#hasUniqueUpperBound()
139 public boolean hasUniqueUpperBound() {
144 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#uniqueLowerBound()
147 public TType uniqueLowerBound() {
152 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#uniqueUpperBound()
155 public TType uniqueUpperBound() {
160 * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#enumerate()
163 public EnumeratedTypeSet enumerate() {
164 EnumeratedTypeSet result= fLHS.enumerate();
166 result.addAll(fRHS.enumerate());
171 public String toString() {
172 return "<" + fID + ": union(" + fLHS + "," + fRHS + ")>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$