diff --git a/common/source/java/ch/systemsx/cisd/common/parser/TabFileLoader.java b/common/source/java/ch/systemsx/cisd/common/parser/TabFileLoader.java index 2536bec9e3bfbb8534ae24675df77a8ba073751e..fcb988a22ff4a4e3d8450a7c543aa910197710ba 100644 --- a/common/source/java/ch/systemsx/cisd/common/parser/TabFileLoader.java +++ b/common/source/java/ch/systemsx/cisd/common/parser/TabFileLoader.java @@ -35,7 +35,29 @@ import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.exceptions.UserFailureException; /** - * Convenient class to load a tab file and deliver a list of beans of type <code>T</code>. + * Convenient class to load a tab file and deliver a list of beans of type <code>T</code>. The following + * formats for the column headers are recognized. + * <ol><li>Column headers in first line: + * <pre> + * column1 column2 column2 + * </pre> + * <li>Comment section: + * <pre> + * # 1. line of comment + * # 2. line of comment + * # ... + * column1 column2 column2 + * </pre> + * <li>Column headers at the end of the comment section: + * <pre> + * # 1. line of comment + * # 2. line of comment + * # ... + * # + * #column1 column2 column2 + * </pre> + * + * </ol> * * @author Franz-Josef Elmer */ @@ -85,9 +107,14 @@ public class TabFileLoader<T> List<T> load(Reader reader) { + List<T> result = new ArrayList<T>(); Iterator<Line> lineIterator = createLineIterator(reader); + if (lineIterator.hasNext() == false) + { + return result; + } Line previousLine = null; - Line line = new Line(0, PREFIX); + Line line = null; boolean previousLineHasColumnHeaders = false; while (lineIterator.hasNext()) { @@ -108,7 +135,6 @@ public class TabFileLoader<T> final IAliasPropertyMapper propertyMapper = new HeaderFilePropertyMapper(tokens); parser.setObjectFactory(factory.createFactory(propertyMapper)); ILineFilter filter = AlwaysAcceptLineFilter.INSTANCE; - List<T> result = new ArrayList<T>(); if (previousLineHasColumnHeaders) { result.addAll(parser.parse(Arrays.asList(line).iterator(), filter)); diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/parser/TabFileLoaderTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/parser/TabFileLoaderTest.java index 8e0e931ee68ecbe776b1c71b548ae5fab73fc9dd..43cbcaa28720d97b4bc760c1a820a1c9a98992e1 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/parser/TabFileLoaderTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/parser/TabFileLoaderTest.java @@ -110,9 +110,15 @@ public class TabFileLoaderTest } @Test - public void testFirstLineHasHeadersWithHashSymbol() + public void testFirstLineWithHashSymbol() { - loadAndCheck("#"); + loadAndCheck("#\n"); + } + + @Test + public void testFirstLineWithHashSymbolAndSomething() + { + loadAndCheck("#blabla\n"); } @Test