@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
/** * {@inheritDoc} * * <p> * This implementation delegates to the analogous method for array fragments. */ @Override public void addElements(final int index, final boolean a[]) { addElements(index, a, 0, a.length); } /**
@Override public boolean peekBoolean(final int i) { return getBoolean(size() - 1 - i); } /**
@Override public boolean topBoolean() { if (isEmpty()) throw new NoSuchElementException(); return getBoolean(size() - 1); } @Override
@Override public boolean popBoolean() { if (isEmpty()) throw new NoSuchElementException(); return removeBoolean(size() - 1); } @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; } /**
/** * Adds all of the elements in the specified collection to this list (optional * operation). */ @Override public boolean addAll(int index, final Collection<? extends Boolean> c) { ensureIndex(index); final Iterator<? extends Boolean> i = c.iterator(); final boolean retVal = i.hasNext(); while (i.hasNext()) add(index++, (i.next()).booleanValue()); return retVal; } /**
/** * {@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(); } /**
/** * 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
/** * Removes a single instance of the specified element from this collection, if * it is present (optional operation). * <p> * This implementation delegates to {@code indexOf()}. * * @see List#remove(Object) */ @Override public boolean rem(final boolean k) { int index = indexOf(k); if (index == -1) return false; removeBoolean(index); return true; } @Override
/** * {@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 removeElements(final int from, final int to) { ensureIndex(to); BooleanListIterator i = listIterator(from); int n = to - from; if (n < 0) throw new IllegalArgumentException("Start index (" + from + ") is greater than end index (" + to + ")"); while (n-- != 0) { i.nextBoolean(); i.remove(); } } /**
/** * {@inheritDoc} * * <p> * This implementation delegates to {@link #listIterator()}. */ @Override public BooleanListIterator iterator() { return listIterator(); } /**
/** * {@inheritDoc} * * <p> * This implementation delegates to the type-specific version of * {@link List#addAll(int, Collection)}. */ @Override public boolean addAll(final int index, final BooleanList l) { return addAll(index, (BooleanCollection) l); } /**
@Override public boolean nextBoolean() { if (!hasNext()) throw new NoSuchElementException(); return AbstractBooleanList.this.getBoolean(last = pos++); } @Override
@Override public void push(final boolean o) { add(o); } @Override
@Override public int compareTo( final List<? extends Boolean> list ) { if ( list instanceof BitVector ) return compareTo( (BitVector)list ); return super.compareTo( list ); }
@Override public BooleanList subList(final int from, final int to) { ensureIndex(from); ensureIndex(to); if (from > to) throw new IndexOutOfBoundsException("Start index (" + from + ") is greater than end index (" + to + ")"); return new BooleanSubList(this, from, to); } /**
/** * Returns true if this list contains the specified element. * <p> * This implementation delegates to {@code indexOf()}. * * @see List#contains(Object) */ @Override public boolean contains(final boolean k) { return indexOf(k) >= 0; } @Override