All pastes #219377 Raw Edit

Anonymous

public text v1 · immutable
#219377 ·published 2006-10-24 17:27 UTC
rendered paste body
public 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
    }