1 24 package org.archive.queue; 25 26 import java.util.Iterator ; 27 import java.util.LinkedList ; 28 29 import org.apache.commons.collections.Predicate; 30 31 36 public class MemQueue<T> extends LinkedList <T> implements Queue<T> { 37 38 private static final long serialVersionUID = -9077824759011044247L; 39 40 42 public MemQueue() { 43 super(); 44 } 45 46 49 public void enqueue(T o) { 50 add(o); 51 } 52 53 56 public T dequeue() { 57 return removeFirst(); 58 } 59 60 63 public long length() { 64 return size(); 65 } 66 67 70 public void release() { 71 } 73 74 77 public T peek() { 78 return getFirst(); 79 } 80 81 82 85 public Iterator <T> getIterator(boolean inCacheOnly) { 86 return listIterator(); 87 } 88 89 92 public long deleteMatchedItems(Predicate matcher) { 93 Iterator <T> it = listIterator(); 94 long numberOfDeletes = 0; 95 while(it.hasNext()){ 96 if(matcher.evaluate(it.next())){ 97 it.remove(); 98 numberOfDeletes++; 99 } 100 } 101 return numberOfDeletes; 102 } 103 104 107 public void unpeek() { 108 } 110 111 112 113 } 114 | Popular Tags |