public ISet intersect(ISet other) { ShareableValuesHashSet commonData = new ShareableValuesHashSet(); Iterator<IValue> setIterator; ISet theOtherSet; if (other.size() <= size()) { setIterator = other.iterator(); theOtherSet = this; } else { setIterator = iterator(); theOtherSet = other; } Type newElementType = TypeFactory.getInstance().voidType(); while (setIterator.hasNext()) { IValue value = setIterator.next(); if (theOtherSet.contains(value)) { newElementType = newElementType.lub(value.getType()); commonData.add(value); } } return new SetWriter(newElementType, commonData).done(); }
public ISet insert(IValue value) { if (!contains(value)) { ShareableValuesHashSet newData = new ShareableValuesHashSet(data); newData.add(value); Type type = elementType.lub(value.getType()); return new SetWriter(type, newData).done(); } else { return this; } }
public ISet subtract(ISet other) { ShareableValuesHashSet newData = new ShareableValuesHashSet(data); Iterator<IValue> setIterator = other.iterator(); while (setIterator.hasNext()) { newData.remove(setIterator.next()); } Type newElementType = TypeFactory.getInstance().voidType(); for (IValue el : newData) newElementType = newElementType.lub(el.getType()); return new SetWriter(newElementType, newData).done(); }
public ISet delete(IValue value) { if (contains(value)) { ShareableValuesHashSet newData = new ShareableValuesHashSet(data); newData.remove(value); Type newElementType = TypeFactory.getInstance().voidType(); for (IValue el : newData) { newElementType = newElementType.lub(el.getType()); } return new SetWriter(newElementType, newData).done(); } else { return this; } }
private Set(Type elementType, ShareableValuesHashSet data) { super(); if (data.isEmpty()) this.elementType = voidType; else this.elementType = elementType; this.setType = typeFactory.setType(this.elementType); this.data = data; }
public ISet product(ISet other) { ShareableValuesHashSet newData = new ShareableValuesHashSet(); Type tupleType = typeFactory.tupleType(elementType, other.getElementType()); Iterator<IValue> thisIterator = data.iterator(); while (thisIterator.hasNext()) { IValue left = thisIterator.next(); Iterator<IValue> setIterator = other.iterator(); while (setIterator.hasNext()) { IValue right = setIterator.next(); IValue[] tuple = new IValue[] {left, right}; newData.add(Tuple.newTuple(tupleType, tuple)); } } return new SetWriter(tupleType, newData).done(); }
public ISet union(ISet other) { ShareableValuesHashSet newData; Iterator<IValue> setIterator; Set otherSet = (Set) other; if (otherSet.size() <= size()) { newData = new ShareableValuesHashSet(data); setIterator = otherSet.iterator(); } else { newData = new ShareableValuesHashSet(otherSet.data); setIterator = iterator(); } while (setIterator.hasNext()) { newData.add(setIterator.next()); } Type newElementType = elementType.lub(otherSet.elementType); return new SetWriter(newElementType, newData).done(); }
public boolean isEqual(IValue value) { if (value == this) return true; if (value == null) return false; if (value instanceof Set) { Set otherSet = (Set) value; return data.isEqual(otherSet.data); } else if (value instanceof ISet) { return SetFunctions.isEqual(ValueFactory.getInstance(), this, (ISet) value); } return false; }
public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o.getClass() == getClass()) { Set otherSet = (Set) o; if (getType() != otherSet.getType()) { return false; } return data.equals(otherSet.data); } return false; }
public boolean contains(IValue element) { return data.contains(element); }
public Iterator<IValue> iterator() { return data.iterator(); }
public boolean isEmpty() { return data.isEmpty(); }
public int size() { return data.size(); }
public int hashCode() { return data.hashCode(); }