@Test public void testConcatenation3() { ArrayDouble[] lists = new ArrayDouble[ 10 ]; for ( int i=0 ; i<lists.length ; i++ ) { lists[ i ] = new ArrayDouble( new double[]{} ); } ListDouble concatenated = ListDouble.concatenate( lists ); assertThat( concatenated.size() , equalTo( 0 ) ); try { concatenated.getDouble( 0 ); assertTrue( false ); } catch ( Exception e ) { } }
public static ListDouble concatenate( final ListNumber... lists ) { int size = 0; for ( ListNumber l : lists ) { size += l.size(); } final int sizeCopy = size; return new ListDouble() { @Override public int size() { return sizeCopy; } @Override public double getDouble( int index ) { if ( index < 0 || index >= size() ) { throw new IndexOutOfBoundsException( "Index out of bounds: " + index + ", size: " + size() ); } int startIdx = 0; for ( ListNumber l : lists ) { int endIdx = startIdx + l.size()-1; if ( startIdx <= index && index <= endIdx ) { return l.getDouble( index - startIdx ); } startIdx += l.size(); } return 0; } }; }
ListDouble implements ListNumber, CollectionDouble { public static ListDouble concatenate( final ListNumber... lists ) { int size = 0; for ( ListNumber l : lists ) { size += l.size(); } final int sizeCopy = size; return new ListDouble() { @Override public int size() { return sizeCopy; } @Override public double getDouble( int index ) { if ( index < 0 || index >= size() ) { throw new IndexOutOfBoundsException( "Index out of bounds: " + index + ", size: " + size() ); } int startIdx = 0; for ( ListNumber l : lists ) { int endIdx = startIdx + l.size()-1; if ( startIdx <= index && index <= endIdx ) { return l.getDouble( index - startIdx ); } startIdx += l.size(); } return 0; } }; } }
ListDouble implements ListNumber, CollectionDouble { public static ListDouble concatenate( final ListNumber... lists ) { int size = 0; for ( ListNumber l : lists ) { size += l.size(); } final int sizeCopy = size; return new ListDouble() { @Override public int size() { return sizeCopy; } @Override public double getDouble( int index ) { if ( index < 0 || index >= size() ) { throw new IndexOutOfBoundsException( "Index out of bounds: " + index + ", size: " + size() ); } int startIdx = 0; for ( ListNumber l : lists ) { int endIdx = startIdx + l.size()-1; if ( startIdx <= index && index <= endIdx ) { return l.getDouble( index - startIdx ); } startIdx += l.size(); } return 0; } }; }  }
ListDouble implements ListNumber, CollectionDouble { public static ListDouble concatenate( final ListNumber... lists ) { int size = 0; for ( ListNumber l : lists ) { size += l.size(); } final int sizeCopy = size; return new ListDouble() { @Override public int size() { return sizeCopy; } @Override public double getDouble( int index ) { if ( index < 0 || index >= size() ) { throw new IndexOutOfBoundsException( "Index out of bounds: " + index + ", size: " + size() ); } int startIdx = 0; for ( ListNumber l : lists ) { int endIdx = startIdx + l.size()-1; if ( startIdx <= index && index <= endIdx ) { return l.getDouble( index - startIdx ); } startIdx += l.size(); } return 0; } }; }  @Override IteratorDouble iterator(); @Override float getFloat(int index); @Override long getLong(int index); @Override int getInt(int index); @Override short getShort(int index); @Override byte getByte(int index); @Override void setDouble(int index, double value); @Override void setFloat(int index, float value); @Override void setLong(int index, long value); @Override void setInt(int index, int value); @Override void setShort(int index, short value); @Override void setByte(int index, byte value); static ListDouble concatenate( final ListNumber... lists ); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
ListDouble implements ListNumber, CollectionDouble { public static ListDouble concatenate( final ListNumber... lists ) { int size = 0; for ( ListNumber l : lists ) { size += l.size(); } final int sizeCopy = size; return new ListDouble() { @Override public int size() { return sizeCopy; } @Override public double getDouble( int index ) { if ( index < 0 || index >= size() ) { throw new IndexOutOfBoundsException( "Index out of bounds: " + index + ", size: " + size() ); } int startIdx = 0; for ( ListNumber l : lists ) { int endIdx = startIdx + l.size()-1; if ( startIdx <= index && index <= endIdx ) { return l.getDouble( index - startIdx ); } startIdx += l.size(); } return 0; } }; }  @Override IteratorDouble iterator(); @Override float getFloat(int index); @Override long getLong(int index); @Override int getInt(int index); @Override short getShort(int index); @Override byte getByte(int index); @Override void setDouble(int index, double value); @Override void setFloat(int index, float value); @Override void setLong(int index, long value); @Override void setInt(int index, int value); @Override void setShort(int index, short value); @Override void setByte(int index, byte value); static ListDouble concatenate( final ListNumber... lists ); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }