public static NodeSequence append ( final NodeSequence first , final NodeSequence second ) { if ( first == null ) { return second != null ? second : emptySequence ( 0 ) ; } if ( second == null ) return first ; int firstWidth = first . width ( ) ; final int secondWidth = second . width ( ) ; if ( firstWidth > 0 && secondWidth > 0 && firstWidth != secondWidth ) { throw new IllegalArgumentException ( "The sequences must have the same width: " + first + " and " + second ) ; } if ( first . isEmpty ( ) ) return second ; if ( second . isEmpty ( ) ) return first ; long firstCount = first . getRowCount ( ) ; long secondCount = second . getRowCount ( ) ; final long count = firstCount < 0 ? - 1 : ( secondCount < 0 ? - 1 : firstCount + secondCount ) ; return new NodeSequence ( ) { private NodeSequence current = first ; @ Override public int width ( ) { return secondWidth ; } @ Override public long getRowCount ( ) { return count ; } @ Override public boolean isEmpty ( ) { return false ; } @ Override public Batch nextBatch ( ) { Batch batch = current . nextBatch ( ) ; while ( batch == null && current == first ) { current = second ; batch = current . nextBatch ( ) ; } return batch ; } @ Override public void close ( ) { try { first . close ( ) ; } finally { second . close ( ) ; } } @ Override public String toString ( ) { return "(append width=" + width ( ) + " " + first + "," + second + " )" ; } } ; }
Create a sequence of nodes that contains the nodes from the first sequence followed by the second sequence .