/** * Adds an element to a specific index in the list if it is not already present. * <p> * <i>(Violation)</i> * The <code>List</code> interface makes the assumption that the element is * always inserted. This may not happen with this implementation. * * @param index the index to insert at * @param object the object to add */ public void add(int index, Object object) { // adds element if it is not contained already if (set.contains(object) == false) { super.add(index, object); set.add(object); } }
public void clear() { super.clear(); set.clear(); }
public Iterator iterator() { return new SetListIterator(super.iterator(), set); }
/** * Sets the value at the specified index avoiding duplicates. * <p> * The object is set into the specified index. * Afterwards, any previous duplicate is removed * If the object is not already in the list then a normal set occurs. * If it is present, then the old version is removed. * * @param index the index to insert at * @param object the object to set * @return the previous object */ public Object set(int index, Object object) { int pos = indexOf(object); Object removed = super.set(index, object); if (pos != -1 && pos != index) { // the object is already in the unique list // (and it hasn't been swapped with itself) super.remove(pos); // remove the duplicate by index } set.remove(removed); // remove the item deleted by the set set.add(object); // add the new item to the unique set return removed; // return the item deleted by the set }
public boolean remove(Object object) { boolean result = super.remove(object); set.remove(object); return result; }
public ListIterator listIterator() { return new SetListListIterator(super.listIterator(), set); }
public List subList(int fromIndex, int toIndex) { List superSubList = super.subList(fromIndex, toIndex); Set subSet = createSetBasedOnList(set, superSubList); return new SetUniqueList(superSubList, subSet); }
public boolean retainAll(Collection coll) { boolean result = super.retainAll(coll); set.retainAll(coll); return result; }
public boolean removeAll(Collection coll) { boolean result = super.removeAll(coll); set.removeAll(coll); return result; }
/** * Sets the value at the specified index avoiding duplicates. * <p> * The object is set into the specified index. * Afterwards, any previous duplicate is removed * If the object is not already in the list then a normal set occurs. * If it is present, then the old version is removed. * * @param index the index to insert at * @param object the object to set * @return the previous object */ public Object set(int index, Object object) { int pos = indexOf(object); Object removed = super.set(index, object); if (pos != -1 && pos != index) { // the object is already in the unique list // (and it hasn't been swapped with itself) super.remove(pos); // remove the duplicate by index } set.remove(removed); // remove the item deleted by the set set.add(object); // add the new item to the unique set return removed; // return the item deleted by the set }
public Object remove(int index) { Object result = super.remove(index); set.remove(result); return result; }
public ListIterator listIterator(int index) { return new SetListListIterator(super.listIterator(index), set); }
public List subList(int fromIndex, int toIndex) { List superSubList = super.subList(fromIndex, toIndex); Set subSet = createSetBasedOnList(set, superSubList); return new SetUniqueList(superSubList, subSet); }
public boolean retainAll(Collection coll) { boolean result = super.retainAll(coll); set.retainAll(coll); return result; }
public boolean removeAll(Collection coll) { boolean result = super.removeAll(coll); set.removeAll(coll); return result; }
/** * Sets the value at the specified index avoiding duplicates. * <p> * The object is set into the specified index. * Afterwards, any previous duplicate is removed * If the object is not already in the list then a normal set occurs. * If it is present, then the old version is removed. * * @param index the index to insert at * @param object the object to set * @return the previous object */ public Object set(int index, Object object) { int pos = indexOf(object); Object removed = super.set(index, object); if (pos == -1 || pos == index) { return removed; } // the object is already in the uniq list // (and it hasn't been swapped with itself) super.remove(pos); // remove the duplicate by index set.remove(removed); // remove the item deleted by the set return removed; // return the item deleted by the set }
public boolean remove(Object object) { boolean result = super.remove(object); set.remove(object); return result; }
public ListIterator listIterator() { return new SetListListIterator(super.listIterator(), set); }
public List subList(int fromIndex, int toIndex) { return new SetUniqueList(super.subList(fromIndex, toIndex), set); }
public boolean retainAll(Collection coll) { boolean result = super.retainAll(coll); set.retainAll(coll); return result; }