From 371501ab6d516f73bd8b505c9a94bdfbe61f812e Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Mon, 25 Feb 2008 07:57:31 +0000
Subject: [PATCH] LMS-247 behaviour of TabFileLoader slightly changed

SVN: 4446
---
 .../cisd/common/parser/TabFileLoader.java     | 32 +++++++++++++++++--
 .../cisd/common/parser/TabFileLoaderTest.java | 10 ++++--
 2 files changed, 37 insertions(+), 5 deletions(-)

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 2536bec9e3b..fcb988a22ff 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 8e0e931ee68..43cbcaa2872 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
-- 
GitLab