1 11 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.core.runtime.Assert; 16 17 18 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType; 19 20 public class SingletonTypeSet extends TypeSet { 21 private final TType fType; 22 23 24 public SingletonTypeSet(TType t, TypeSetEnvironment typeSetEnvironment) { 26 super(typeSetEnvironment); 27 Assert.isNotNull(t); 28 fType= t; 29 } 30 31 34 public boolean isUniverse() { 35 return false; 36 } 37 38 41 public TypeSet makeClone() { 42 return this; } 44 45 48 protected TypeSet specialCasesIntersectedWith(TypeSet s2) { 49 if (s2.contains(fType)) 50 return this; 51 else 52 return getTypeSetEnvironment().getEmptyTypeSet(); 53 } 54 55 58 public boolean isEmpty() { 59 return false; 60 } 61 62 65 public TypeSet upperBound() { 66 return this; } 68 69 72 public TypeSet lowerBound() { 73 return this; } 75 76 79 public boolean hasUniqueLowerBound() { 80 return true; 81 } 82 83 86 public boolean hasUniqueUpperBound() { 87 return true; 88 } 89 90 93 public TType uniqueLowerBound() { 94 return fType; 95 } 96 97 100 public TType uniqueUpperBound() { 101 return fType; 102 } 103 104 107 public boolean contains(TType t) { 108 return fType.equals(t); 109 } 110 111 114 public boolean containsAll(TypeSet s) { 115 if (s.isEmpty()) 116 return true; 117 if (s.isSingleton()) 118 return s.anyMember().equals(fType); 119 return false; 120 } 121 122 125 public Iterator iterator() { 126 return new Iterator () { 127 private boolean done= false; 128 public void remove() { 129 throw new UnsupportedOperationException (); 130 } 131 public boolean hasNext() { 132 return !done; 133 } 134 public Object next() { 135 done= true; 136 return fType; 137 } 138 }; 139 } 140 141 144 public boolean isSingleton() { 145 return true; 146 } 147 148 151 public TType anyMember() { 152 return fType; 153 } 154 155 158 public EnumeratedTypeSet enumerate() { 159 EnumeratedTypeSet enumeratedTypeSet= new EnumeratedTypeSet(fType, getTypeSetEnvironment()); 160 enumeratedTypeSet.initComplete(); 161 return enumeratedTypeSet; 162 } 163 164 public boolean equals(Object o) { 165 if (o instanceof SingletonTypeSet) { 166 SingletonTypeSet other= (SingletonTypeSet) o; 167 168 return fType.equals(other.fType); 169 } else if (o instanceof TypeSet) { 170 TypeSet other= (TypeSet) o; 171 172 return other.isSingleton() && other.anyMember().equals(fType); 173 } else 174 return false; 175 } 176 177 public String toString() { 178 return "{" + fID + ": " + fType.getPrettySignature() + "}"; } 180 } 181 | Popular Tags |