/** * Add a new value to the list but don't employ a wrapper. * * @param value new value * @return was able to add. */ public boolean addFloat(double value) { if (end + 1 >= values.length) { values = grow(values); } values[end] = value; end++; return true; }
@Override public int hashCode() { int result = 1; result = 31 * result + (values != null ? Dbl.hashCode(0, end, values) : 0); result = 31 * result + end; return result; }
/** * max * * @return max */ public double max() { return Dbl.max(values, end); }
@Universal public static double[] insert( final double[] array, final int fromIndex, final double[] values ) { if ( fromIndex >= array.length ) { return add( array, values ); } final int index = calculateIndex( array, fromIndex ); //Object newArray = Array.newInstance(array.getClass().getComponentType(), array.length+1); double[] newArray = new double[ array.length + values.length ]; if ( index != 0 ) { /* Copy up to the length in the array before the index. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, 0, newArray, 0, index ); } boolean lastIndex = index == array.length - 1; int toIndex = index + values.length; int remainingIndex = newArray.length - toIndex; if ( lastIndex ) { /* Copy the area after the insert. Make sure we don't write over the end. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, index, newArray, index + values.length, remainingIndex ); } else { /* Copy the area after the insert. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, index, newArray, index + values.length, remainingIndex ); } for ( int i = index, j = 0; i < toIndex; i++, j++ ) { newArray[ i ] = values[ j ]; } return newArray; }
/** * Mean * * @return mean */ public double mean() { return Dbl.mean(values, end); }
@Universal public static double[] slc( double[] array, int startIndex, int endIndex ) { final int start = calculateIndex( array, startIndex ); final int end = calculateEndIndex(array, endIndex); final int newLength = end - start; if ( newLength < 0 ) { throw new ArrayIndexOutOfBoundsException( String.format( "start index %d, end index %d, length %d", startIndex, endIndex, array.length ) ); } double[] newArray = new double[ newLength ]; System.arraycopy( array, start, newArray, 0, newLength ); return newArray; }
/** * median * * @return median */ public double median() { return Dbl.median(values, end); }
/** * Min * @param values values in int * @return min */ public static double min( double[] values, int length ) { return min(values, 0, length); }
@Universal public static double idx( final double[] array, final int index ) { final int i = calculateIndex( array, index ); return array[ i ]; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; DoubleList values = (DoubleList) o; if (end != values.end) return false; if (!Dbl.equals(0, end, this.values, values.values)) return false; return true; }
@Universal public static double[] slcEnd( final double[] array, final int endIndex ) { final int end = calculateEndIndex(array, endIndex); final int newLength = end; // + (endIndex < 0 ? 1 : 0); if ( newLength < 0 ) { throw new ArrayIndexOutOfBoundsException( String.format( "start index %d, length %d", endIndex, array.length ) ); } double[] newArray = new double[ newLength ]; System.arraycopy( array, 0, newArray, 0, newLength ); return newArray; }
@Universal public static double[] insert( final double[] array, final int fromIndex, final double[] values ) { if ( fromIndex >= array.length ) { return add( array, values ); } final int index = calculateIndex( array, fromIndex ); //Object newArray = Array.newInstance(array.getClass().getComponentType(), array.length+1); double[] newArray = new double[ array.length + values.length ]; if ( index != 0 ) { /* Copy up to the length in the array before the index. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, 0, newArray, 0, index ); } boolean lastIndex = index == array.length - 1; int toIndex = index + values.length; int remainingIndex = newArray.length - toIndex; if ( lastIndex ) { /* Copy the area after the insert. Make sure we don't write over the end. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, index, newArray, index + values.length, remainingIndex ); } else { /* Copy the area after the insert. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, index, newArray, index + values.length, remainingIndex ); } for ( int i = index, j = 0; i < toIndex; i++, j++ ) { newArray[ i ] = values[ j ]; } return newArray; }
/** * Average * @param values values * @return average */ public static double mean( double[] values, final int length ) { return mean(values, 0, length); }
@Universal public static double[] slc( double[] array, int startIndex, int endIndex ) { final int start = calculateIndex( array, startIndex ); final int end = calculateEndIndex(array, endIndex); final int newLength = end - start; if ( newLength < 0 ) { throw new ArrayIndexOutOfBoundsException( String.format( "start index %d, end index %d, length %d", startIndex, endIndex, array.length ) ); } double[] newArray = new double[ newLength ]; System.arraycopy( array, start, newArray, 0, newLength ); return newArray; }
/** * Calculate Median * @param values values * @return median */ public static double median(double[] values) { return median(values, 0, values.length); }
/** * Min * @param values values in int * @return min */ public static double min( double[] values ) { return min(values, 0, values.length); }
@Universal public static void idx( final double[] array, int index, double value ) { final int i = calculateIndex( array, index ); array[ i ] = value; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; DoubleList values = (DoubleList) o; if (end != values.end) return false; if (!Dbl.equals(0, end, this.values, values.values)) return false; return true; }
@Universal public static double[] slcEnd( final double[] array, final int endIndex ) { final int end = calculateEndIndex(array, endIndex); final int newLength = end; // + (endIndex < 0 ? 1 : 0); if ( newLength < 0 ) { throw new ArrayIndexOutOfBoundsException( String.format( "start index %d, length %d", endIndex, array.length ) ); } double[] newArray = new double[ newLength ]; System.arraycopy( array, 0, newArray, 0, newLength ); return newArray; }
@Universal public static double[] insert( final double[] array, final int fromIndex, final double[] values ) { if ( fromIndex >= array.length ) { return add( array, values ); } final int index = calculateIndex( array, fromIndex ); //Object newArray = Array.newInstance(array.getClass().getComponentType(), array.length+1); double[] newArray = new double[ array.length + values.length ]; if ( index != 0 ) { /* Copy up to the length in the array before the index. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, 0, newArray, 0, index ); } boolean lastIndex = index == array.length - 1; int toIndex = index + values.length; int remainingIndex = newArray.length - toIndex; if ( lastIndex ) { /* Copy the area after the insert. Make sure we don't write over the end. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, index, newArray, index + values.length, remainingIndex ); } else { /* Copy the area after the insert. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, index, newArray, index + values.length, remainingIndex ); } for ( int i = index, j = 0; i < toIndex; i++, j++ ) { newArray[ i ] = values[ j ]; } return newArray; }