package sets; import java.util.LinkedList; import java.util.Iterator; public class ListSet<E> implements Set<E>{ private LinkedList <E> body; public ListSet () { body = new LinkedList<E>(); } /* * Adds the specified element to this set if it is not * already present (optional operation). More formally, * adds the specified element e to this set if the set contains * no element e2 such that (e==null ? e2==null : e.equals(e2)). * If this set already contains the element, the call leaves * the set unchanged and returns false. * In combination with the restriction on constructors, * this ensures that sets never contain duplicate elements. */ public boolean add(E e) { throw new UnsupportedOperationException(); } /* * Removes all of the elements from this set (optional operation). * The set will be empty after this call returns. */ public void clear() { throw new UnsupportedOperationException(); } /* * Returns a clone of this set. The copy will contain a reference * to a clone of the internal vector, not a reference to the original internal vector * of this Set object. */ public Object clone() { ListSet<E> result = null; try { result = (ListSet<E>)super.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } result.body = (LinkedList<E>)body.clone(); return result; } /* * Returns true if this set contains the specified element. * More formally, returns true if and only if this set contains an element * e such that (o==null ? e==null : o.equals(e)). */ public boolean contains(E e) { throw new UnsupportedOperationException(); } /* * Returns the difference of this set and the other set. */ public Set<E> difference(Set<E> other) { throw new UnsupportedOperationException(); } /* * Compares the specified object with this set for equality. * Returns true if the specified object is also a set, the two sets * have the same size, and every member of the specified set is contained in this set * (or equivalently, every member of this set is contained in the specified set). * This definition ensures that the equals method works properly across different * implementations of the set interface. */ public boolean equals(Object o) { if(o == null) return false; if(this == o) return true; if(!(o instanceof ListSet)) return false; ListSet<E> other = (ListSet<E>)o; return this.isSubsetOf(other) && other.isSubsetOf(this); } /* * Returns the intersection of this set and the other set. */ public Set<E> intersection(Set<E> other) { throw new UnsupportedOperationException(); } /* * Returns true if this set contains no elements. */ public boolean isEmpty() { throw new UnsupportedOperationException(); } /* * Returns true if this set is a subset of the other set. */ public boolean isSubsetOf(Set<E> other) { throw new UnsupportedOperationException(); } /* * Returns an iterator over the elements in this set. * The elements are returned in no particular order * (unless this set is an instance of some class that provides a guarantee). */ public Iterator<E> iterator() { return body.iterator(); } /* * Removes the specified element from this set if it is present * (optional operation). More formally, removes an element e such * that (o==null ? e==null : o.equals(e)), if this set contains such an element. * Returns true if this set contained the element (or equivalently, * if this set changed as a result of the call). (This set will not contain the element * once the call returns.) */ public boolean remove(E e) { throw new UnsupportedOperationException(); } /* * Returns the number of elements in this set (its cardinality). * If this set contains more than Integer.MAX_VALUE elements, * returns Integer.MAX_VALUE */ public int size() { throw new UnsupportedOperationException(); } /* * Returns the symmetric difference of this set and the other set. */ public Set<E> symDifference(Set<E> other) { throw new UnsupportedOperationException(); } /* * Returns an array containing all of the elements in this set. * If this set makes any guarantees as to what order its elements * are returned by its iterator, this method must return the elements * in the same order. */ public Object[] toArray() { throw new UnsupportedOperationException(); } /* * Overrides java.lang.Object.toString() */ public String toString() { StringBuffer stb = new StringBuffer("[ "); if(!isEmpty()) { Iterator<E> it = iterator(); while(it.hasNext()) stb.append(it.next().toString() + " ; "); stb.delete(stb.length()-2, stb.length()-1); } stb.append("]"); return stb.toString(); } /* * Returns the union of this set and the other set. */ public Set<E> union(Set<E> other) { throw new UnsupportedOperationException(); } }