@Universal public static short[] sliceOf( short[] 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 ) ); } short[] newArray = new short[ newLength ]; System.arraycopy( array, start, newArray, 0, newLength ); return newArray; }
@Universal public static short[] insert( final short[] array, final int idx, final short v ) { Exceptions.requireNonNull( array ); if ( idx >= array.length ) { return add( array, v ); } final int index = calculateIndex( array, idx ); //Object newArray = Array.newInstance(array.getClass().getComponentType(), array.length+1); short[] newArray = new short[ array.length + 1 ]; 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 remainingIndex = array.length - index; 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 + 1, remainingIndex ); } else { /* Copy the area after the insert. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, index, newArray, index + 1, remainingIndex ); } newArray[ index ] = v; return newArray; }
@Universal public static short idx( final short[] array, final int index ) { final int i = calculateIndex( array, index ); return array[ i ]; }
@Universal public static short[] slcEnd( short[] array, int endIndex ) { Exceptions.requireNonNull( array ); 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 ) ); } short[] newArray = new short[ newLength ]; System.arraycopy( array, 0, newArray, 0, newLength ); return newArray; }
@Test public void testSliceOf() { short[] array = Shrt.array((short)0, (short)1, (short)2, (short)3, (short)4, (short)5, (short)6); short[] array2 = Shrt.sliceOf(array, 0, 100); Shrt.equalsOrDie(array, array2); }
ok |= idx( shorts, 0 ) == 1 || die( "" + idx( shorts, 0 ) ); ok |= idx( shorts, 1 ) == 2 || die( "" + idx( shorts, 1 ) ); ok |= idx( shorts, 2 ) == 3 || die( "" + idx( shorts, 2 ) ); ok |= idx( shorts, 0 ) == 1 || die( "" + idx( shorts, 0 ) ); ok |= idx( shorts, 1 ) == 2 || die( "" + idx( shorts, 1 ) ); ok |= idx( shorts, 2 ) == 3 || die( "" + idx( shorts, 2 ) ); ok |= idx( shorts, 0 ) == 1 || die( "" + idx( shorts, 0 ) ); ok |= idx( shorts, 1 ) == 2 || die( "" + idx( shorts, 1 ) ); ok |= idx( shorts, 2 ) == 3 || die( "" + idx( shorts, 2 ) ); ok |= idx( shorts, 0 ) == 2 || die( "" + idx( shorts, 0 ) ); ok |= idx( shorts, 1 ) == 2 || die( "" + idx( shorts, 1 ) ); ok |= idx( shorts, 2 ) == 2 || die( "" + idx( shorts, 2 ) );
@Universal public static short[] insert( final short[] array, final int idx, final short v ) { Exceptions.requireNonNull( array ); if ( idx >= array.length ) { return add( array, v ); } final int index = calculateIndex( array, idx ); //Object newArray = Array.newInstance(array.getClass().getComponentType(), array.length+1); short[] newArray = new short[ array.length + 1 ]; 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 remainingIndex = array.length - index; 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 + 1, remainingIndex ); } else { /* Copy the area after the insert. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, index, newArray, index + 1, remainingIndex ); } newArray[ index ] = v; return newArray; }
@Universal public static short idx( final short[] array, final int index ) { final int i = calculateIndex( array, index ); return array[ i ]; }
@Universal public static short[] endSliceOf( short[] array, int endIndex ) { Exceptions.requireNonNull( array ); 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 ) ); } short[] newArray = new short[ newLength ]; System.arraycopy( array, 0, newArray, 0, newLength ); return newArray; }
@Universal public static short[] slc( short[] 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 ) ); } short[] newArray = new short[ newLength ]; System.arraycopy( array, start, newArray, 0, newLength ); return newArray; }
return add( array, values ); final int index = calculateIndex( array, fromIndex );
@Universal public static void idx( final short[] array, int index, short value ) { final int i = calculateIndex( array, index ); array[ i ] = value; }
@Universal public static short[] endSliceOf( short[] array, int endIndex ) { Exceptions.requireNonNull( array ); 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 ) ); } short[] newArray = new short[ newLength ]; System.arraycopy( array, 0, newArray, 0, newLength ); return newArray; }
@Universal public static short[] slc( short[] 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 ) ); } short[] newArray = new short[ newLength ]; System.arraycopy( array, start, newArray, 0, newLength ); return newArray; }
return add( array, values ); final int index = calculateIndex( array, fromIndex );
@Universal public static void idx( final short[] array, int index, short value ) { final int i = calculateIndex( array, index ); array[ i ] = value; }
@Universal public static short[] slcEnd( short[] array, int endIndex ) { Exceptions.requireNonNull( array ); 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 ) ); } short[] newArray = new short[ newLength ]; System.arraycopy( array, 0, newArray, 0, newLength ); return newArray; }
@Universal public static short[] sliceOf( short[] 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 ) ); } short[] newArray = new short[ newLength ]; System.arraycopy( array, start, newArray, 0, newLength ); return newArray; }
@Universal public static short[] insert( final short[] array, final int idx, final short v ) { Exceptions.requireNonNull( array ); if ( idx >= array.length ) { return add( array, v ); } final int index = calculateIndex( array, idx ); //Object newArray = Array.newInstance(array.getClass().getComponentType(), array.length+1); short[] newArray = new short[ array.length + 1 ]; 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 remainingIndex = array.length - index; 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 + 1, remainingIndex ); } else { /* Copy the area after the insert. */ /* src sbegin dst dbegin length of copy */ System.arraycopy( array, index, newArray, index + 1, remainingIndex ); } newArray[ index ] = v; return newArray; }
@Universal public static short idx( final short[] array, final int index ) { final int i = calculateIndex( array, index ); return array[ i ]; }