Exemplo n.º 1
0
 /**
  * Moves the element in front.
  *
  * <p>Could also be implemented as remove() and push(), but explicitely coding might be a bit
  * faster.
  *
  * @param element the entry to move in front.
  */
 public synchronized void moveFirst(final Entry element) {
   if (element.getValid() && element.getPrevious() != null) {
     Entry prev = element.getPrevious();
     Entry next = element.getNext();
     prev.setNext(next);
     if (next != null) {
       next.setPrevious(prev);
     } else {
       last = prev;
     }
     first.setPrevious(element);
     element.setNext(first);
     element.setPrevious(null);
     first = element;
   }
 }
Exemplo n.º 2
0
 /**
  * Moves the element to the back.
  *
  * <p>Could also be implemented as remove() and unpop(), but explicitely coding might be a bit
  * faster.
  *
  * @param element the entry to move to the back.
  */
 public synchronized void moveLast(final Entry element) {
   if (element.getValid() && element.getNext() != null) {
     Entry next = element.getNext();
     Entry prev = element.getPrevious();
     next.setPrevious(prev);
     if (prev != null) {
       prev.setNext(next);
     } else {
       first = next;
     }
     last.setNext(element);
     element.setPrevious(last);
     element.setNext(null);
     last = element;
   }
 }
Exemplo n.º 3
0
 /**
  * Removes the last element of the list and returns its content.
  *
  * @return the content of the last element of the list.
  */
 public synchronized T pop() {
   T content = null;
   if (last != null) {
     Entry element = last;
     last = last.getPrevious();
     content = element.getContent();
     if (last == null) {
       first = null;
     } else {
       last.setNext(null);
     }
     size--;
     element.invalidate();
   }
   return content;
 }
Exemplo n.º 4
0
 /**
  * Removes any element of the list and returns its content.
  *
  * @param element The element to remove
  */
 public synchronized void remove(final Entry element) {
   if (element == null || !element.getValid()) {
     return;
   }
   Entry next = element.getNext();
   Entry prev = element.getPrevious();
   if (next != null) {
     next.setPrevious(prev);
   } else {
     last = prev;
   }
   if (prev != null) {
     prev.setNext(next);
   } else {
     first = next;
   }
   size--;
   element.invalidate();
 }