Ejemplo n.º 1
0
  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();
  }
Ejemplo n.º 2
0
  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;
    }
  }
Ejemplo n.º 3
0
  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();
  }
Ejemplo n.º 4
0
  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;
    }
  }
Ejemplo n.º 5
0
  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;
  }
Ejemplo n.º 6
0
  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();
  }
Ejemplo n.º 7
0
  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();
  }
Ejemplo n.º 8
0
  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;
  }
Ejemplo n.º 9
0
  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;
  }
Ejemplo n.º 10
0
 public boolean contains(IValue element) {
   return data.contains(element);
 }
Ejemplo n.º 11
0
 public Iterator<IValue> iterator() {
   return data.iterator();
 }
Ejemplo n.º 12
0
 public boolean isEmpty() {
   return data.isEmpty();
 }
Ejemplo n.º 13
0
 public int size() {
   return data.size();
 }
Ejemplo n.º 14
0
 public int hashCode() {
   return data.hashCode();
 }