@Override public boolean hasNext() { return pos < AbstractBooleanList.this.size(); } @Override
/** * Ensures that the given index is nonnegative and not greater than the list * size. * * @param index * an index. * @throws IndexOutOfBoundsException * if the given index is negative or greater than the list size. */ protected void ensureIndex(final int index) { if (index < 0) throw new IndexOutOfBoundsException("Index (" + index + ") is negative"); if (index > size()) throw new IndexOutOfBoundsException("Index (" + index + ") is greater than list size (" + (size()) + ")"); } /**
/** * Ensures that the given index is nonnegative and smaller than the list size. * * @param index * an index. * @throws IndexOutOfBoundsException * if the given index is negative or not smaller than the list size. */ protected void ensureRestrictedIndex(final int index) { if (index < 0) throw new IndexOutOfBoundsException("Index (" + index + ") is negative"); if (index >= size()) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + (size()) + ")"); } /**
/** * {@inheritDoc} * <p> * This implementation delegates to {@link #removeElements(int, int)}. */ @Override public void clear() { removeElements(0, size()); } private boolean valEquals(final Object a, final Object b) {
/** * {@inheritDoc} * * <p> * This implementation delegates to the type-specific list version of * {@link List#addAll(int, Collection)}. */ @Override public boolean addAll(final BooleanList l) { return addAll(size(), l); } @Override
/** * {@inheritDoc} * * <p> * This implementation delegates to the type-specific version of * {@link List#add(int, Object)}. */ @Override public boolean add(final boolean k) { add(size(), k); return true; } /**
@Override public boolean peekBoolean(final int i) { return getBoolean(size() - 1 - i); } /**
/** * {@inheritDoc} * * <p> * This implementation delegates to the type-specific version of * {@link List#addAll(int, Collection)}. */ @Override public boolean addAll(final BooleanCollection c) { return addAll(size(), c); } /**
/** * {@inheritDoc} * * <p> * This implementation delegates to the type-specific version of * {@link List#addAll(int, Collection)}. */ @Override public boolean addAll(final Collection<? extends Boolean> c) { return addAll(size(), c); } /**
/** * {@inheritDoc} * * <p> * This is a trivial iterator-based implementation. It is expected that * implementations will override this method with a more optimized version. */ @Override public void getElements(final int from, final boolean a[], int offset, int length) { BooleanListIterator i = listIterator(from); if (offset < 0) throw new ArrayIndexOutOfBoundsException("Offset (" + offset + ") is negative"); if (offset + length > a.length) throw new ArrayIndexOutOfBoundsException( "End index (" + (offset + length) + ") is greater than array length (" + a.length + ")"); if (from + length > size()) throw new IndexOutOfBoundsException( "End index (" + (from + length) + ") is greater than list size (" + size() + ")"); while (length-- != 0) a[offset++] = i.nextBoolean(); } /**
@Override public boolean popBoolean() { if (isEmpty()) throw new NoSuchElementException(); return removeBoolean(size() - 1); } @Override
@Override public boolean topBoolean() { if (isEmpty()) throw new NoSuchElementException(); return getBoolean(size() - 1); } @Override
@Override public String toString() { final StringBuilder s = new StringBuilder(); final BooleanIterator i = iterator(); int n = size(); boolean k; boolean first = true; s.append("["); while (n-- != 0) { if (first) first = false; else s.append(", "); k = i.nextBoolean(); s.append(String.valueOf(k)); } s.append("]"); return s.toString(); } /** A class implementing a sublist view. */
@Override public void size(final int size) { int i = size(); if (size > i) while (i++ < size) add((false)); else while (i-- != size) removeBoolean(i); } @Override
/** * Returns the hash code for this list, which is identical to * {@link java.util.List#hashCode()}. * * @return the hash code for this list. */ @Override public int hashCode() { BooleanIterator i = iterator(); int h = 1, s = size(); while (s-- != 0) { boolean k = i.nextBoolean(); h = 31 * h + ((k) ? 1231 : 1237); } return h; } @Override
@Override public boolean equals(final Object o) { if (o == this) return true; if (!(o instanceof List)) return false; final List<?> l = (List<?>) o; int s = size(); if (s != l.size()) return false; if (l instanceof BooleanList) { final BooleanListIterator i1 = listIterator(), i2 = ((BooleanList) l).listIterator(); while (s-- != 0) if (i1.nextBoolean() != i2.nextBoolean()) return false; return true; } final ListIterator<?> i1 = listIterator(), i2 = l.listIterator(); while (s-- != 0) if (!valEquals(i1.next(), i2.next())) return false; return true; } /**
@Override public int lastIndexOf(final boolean k) { BooleanListIterator i = listIterator(size()); boolean e; while (i.hasPrevious()) { e = i.previousBoolean(); if (((k) == (e))) return i.nextIndex(); } return -1; } @Override