I know about SortedSet, but in my case I need something that implements List, and not Set. So is there an implementation out there, in the API or e
So here's what I did eventually. I hope this helps someone else.
class NoDuplicatesList extends LinkedList {
@Override
public boolean add(E e) {
if (this.contains(e)) {
return false;
}
else {
return super.add(e);
}
}
@Override
public boolean addAll(Collection extends E> collection) {
Collection copy = new LinkedList(collection);
copy.removeAll(this);
return super.addAll(copy);
}
@Override
public boolean addAll(int index, Collection extends E> collection) {
Collection copy = new LinkedList(collection);
copy.removeAll(this);
return super.addAll(index, copy);
}
@Override
public void add(int index, E element) {
if (this.contains(element)) {
return;
}
else {
super.add(index, element);
}
}
}