Javadoc and stylistic changes

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@219314 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2005-07-16 11:12:51 +00:00
parent a4fd44d404
commit 1fa2dd8d12
1 changed files with 11 additions and 20 deletions

View File

@ -57,8 +57,11 @@ import org.apache.commons.collections.BufferUnderflowException;
* @author Berin Loritsch * @author Berin Loritsch
* @author Paul Jack * @author Paul Jack
* @author Stephen Colebourne * @author Stephen Colebourne
* @author Andreas Schlosser
*/ */
public class UnboundedFifoBuffer extends AbstractCollection implements Buffer, Serializable { public class UnboundedFifoBuffer extends AbstractCollection implements Buffer, Serializable {
// invariant: buffer.length > size()
// ie.buffer always has at least one empty entry
/** Serialization vesrion */ /** Serialization vesrion */
private static final long serialVersionUID = -3482960336579541419L; private static final long serialVersionUID = -3482960336579541419L;
@ -123,7 +126,7 @@ public class UnboundedFifoBuffer extends AbstractCollection implements Buffer, S
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject(); in.defaultReadObject();
int size = in.readInt(); int size = in.readInt();
buffer = new Object[size+1]; buffer = new Object[size + 1];
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
buffer[i] = in.readObject(); buffer[i] = in.readObject();
} }
@ -171,30 +174,24 @@ public class UnboundedFifoBuffer extends AbstractCollection implements Buffer, S
} }
if (size() + 1 >= buffer.length) { if (size() + 1 >= buffer.length) {
// copy contents to a new buffer array
Object[] tmp = new Object[((buffer.length - 1) * 2) + 1]; Object[] tmp = new Object[((buffer.length - 1) * 2) + 1];
int j = 0; int j = 0;
// move head to element zero in the new array
for (int i = head; i != tail;) { for (int i = head; i != tail;) {
tmp[j] = buffer[i]; tmp[j] = buffer[i];
buffer[i] = null; buffer[i] = null;
j++; j++;
i++; i = increment(i);
if (i == buffer.length) {
i = 0;
}
} }
buffer = tmp; buffer = tmp;
head = 0; head = 0;
tail = j; tail = j;
} }
buffer[tail] = obj; buffer[tail] = obj;
tail++; tail = increment(tail);
if (tail >= buffer.length) {
tail = 0;
}
return true; return true;
} }
@ -224,16 +221,10 @@ public class UnboundedFifoBuffer extends AbstractCollection implements Buffer, S
} }
Object element = buffer[head]; Object element = buffer[head];
if (element != null) {
if (null != element) {
buffer[head] = null; buffer[head] = null;
head = increment(head);
head++;
if (head >= buffer.length) {
head = 0;
}
} }
return element; return element;
} }
@ -322,5 +313,5 @@ public class UnboundedFifoBuffer extends AbstractCollection implements Buffer, S
}; };
} }
} }