Anonymous
public text v1 · immutablepublic boolean insert(E x) {
E newE = find(x);
if(!duplicates && newE == x) // Is there an item matching?
return false; // Yep, and duplicates aren't allowed
ListIterator<E> it = theList.listIterator();
while(it.hasNext()) {
E myObject = it.next();
if (x.compareTo(myObject) <= 0) {
it.previous(); // Required, otherwise it will be place+1...
break;
}
}
it.add(x); // Insert the item in the list at the correct place
return true; // Item entered
}