X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Futil%2FBasicTableParser.java;h=4e5f4b35b6d87beb139ca24c053acb53078a43e7;hb=06b38f91bc061d8ab1dfea3b6238c94c95a30d26;hp=bc369bfad1394b88f167ba82e0491da27d666032;hpb=c4cf3c01b3cbb89d98f29418444287ca8703a781;p=jalview.git diff --git a/forester/java/src/org/forester/util/BasicTableParser.java b/forester/java/src/org/forester/util/BasicTableParser.java index bc369bf..4e5f4b3 100644 --- a/forester/java/src/org/forester/util/BasicTableParser.java +++ b/forester/java/src/org/forester/util/BasicTableParser.java @@ -21,7 +21,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.util; @@ -38,13 +38,13 @@ public class BasicTableParser { private BasicTableParser() { } - public static BasicTable parse( final Object source, final String column_delimiter ) throws IOException { + public static BasicTable parse( final Object source, final char column_delimiter ) throws IOException { 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 char column_delimiter, final boolean use_first_separator_only, final boolean use_last_separator_only ) throws IOException { return BasicTableParser.parse( source, @@ -56,12 +56,15 @@ public class BasicTableParser { } public static List> parse( final Object source, - final String column_delimiter, + final char 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(); @@ -90,16 +93,16 @@ public class BasicTableParser { && ( !use_start_of_comment_line || !line.startsWith( start_of_comment_line ) ) ) { saw_first_table = true; if ( use_last_separator_only ) { - String e[] = line.split( column_delimiter ); + final String e[] = line.split( column_delimiter + "" ); final StringBuffer rest = new StringBuffer(); - for( int i = 0; i < e.length - 1; ++i ) { + for( int i = 0; i < ( e.length - 1 ); ++i ) { rest.append( e[ i ].trim() ); } - table.setValue( 0, row, e[ e.length - 1 ] ); - table.setValue( 1, row, rest.toString() ); + table.setValue( 0, row, rest.toString() ); + table.setValue( 1, row, e[ e.length - 1 ] ); } else { - final StringTokenizer st = new StringTokenizer( line, column_delimiter ); + final StringTokenizer st = new StringTokenizer( line, column_delimiter + "" ); int col = 0; if ( st.hasMoreTokens() ) { table.setValue( col++, row, st.nextToken().trim() ); @@ -117,8 +120,8 @@ public class BasicTableParser { } } } + ++row; } - ++row; } if ( !table.isEmpty() ) { tables.add( table );