X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Futil%2FBasicTableParser.java;h=2917a3190ea7df605736cd6846f5182f40351600;hb=bc282cbd857f4fb9decdc00b278640bcf146a645;hp=74dd567d39018d25c9c54b0151f5d7c2f72917c5;hpb=72c535142a5e6b0da9c7edb2f605eb835b43e6fb;p=jalview.git diff --git a/forester/java/src/org/forester/util/BasicTableParser.java b/forester/java/src/org/forester/util/BasicTableParser.java index 74dd567..2917a31 100644 --- a/forester/java/src/org/forester/util/BasicTableParser.java +++ b/forester/java/src/org/forester/util/BasicTableParser.java @@ -39,15 +39,18 @@ public class BasicTableParser { } public static BasicTable parse( final Object source, final String column_delimiter ) throws IOException { - return BasicTableParser.parse( source, column_delimiter, false, START_OF_COMMENT_LINE_DEFAULT, false ).get( 0 ); + return BasicTableParser.parse( source, column_delimiter, false, false, START_OF_COMMENT_LINE_DEFAULT, false ) + .get( 0 ); } public static BasicTable parse( final Object source, final String column_delimiter, - final boolean use_first_separator_only ) throws IOException { + final boolean use_first_separator_only, + final boolean use_last_separator_only ) throws IOException { return BasicTableParser.parse( source, column_delimiter, use_first_separator_only, + use_last_separator_only, START_OF_COMMENT_LINE_DEFAULT, false ).get( 0 ); } @@ -55,9 +58,13 @@ public class BasicTableParser { public static List> parse( final Object source, final String column_delimiter, final boolean use_first_separator_only, + final boolean use_last_separator_only, final String start_of_comment_line, final boolean tables_separated_by_single_string_line ) throws IOException { + if ( use_first_separator_only && use_last_separator_only ) { + throw new IllegalArgumentException(); + } final BufferedReader reader = ForesterUtil.obtainReader( source ); final List> tables = new ArrayList>(); BasicTable table = new BasicTable(); @@ -85,22 +92,33 @@ public class BasicTableParser { else if ( !ForesterUtil.isEmpty( line ) && ( !use_start_of_comment_line || !line.startsWith( start_of_comment_line ) ) ) { saw_first_table = true; - final StringTokenizer st = new StringTokenizer( line, column_delimiter ); - int col = 0; - if ( st.hasMoreTokens() ) { - table.setValue( col++, row, st.nextToken().trim() ); - } - if ( !use_first_separator_only ) { - while ( st.hasMoreTokens() ) { - table.setValue( col++, row, st.nextToken().trim() ); + if ( use_last_separator_only ) { + final String e[] = line.split( column_delimiter ); + final StringBuffer rest = new StringBuffer(); + for( int i = 0; i < ( e.length - 1 ); ++i ) { + rest.append( e[ i ].trim() ); } + table.setValue( 0, row, rest.toString() ); + table.setValue( 1, row, e[ e.length - 1 ] ); } else { - final StringBuffer rest = new StringBuffer(); - while ( st.hasMoreTokens() ) { - rest.append( st.nextToken() ); + final StringTokenizer st = new StringTokenizer( line, column_delimiter ); + int col = 0; + if ( st.hasMoreTokens() ) { + table.setValue( col++, row, st.nextToken().trim() ); + } + if ( use_first_separator_only ) { + final StringBuffer rest = new StringBuffer(); + while ( st.hasMoreTokens() ) { + rest.append( st.nextToken() ); + } + table.setValue( col++, row, rest.toString() ); + } + else { + while ( st.hasMoreTokens() ) { + table.setValue( col++, row, st.nextToken().trim() ); + } } - table.setValue( col++, row, rest.toString().trim() ); } ++row; }