public static CharSequence concat ( CharSequence ... lines ) { return new CharSequence ( ) { private final StringBuilder content = new StringBuilder ( ) ; private int next ; private int length = - 1 ; @ Override public String toString ( ) { ensure ( length ( ) ) ; return this . content . toString ( ) ; } private void ensure ( int index ) { while ( this . next < lines . length && index >= this . content . length ( ) ) { if ( lines [ this . next ] != null ) { this . content . append ( lines [ this . next ] ) . append ( "\n" ) ; //$NON-NLS-1$ } ++ this . next ; } } @ Override public CharSequence subSequence ( int start , int end ) { ensure ( end - 1 ) ; return this . content . subSequence ( start , end ) ; } @ Override public int length ( ) { if ( this . length < 0 ) { int len = 0 ; for ( final CharSequence seq : lines ) { len += seq . length ( ) + 1 ; } len = Math . max ( 0 , len - 1 ) ; this . length = len ; } return this . length ; } @ Override public char charAt ( int index ) { ensure ( index ) ; return this . content . charAt ( index ) ; } } ; }
Contact the given strings of characters .