You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2004/01/01 20:24:46 UTC
cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/buffer BoundedFifoBuffer.java UnboundedFifoBuffer.java
scolebourne 2004/01/01 11:24:46
Modified: collections/src/java/org/apache/commons/collections/buffer
BoundedFifoBuffer.java UnboundedFifoBuffer.java
Log:
Apply collection coding standards
Revision Changes Path
1.4 +46 -42 jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java
Index: BoundedFifoBuffer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BoundedFifoBuffer.java 28 Dec 2003 16:36:48 -0000 1.3
+++ BoundedFifoBuffer.java 1 Jan 2004 19:24:46 -0000 1.4
@@ -100,10 +100,10 @@
public class BoundedFifoBuffer extends AbstractCollection
implements Buffer, BoundedCollection {
- private final Object[] m_elements;
- private int m_start = 0;
- private int m_end = 0;
- private boolean m_full = false;
+ private final Object[] elements;
+ private int start = 0;
+ private int end = 0;
+ private boolean full = false;
private final int maxElements;
/**
@@ -125,8 +125,8 @@
if (size <= 0) {
throw new IllegalArgumentException("The size must be greater than 0");
}
- m_elements = new Object[size];
- maxElements = m_elements.length;
+ elements = new Object[size];
+ maxElements = elements.length;
}
/**
@@ -150,12 +150,12 @@
public int size() {
int size = 0;
- if (m_end < m_start) {
- size = maxElements - m_start + m_end;
- } else if (m_end == m_start) {
- size = (m_full ? maxElements : 0);
+ if (end < start) {
+ size = maxElements - start + end;
+ } else if (end == start) {
+ size = (full ? maxElements : 0);
} else {
- size = m_end - m_start;
+ size = end - start;
}
return size;
@@ -192,10 +192,10 @@
* Clears this buffer.
*/
public void clear() {
- m_full = false;
- m_start = 0;
- m_end = 0;
- Arrays.fill(m_elements, null);
+ full = false;
+ start = 0;
+ end = 0;
+ Arrays.fill(elements, null);
}
/**
@@ -211,18 +211,18 @@
throw new NullPointerException("Attempted to add null object to buffer");
}
- if (m_full) {
+ if (full) {
throw new BufferOverflowException("The buffer cannot hold more than " + maxElements + " objects.");
}
- m_elements[m_end++] = element;
+ elements[end++] = element;
- if (m_end >= maxElements) {
- m_end = 0;
+ if (end >= maxElements) {
+ end = 0;
}
- if (m_end == m_start) {
- m_full = true;
+ if (end == start) {
+ full = true;
}
return true;
@@ -239,7 +239,7 @@
throw new BufferUnderflowException("The buffer is already empty");
}
- return m_elements[m_start];
+ return elements[start];
}
/**
@@ -253,16 +253,16 @@
throw new BufferUnderflowException("The buffer is already empty");
}
- Object element = m_elements[m_start];
+ Object element = elements[start];
if (null != element) {
- m_elements[m_start++] = null;
+ elements[start++] = null;
- if (m_start >= maxElements) {
- m_start = 0;
+ if (start >= maxElements) {
+ start = 0;
}
- m_full = false;
+ full = false;
}
return element;
@@ -304,28 +304,32 @@
public Iterator iterator() {
return new Iterator() {
- private int index = m_start;
+ private int index = start;
private int lastReturnedIndex = -1;
- private boolean isFirst = m_full;
+ private boolean isFirst = full;
public boolean hasNext() {
- return isFirst || (index != m_end);
+ return isFirst || (index != end);
}
public Object next() {
- if (!hasNext()) throw new NoSuchElementException();
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
isFirst = false;
lastReturnedIndex = index;
index = increment(index);
- return m_elements[lastReturnedIndex];
+ return elements[lastReturnedIndex];
}
public void remove() {
- if (lastReturnedIndex == -1) throw new IllegalStateException();
+ if (lastReturnedIndex == -1) {
+ throw new IllegalStateException();
+ }
// First element can be removed quickly
- if (lastReturnedIndex == m_start) {
+ if (lastReturnedIndex == start) {
BoundedFifoBuffer.this.remove();
lastReturnedIndex = -1;
return;
@@ -333,20 +337,20 @@
// Other elements require us to shift the subsequent elements
int i = lastReturnedIndex + 1;
- while (i != m_end) {
+ while (i != end) {
if (i >= maxElements) {
- m_elements[i - 1] = m_elements[0];
+ elements[i - 1] = elements[0];
i = 0;
} else {
- m_elements[i - 1] = m_elements[i];
+ elements[i - 1] = elements[i];
i++;
}
}
lastReturnedIndex = -1;
- m_end = decrement(m_end);
- m_elements[m_end] = null;
- m_full = false;
+ end = decrement(end);
+ elements[end] = null;
+ full = false;
index = decrement(index);
}
1.3 +46 -44 jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java
Index: UnboundedFifoBuffer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- UnboundedFifoBuffer.java 28 Dec 2003 16:36:48 -0000 1.2
+++ UnboundedFifoBuffer.java 1 Jan 2004 19:24:46 -0000 1.3
@@ -96,9 +96,9 @@
*/
public class UnboundedFifoBuffer extends AbstractCollection implements Buffer {
- protected Object[] m_buffer;
- protected int m_head;
- protected int m_tail;
+ protected Object[] buffer;
+ protected int head;
+ protected int tail;
/**
* Constructs an UnboundedFifoBuffer with the default number of elements.
@@ -123,9 +123,9 @@
if (initialSize <= 0) {
throw new IllegalArgumentException("The size must be greater than 0");
}
- m_buffer = new Object[initialSize + 1];
- m_head = 0;
- m_tail = 0;
+ buffer = new Object[initialSize + 1];
+ head = 0;
+ tail = 0;
}
/**
@@ -136,10 +136,10 @@
public int size() {
int size = 0;
- if (m_tail < m_head) {
- size = m_buffer.length - m_head + m_tail;
+ if (tail < head) {
+ size = buffer.length - head + tail;
} else {
- size = m_tail - m_head;
+ size = tail - head;
}
return size;
@@ -167,30 +167,30 @@
throw new NullPointerException("Attempted to add null object to buffer");
}
- if (size() + 1 >= m_buffer.length) {
- Object[] tmp = new Object[((m_buffer.length - 1) * 2) + 1];
+ if (size() + 1 >= buffer.length) {
+ Object[] tmp = new Object[((buffer.length - 1) * 2) + 1];
int j = 0;
- for (int i = m_head; i != m_tail;) {
- tmp[j] = m_buffer[i];
- m_buffer[i] = null;
+ for (int i = head; i != tail;) {
+ tmp[j] = buffer[i];
+ buffer[i] = null;
j++;
i++;
- if (i == m_buffer.length) {
+ if (i == buffer.length) {
i = 0;
}
}
- m_buffer = tmp;
- m_head = 0;
- m_tail = j;
+ buffer = tmp;
+ head = 0;
+ tail = j;
}
- m_buffer[m_tail] = obj;
- m_tail++;
- if (m_tail >= m_buffer.length) {
- m_tail = 0;
+ buffer[tail] = obj;
+ tail++;
+ if (tail >= buffer.length) {
+ tail = 0;
}
return true;
}
@@ -206,7 +206,7 @@
throw new BufferUnderflowException("The buffer is already empty");
}
- return m_buffer[m_head];
+ return buffer[head];
}
/**
@@ -220,14 +220,14 @@
throw new BufferUnderflowException("The buffer is already empty");
}
- Object element = m_buffer[m_head];
+ Object element = buffer[head];
if (null != element) {
- m_buffer[m_head] = null;
+ buffer[head] = null;
- m_head++;
- if (m_head >= m_buffer.length) {
- m_head = 0;
+ head++;
+ if (head >= buffer.length) {
+ head = 0;
}
}
@@ -242,7 +242,7 @@
*/
private int increment(int index) {
index++;
- if (index >= m_buffer.length) {
+ if (index >= buffer.length) {
index = 0;
}
return index;
@@ -257,7 +257,7 @@
private int decrement(int index) {
index--;
if (index < 0) {
- index = m_buffer.length - 1;
+ index = buffer.length - 1;
}
return index;
}
@@ -270,28 +270,30 @@
public Iterator iterator() {
return new Iterator() {
- private int index = m_head;
+ private int index = head;
private int lastReturnedIndex = -1;
public boolean hasNext() {
- return index != m_tail;
+ return index != tail;
}
public Object next() {
- if (!hasNext())
+ if (!hasNext()) {
throw new NoSuchElementException();
+ }
lastReturnedIndex = index;
index = increment(index);
- return m_buffer[lastReturnedIndex];
+ return buffer[lastReturnedIndex];
}
public void remove() {
- if (lastReturnedIndex == -1)
+ if (lastReturnedIndex == -1) {
throw new IllegalStateException();
+ }
// First element can be removed quickly
- if (lastReturnedIndex == m_head) {
+ if (lastReturnedIndex == head) {
UnboundedFifoBuffer.this.remove();
lastReturnedIndex = -1;
return;
@@ -299,19 +301,19 @@
// Other elements require us to shift the subsequent elements
int i = lastReturnedIndex + 1;
- while (i != m_tail) {
- if (i >= m_buffer.length) {
- m_buffer[i - 1] = m_buffer[0];
+ while (i != tail) {
+ if (i >= buffer.length) {
+ buffer[i - 1] = buffer[0];
i = 0;
} else {
- m_buffer[i - 1] = m_buffer[i];
+ buffer[i - 1] = buffer[i];
i++;
}
}
lastReturnedIndex = -1;
- m_tail = decrement(m_tail);
- m_buffer[m_tail] = null;
+ tail = decrement(tail);
+ buffer[tail] = null;
index = decrement(index);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org