1 22 package org.jboss.util.collection; 23 24 import java.util.List ; 25 import java.util.LinkedList ; 26 import java.util.Iterator ; 27 28 import org.jboss.util.NullArgumentException; 29 30 37 public class ListQueue 38 extends AbstractQueue 39 { 40 41 protected final List list; 42 43 51 public ListQueue(final List list, final int maxSize) { 52 super(maxSize); 53 54 if (list == null) 55 throw new NullArgumentException("list"); 56 57 this.list = list; 58 } 59 60 66 public ListQueue(final int maxSize) { 67 super(maxSize); 68 this.list = new LinkedList (); 69 } 70 71 78 public ListQueue(final List list) { 79 this(list, UNLIMITED_MAXIMUM_SIZE); 80 } 81 82 86 public ListQueue() { 87 this(new LinkedList (), UNLIMITED_MAXIMUM_SIZE); 88 } 89 90 95 protected boolean addLast(final Object obj) { 96 return list.add(obj); 97 } 98 99 104 protected Object removeFirst() { 105 return list.remove(0); 106 } 107 108 113 public int size() { 114 return list.size(); 115 } 116 117 122 public Iterator iterator() { 123 return list.iterator(); 124 } 125 126 133 public Object getFront() throws EmptyCollectionException { 134 if (isEmpty()) 135 throw new EmptyCollectionException(); 136 137 return list.get(0); 138 } 139 140 147 public Object getBack() throws EmptyCollectionException { 148 if (isEmpty()) 149 throw new EmptyCollectionException(); 150 151 return list.get(list.size() - 1); 152 } 153 154 159 public Iterator reverseIterator() { 160 return new ReverseListIterator(list); 161 } 162 163 168 public String toString() { 169 return list.toString(); 170 } 171 } 172 | Popular Tags |