/** {@inheritDoc} */ @Override public void add( double[] vals ) { add( vals, 0, vals.length ); }
/** {@inheritDoc} */ @Override public int binarySearch( double value ) { return binarySearch( value, 0, _pos ); }
/** {@inheritDoc} */ @Override public boolean hasNext() { return cursor < size(); }
/** * Grow the internal array as needed to accommodate the specified number of elements. * The size of the array bytes on each resize unless capacity requires more than twice * the current capacity. */ public void ensureCapacity( int capacity ) { int oldCapacity = capacity(); if ( capacity > oldCapacity ) { int newCap = Math.max( oldCapacity << 1, capacity ); _data.resize( newCap ); } }
/** {@inheritDoc} */ @Override public double replace( int offset, double val ) { return set( offset, val ); }
/** {@inheritDoc} */ @Override public int lastIndexOf( double value ) { return lastIndexOf( _pos, value ); }
/** {@inheritDoc} */ @Override public boolean add( double val ) { ensureCapacity( _pos + 1 ); _data.put( _pos++, val ); return true; }
/** {@inheritDoc} */ @Override public void clear() { clear( DEFAULT_CAPACITY ); }
/** {@inheritDoc} */ @Override public int indexOf( double value ) { return indexOf( 0, value ); }
/** {@inheritDoc} */ @Override public double next() { try { double next = get( cursor ); lastRet = cursor++; return next; } catch ( IndexOutOfBoundsException e ) { throw new NoSuchElementException(); } }
/** {@inheritDoc} */ @Override public double max() { if ( size() == 0 ) { throw new IllegalStateException("cannot find maximum of an empty list"); } double max = Double.NEGATIVE_INFINITY; for ( int i = 0; i < _pos; i++ ) { double val = _data.get( i ); if ( val > max ) { max = val; } } return max; }
/** {@inheritDoc} */ @Override public TDoubleList subList( int begin, int end ) { if ( end < begin ) { throw new IllegalArgumentException( "end index " + end + " greater than begin index " + begin ); } if ( begin < 0 ) { throw new IndexOutOfBoundsException( "begin index can not be < 0" ); } if ( end > capacity() ) { throw new IndexOutOfBoundsException( "end index < " + capacity() ); } TDoubleArrayList list = new TDoubleArrayList( end - begin ); _data.toArray(begin, list._data, 0, end - begin); list._pos = end - begin; return list; }
/** {@inheritDoc} */ @Override public void set( int offset, double[] values ) { set( offset, values, 0, values.length ); }
/** {@inheritDoc} */ @Override public boolean contains( double value ) { return lastIndexOf( value ) >= 0; }
/** {@inheritDoc} */ @Override public void add( double[] vals, int offset, int length ) { ensureCapacity( _pos + length ); _data.fromArray( vals, offset, _pos, length ); _pos += length; }
/** {@inheritDoc} */ @Override public double min() { if ( size() == 0 ) { throw new IllegalStateException( "cannot find minimum of an empty list" ); } double min = Double.POSITIVE_INFINITY; for ( int i = 0; i < _pos; i++ ) { double val = _data.get( i ); if ( val < min ) { min = val; } } return min; }
/** {@inheritDoc} */ @Override public boolean addAll( double[] array ) { boolean changed = false; for ( double element : array ) { if ( add( element ) ) { changed = true; } } return changed; }
@Override public void writeExternal( ObjectOutput out ) throws IOException { // VERSION out.writeByte( 0 ); // POSITION out.writeInt( _pos ); // NO_ENTRY_VALUE out.writeDouble( no_entry_value ); // ENTRIES int len = capacity(); out.writeInt( len ); for( int i = 0; i < len; i++ ) { out.writeDouble( _data.get( i ) ); } }
/** {@inheritDoc} */ @Override public String toString() { final StringBuilder buf = new StringBuilder( "{" ); for ( int i = 0, end = _pos - 1; i < end; i++ ) { buf.append( _data.get( i ) ); buf.append( ", " ); } if ( size() > 0 ) { buf.append( _data.get( _pos - 1 ) ); } buf.append( "}" ); return buf.toString(); }