1 22 23 package com.sosnoski.util.queue; 24 25 import java.util.Iterator ; 26 27 import com.sosnoski.util.WrappedArrayIterator; 28 29 40 41 public class ObjectQueue extends QueueBase 42 { 43 44 protected Object [] m_baseArray; 45 46 52 53 public ObjectQueue(int size, int growth) { 54 super(size, growth, Object .class); 55 } 56 57 62 63 public ObjectQueue(int size) { 64 super(size, Object .class); 65 } 66 67 70 71 public ObjectQueue() { 72 this(DEFAULT_SIZE); 73 } 74 75 80 81 public ObjectQueue(ObjectQueue base) { 82 super(base); 83 } 84 85 91 92 protected Object getArray() { 93 return m_baseArray; 94 } 95 96 102 103 protected void setArray(Object array) { 104 m_baseArray = (Object []) array; 105 } 106 107 113 114 public void add(Object item) { 115 int index = getAddIndex(); 116 m_baseArray[index] = item; 117 } 118 119 126 127 public Object remove() { 128 int index = getRemoveIndex(); 129 Object item = m_baseArray[index]; 130 m_baseArray[index] = null; 131 return item; 132 } 133 134 143 144 public final Iterator iterator() { 145 int end = m_fillOffset - 1; 146 if (end < 0) { 147 end = m_countLimit - 1; 148 } 149 return WrappedArrayIterator.buildIterator(m_baseArray, 150 m_emptyOffset, end); 151 } 152 153 159 160 public Object [] toArray() { 161 return (Object []) buildArray(Object .class); 162 } 163 164 172 173 public Object [] toArray(Class type) { 174 return (Object []) buildArray(type); 175 } 176 177 182 183 public Object clone() { 184 return new ObjectQueue(this); 185 } 186 } 187 | Popular Tags |