/** {@inheritDoc} */ public TCharList inverseGrep( TCharProcedure condition ) { TCharArrayList list = new TCharArrayList(); for ( int i = 0; i < _pos; i++ ) { if ( !condition.execute( _data[ i ] ) ) { list.add( _data[ i ] ); } } return list; }
/** {@inheritDoc} */ public char[] toArray( char[] dest ) { int len = dest.length; if ( dest.length > _pos ) { len = _pos; dest[len] = no_entry_value; } toArray( dest, 0, len ); return dest; }
/** * Creates a new <code>TCharArrayList</code> instance that contains * a copy of the collection passed to us. * * @param collection the collection to copy */ public TCharArrayList ( TCharCollection collection ) { this( collection.size() ); addAll( collection ); }
/** {@inheritDoc} */ public void insert( int offset, char 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++; }
/** {@inheritDoc} */ public boolean removeAll( TCharCollection collection ) { if ( collection == this ) { clear(); return true; } boolean changed = false; TCharIterator iter = collection.iterator(); while ( iter.hasNext() ) { char element = iter.next(); if ( remove( element ) ) { changed = true; } } return changed; }
/** {@inheritDoc} */ public boolean containsAll( char[] array ) { for ( int i = array.length; i-- > 0; ) { if ( ! contains( array[i] ) ) { return false; } } return true; }
/** {@inheritDoc} */ public boolean addAll( char[] array ) { boolean changed = false; for ( char element : array ) { if ( add( element ) ) { 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( char[] 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(); }
/** {@inheritDoc} */ public boolean add( char val ) { ensureCapacity( _pos + 1 ); _data[ _pos++ ] = val; return true; }
/** * Creates a new <code>TCharArrayStack</code> instance with the * specified capacity. * * @param capacity the initial depth of the stack * @param no_entry_value value that represents null */ public TCharArrayStack( int capacity, char no_entry_value ) { _list = new TCharArrayList( capacity, no_entry_value ); }
public boolean equals( Object o ) { if ( this == o ) { return true; } if ( o == null || getClass() != o.getClass() ) { return false; } TCharArrayStack that = ( TCharArrayStack ) o; return _list.equals( that._list ); }
/** {@inheritDoc} */ public int binarySearch( char value ) { return binarySearch( value, 0, _pos ); }
/** {@inheritDoc} */ public char next() { try { char next = get( cursor ); lastRet = cursor++; return next; } catch ( IndexOutOfBoundsException e ) { throw new NoSuchElementException(); } }
/** * Returns a String representation of the list, top to bottom. * * @return a <code>String</code> value */ public String toString() { final StringBuilder buf = new StringBuilder( "{" ); for ( int i = _list.size() - 1; i > 0; i-- ) { buf.append( _list.get( i ) ); buf.append( ", " ); } if ( size() > 0 ) { buf.append( _list.get( 0 ) ); } buf.append( "}" ); return buf.toString(); }
/** {@inheritDoc} */ public void insert( int offset, char[] values, int valOffset, int len ) { if ( offset == _pos ) { add( values, valOffset, len ); return; } ensureCapacity( _pos + len ); // shift right System.arraycopy( _data, offset, _data, offset + len, _pos - offset ); // insert System.arraycopy( values, valOffset, _data, offset, len ); _pos += len; }