@Test public void indexOfTest () { final BooleanQueue q = new BooleanQueue(); for (int j = 0; j <= 6; j++) q.addLast(j % 2 == 0); for (int j = 0; j <= 6; j++) assertEquals(q.indexOf(j % 2 == 0), j % 2); q.clear(); for (int j = 2; j >= 0; j--) q.addFirst(j % 2 == 0); for (int j = 3; j <= 6; j++) q.addLast(j % 2 == 0); for (int j = 0; j <= 6; j++) assertEquals(q.indexOf(j % 2 == 0), j % 2); }
public int indexOf (boolean value) { if (size == 0) return -1; boolean[] values = this.values; final int head = this.head, tail = this.tail; if (head < tail) { for (int i = head; i < tail; i++) if (values[i] == value) return i - head; } else { for (int i = head, n = values.length; i < n; i++) if (values[i] == value) return i - head; for (int i = 0; i < tail; i++) if (values[i] == value) return i + values.length - head; } return -1; }
BooleanQueue { public int indexOf (boolean value) { if (size == 0) return -1; boolean[] values = this.values; final int head = this.head, tail = this.tail; if (head < tail) { for (int i = head; i < tail; i++) if (values[i] == value) return i - head; } else { for (int i = head, n = values.length; i < n; i++) if (values[i] == value) return i - head; for (int i = 0; i < tail; i++) if (values[i] == value) return i + values.length - head; } return -1; } }
BooleanQueue { public int indexOf (boolean value) { if (size == 0) return -1; boolean[] values = this.values; final int head = this.head, tail = this.tail; if (head < tail) { for (int i = head; i < tail; i++) if (values[i] == value) return i - head; } else { for (int i = head, n = values.length; i < n; i++) if (values[i] == value) return i - head; for (int i = 0; i < tail; i++) if (values[i] == value) return i + values.length - head; } return -1; } BooleanQueue();  BooleanQueue(int initialSize); }
BooleanQueue { public int indexOf (boolean value) { if (size == 0) return -1; boolean[] values = this.values; final int head = this.head, tail = this.tail; if (head < tail) { for (int i = head; i < tail; i++) if (values[i] == value) return i - head; } else { for (int i = head, n = values.length; i < n; i++) if (values[i] == value) return i - head; for (int i = 0; i < tail; i++) if (values[i] == value) return i + values.length - head; } return -1; } 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 int indexOf (boolean value) { if (size == 0) return -1; boolean[] values = this.values; final int head = this.head, tail = this.tail; if (head < tail) { for (int i = head; i < tail; i++) if (values[i] == value) return i - head; } else { for (int i = head, n = values.length; i < n; i++) if (values[i] == value) return i - head; for (int i = 0; i < tail; i++) if (values[i] == value) return i + values.length - head; } return -1; } 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; }