/** {@inheritDoc} */ public TByteList grep( TByteProcedure condition ) { TByteArrayList list = new TByteArrayList(); for ( int i = 0; i < _pos; i++ ) { if ( condition.execute( _data[ i ] ) ) { list.add( _data[ i ] ); } } return list; }
/** * Creates a new <code>TByteArrayStack</code> instance with the * specified capacity. * * @param capacity the initial depth of the stack */ public TByteArrayStack( int capacity ) { _list = new TByteArrayList( capacity ); }
/** * Pushes the value onto the top of the stack. * * @param val an <code>byte</code> value */ public void push( byte val ) { _list.add( val ); }
/** {@inheritDoc} */ public byte[] toArray( int offset, int len ) { byte[] rv = new byte[ len ]; toArray( rv, offset, len ); return rv; }
/** {@inheritDoc} */ public boolean removeAll( TByteCollection collection ) { if ( collection == this ) { clear(); return true; } boolean changed = false; TByteIterator iter = collection.iterator(); while ( iter.hasNext() ) { byte element = iter.next(); if ( remove( element ) ) { changed = true; } } return changed; }
/** {@inheritDoc} */ public void insert( int offset, byte value ) { if ( offset == _pos ) { add( value ); return; } ensureCapacity( _pos + 1 ); // shift right System.arraycopy( _data, offset, _data, offset + 1, _pos - offset ); // insert _data[ offset ] = value; _pos++; }
/** * Returns the current depth of the stack. */ public int size() { return _list.size(); }
/** {@inheritDoc} */ public boolean containsAll( byte[] array ) { for ( int i = array.length; i-- > 0; ) { if ( ! contains( array[i] ) ) { return false; } } return true; }
/** {@inheritDoc} */ public boolean removeAll( byte[] array ) { boolean changed = false; for ( int i = array.length; i-- > 0; ) { if ( remove(array[i]) ) { changed = true; } } return changed; }
/** * Copies a slice of the list into a native array. Note that this will NOT * pop them out of the stack. The front of the list will be the top * of the stack. * <p> * If the native array is smaller than the stack depth, * the native array will be filled with the elements from the top * of the array until it is full and exclude the remainder. * * @param dest the array to copy into. */ public void toArray( byte[] dest ) { int size = size(); int start = size - dest.length; if ( start < 0 ) { start = 0; } int length = Math.min( size, dest.length ); _list.toArray( dest, start, length ); reverse( dest, 0, length ); if ( dest.length > size ) { dest[size] = _list.getNoEntryValue(); } }
/** * Clears the stack. */ public void clear() { _list.clear(); }
/** * Creates a new <code>TByteArrayList</code> instance that contains * a copy of the collection passed to us. * * @param collection the collection to copy */ public TByteArrayList ( TByteCollection collection ) { this( collection.size() ); addAll( collection ); }
/** {@inheritDoc} */ public int binarySearch( byte value ) { return binarySearch( value, 0, _pos ); }
/** {@inheritDoc} */ public byte next() { try { byte next = get( cursor ); lastRet = cursor++; return next; } catch ( IndexOutOfBoundsException e ) { throw new NoSuchElementException(); } }
/** * Creates a new <code>TByteArrayStack</code> instance with the * specified capacity. * * @param capacity the initial depth of the stack * @param no_entry_value value that represents null */ public TByteArrayStack( int capacity, byte no_entry_value ) { _list = new TByteArrayList( capacity, no_entry_value ); }