1 25 package org.snipsnap.util; 26 27 import org.radeox.util.logging.Logger; 28 import org.snipsnap.snip.Snip; 29 30 import java.util.Iterator ; 31 import java.util.LinkedList ; 32 import java.util.List ; 33 34 39 public class Queue { 40 private LinkedList queue; 41 private int size; 42 43 public Queue() { 44 this(100); 45 } 46 47 public Queue(int size) { 48 this.size = size; 49 queue = new LinkedList (); 50 } 51 52 public void fill(List list) { 53 queue.clear(); 54 queue.addAll(list); 55 } 56 57 public Snip add(Snip snip) { 58 Logger.debug("Adding snip="+snip); 59 Logger.debug("Class="+snip.getClass()); 60 Iterator iterator = queue.iterator(); 61 while (iterator.hasNext()) { 62 Snip snip1 = (Snip) iterator.next(); 63 } 64 if (queue.contains(snip)) { 66 queue.remove(snip); 68 } 69 70 if (queue.size() == size) { 72 queue.removeLast(); 73 } 74 queue.addFirst(snip); 75 return snip; 76 } 77 78 public void remove(Snip snip) { 79 queue.remove(snip); 80 } 81 82 public List get() { 83 return (List ) queue; 84 } 85 86 public List get(int count) { 87 count = Math.min(count, queue.size()); 88 return (List ) queue.subList(0, count); 89 } 90 91 } 92 | Popular Tags |