/** {@inheritDoc} */ public TShortList grep( TShortProcedure condition ) { TShortArrayList list = new TShortArrayList(); for ( int i = 0; i < _pos; i++ ) { if ( condition.execute( _data[ i ] ) ) { list.add( _data[ i ] ); } } return list; }
/** {@inheritDoc} */ public short[] toArray( int offset, int len ) { short[] rv = new short[ len ]; toArray( rv, offset, len ); return rv; }
/** * Creates a new <code>TShortArrayList</code> instance that contains * a copy of the collection passed to us. * * @param collection the collection to copy */ public TShortArrayList ( TShortCollection collection ) { this( collection.size() ); addAll( collection ); }
public static String encode(boolean[] fingerprint) { TShortArrayList xs = new TShortArrayList(120); for (int k=0; k < fingerprint.length; ++k) if (fingerprint[k]) xs.add((short)k); return encode(xs.toArray()); }
/** * Pushes the value onto the top of the stack. * * @param val an <code>short</code> value */ public void push( short val ) { _list.add( val ); }
/** {@inheritDoc} */ public void insert( int offset, short 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++; }
/** * Creates a new <code>TShortArrayStack</code> instance with the * specified capacity. * * @param capacity the initial depth of the stack */ public TShortArrayStack( int capacity ) { _list = new TShortArrayList( capacity ); }
/** * 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( short[] 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(); } }
/** {@inheritDoc} */ public boolean removeAll( TShortCollection collection ) { if ( collection == this ) { clear(); return true; } boolean changed = false; TShortIterator iter = collection.iterator(); while ( iter.hasNext() ) { short element = iter.next(); if ( remove( element ) ) { changed = true; } } return changed; }
/** {@inheritDoc} */ public boolean containsAll( short[] array ) { for ( int i = array.length; i-- > 0; ) { if ( ! contains( array[i] ) ) { return false; } } return true; }
/** {@inheritDoc} */ public boolean add( short val ) { ensureCapacity( _pos + 1 ); _data[ _pos++ ] = val; return true; }
/** * Clears the stack. */ public void clear() { _list.clear(); }
public boolean equals( Object o ) { if ( this == o ) { return true; } if ( o == null || getClass() != o.getClass() ) { return false; } TShortArrayStack that = ( TShortArrayStack ) o; return _list.equals( that._list ); }
/** {@inheritDoc} */ public int binarySearch( short value ) { return binarySearch( value, 0, _pos ); }
/** {@inheritDoc} */ public short next() { try { short next = get( cursor ); lastRet = cursor++; return next; } catch ( IndexOutOfBoundsException e ) { throw new NoSuchElementException(); } }
/** {@inheritDoc} */ public boolean addAll( short[] array ) { boolean changed = false; for ( short element : array ) { if ( add( element ) ) { changed = true; } } return changed; }
/** {@inheritDoc} */ public void insert( int offset, short[] 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; }