@Test public void getTest () { final BooleanQueue q = new BooleanQueue(7); for (int i = 0; i < 5; i++) { for (int j = 0; j < 4; j++) { q.addLast(j % 2 == 0); } assertEquals("get(0) is not equal to peek (" + i + ")", q.get(0), q.first()); assertEquals("get(size-1) is not equal to peekLast (" + i + ")", q.get(q.size - 1), q.last()); for (int j = 0; j < 4; j++) { assertEquals(q.get(j), (j % 2 == 0)); } for (int j = 0; j < 4 - 1; j++) { q.removeFirst(); assertEquals("get(0) is not equal to peek (" + i + ")", q.get(0), q.first()); } q.removeFirst(); assert q.size == 0; try { q.get(0); fail("get() on empty queue did not throw"); } catch (IndexOutOfBoundsException ignore) { } } }
public boolean get (int index) { if (index < 0) throw new IndexOutOfBoundsException("index can't be < 0: " + index); if (index >= size) throw new IndexOutOfBoundsException("index can't be >= size: " + index + " >= " + size); final boolean[] values = this.values; int i = head + index; if (i >= values.length) { i -= values.length; } return values[i]; }
BooleanQueue { public boolean get (int index) { if (index < 0) throw new IndexOutOfBoundsException("index can't be < 0: " + index); if (index >= size) throw new IndexOutOfBoundsException("index can't be >= size: " + index + " >= " + size); final boolean[] values = this.values; int i = head + index; if (i >= values.length) { i -= values.length; } return values[i]; } }
BooleanQueue { public boolean get (int index) { if (index < 0) throw new IndexOutOfBoundsException("index can't be < 0: " + index); if (index >= size) throw new IndexOutOfBoundsException("index can't be >= size: " + index + " >= " + size); final boolean[] values = this.values; int i = head + index; if (i >= values.length) { i -= values.length; } return values[i]; } BooleanQueue();  BooleanQueue(int initialSize); }
BooleanQueue { public boolean get (int index) { if (index < 0) throw new IndexOutOfBoundsException("index can't be < 0: " + index); if (index >= size) throw new IndexOutOfBoundsException("index can't be >= size: " + index + " >= " + size); final boolean[] values = this.values; int i = head + index; if (i >= values.length) { i -= values.length; } return values[i]; } BooleanQueue();  BooleanQueue(int initialSize); void addLast(boolean object); void addFirst(boolean object); void ensureCapacity(int additional); boolean removeFirst(); boolean removeLast(); int indexOf(boolean value); boolean removeValue(boolean value); boolean removeIndex(int index); boolean notEmpty(); boolean isEmpty(); boolean first(); boolean last(); boolean get(int index); void clear(); Iterator<Boolean> iterator(); String toString(); String toString(String separator); int hashCode(); boolean equals(Object o); }
BooleanQueue { public boolean get (int index) { if (index < 0) throw new IndexOutOfBoundsException("index can't be < 0: " + index); if (index >= size) throw new IndexOutOfBoundsException("index can't be >= size: " + index + " >= " + size); final boolean[] values = this.values; int i = head + index; if (i >= values.length) { i -= values.length; } return values[i]; } BooleanQueue();  BooleanQueue(int initialSize); void addLast(boolean object); void addFirst(boolean object); void ensureCapacity(int additional); boolean removeFirst(); boolean removeLast(); int indexOf(boolean value); boolean removeValue(boolean value); boolean removeIndex(int index); boolean notEmpty(); boolean isEmpty(); boolean first(); boolean last(); boolean get(int index); void clear(); Iterator<Boolean> iterator(); String toString(); String toString(String separator); int hashCode(); boolean equals(Object o); public int size; }