Esempio n. 1
0
 /**
  * Get the node with the highest value in the list
  *
  * @return The node with the highest item value
  */
 private DoubleNode<E> highest() {
   DoubleNode<E> highest = head.getNext();
   Iterator<DoubleNode<E>> i = nodeIterator();
   while (i.hasNext()) {
     DoubleNode<E> current = i.next();
     if (current.getValue().compareTo(highest.getValue()) > 0) {
       highest = current;
     }
   }
   return highest;
 }
Esempio n. 2
0
 /**
  * Add an item in rising order
  *
  * @param value The value to be added
  */
 public void add(E value) {
   DoubleNode<E> closest = lowest();
   if (size == 0 || closest.getValue().compareTo(value) > 0) {
     addFirst(value);
     return;
   }
   Iterator<DoubleNode<E>> i = nodeIterator();
   while (i.hasNext()) {
     DoubleNode<E> current = i.next();
     if (current.getValue().compareTo(value) < 0
         && current.getValue().compareTo(closest.getValue()) > 0) {
       closest = current;
     }
   }
   addAfter(closest, value);
 }
Esempio n. 3
0
 /**
  * Remove all items with matching value
  *
  * @param value The value to be removed
  * @return Whether one or more items were removed
  */
 public boolean remove(E value) {
   boolean removed = false;
   Iterator<DoubleNode<E>> i = nodeIterator();
   while (i.hasNext()) {
     DoubleNode<E> current = i.next();
     if (value.equals(current.getValue())) {
       removeNode(current);
       removed = true;
     }
   }
   return removed;
 }