1 22 package org.jboss.util.collection; 23 24 import java.util.AbstractCollection ; 25 26 33 public abstract class AbstractQueue 34 extends AbstractCollection 35 implements Queue 36 { 37 38 public static int DEFAULT_MAXIMUM_SIZE = UNLIMITED_MAXIMUM_SIZE; 39 40 41 protected int maximumSize = DEFAULT_MAXIMUM_SIZE; 42 43 46 protected AbstractQueue() {} 47 48 55 protected AbstractQueue(final int maxSize) { 56 setMaximumSize(maxSize); 57 } 58 59 64 public int getMaximumSize() { 65 return maximumSize; 66 } 67 68 75 public void setMaximumSize(final int size) { 76 if (size < 0 && size != UNLIMITED_MAXIMUM_SIZE) 77 throw new IllegalArgumentException ("illegal size: " + size); 78 79 maximumSize = size; 80 } 81 82 87 public boolean isFull() { 88 if (maximumSize != UNLIMITED_MAXIMUM_SIZE && size() >= maximumSize) 89 return true; 90 91 return false; 92 } 93 94 99 public boolean isEmpty() { 100 if (size() <= 0) 101 return true; 102 103 return false; 104 } 105 106 114 public boolean add(Object obj) throws FullCollectionException { 115 if (isFull()) 116 throw new FullCollectionException(); 117 118 return addLast(obj); 119 } 120 121 128 public Object remove() throws EmptyCollectionException { 129 if (isEmpty()) 130 throw new EmptyCollectionException(); 131 132 return removeFirst(); 133 } 134 135 138 public void clear() { 139 while (!isEmpty()) { 140 remove(); 141 } 142 } 143 144 151 protected abstract boolean addLast(Object obj); 152 153 158 protected abstract Object removeFirst(); 159 } 160 | Popular Tags |