1 25 package org.snipsnap.util; 26 27 import java.util.LinkedList ; 28 import java.util.List ; 29 30 35 public class WeblogQueue { 36 private LinkedList queue; 37 private int size; 38 39 public WeblogQueue(int size) { 40 this.size = size; 41 queue = new LinkedList (); 42 } 43 44 public Weblog add(Weblog weblog) { 45 if (queue.contains(weblog)) { 46 queue.remove(weblog); 47 } 48 49 if (queue.size() == size) { 50 queue.removeLast(); 51 } 52 queue.addFirst(weblog); 53 return weblog; 54 } 55 56 public void remove(Weblog weblog) { 57 queue.remove(weblog); 58 } 59 60 public List get() { 61 return (List ) queue; 62 } 63 64 public List get(int count) { 65 count = Math.min(count, queue.size()); 66 return (List ) queue.subList(0, count); 67 } 68 69 } 70 | Popular Tags |