package de.animux.android.andmal.util; import java.util.Collection; import java.util.LinkedList; import java.util.ListIterator; public class SortedLinkedList> extends LinkedList { private static final long serialVersionUID = 8263372892230475461L; @Override public boolean add(T object) { ListIterator it = listIterator(); while (it.hasNext()) { if (object.compareTo(it.next()) > 0) { break; } } if (it.hasPrevious()) { it.previous(); it.add(object); } else { // insert at first position listIterator().add(object); } return true; } @Override public boolean addAll(Collection collection) { for (T object : collection) { add(object); } return true; } }