hudson.plugins.tfs.util
Class TextTableParser

java.lang.Object
  extended by hudson.plugins.tfs.util.TextTableParser

public class TextTableParser
extends java.lang.Object

Parser for the text table output from the TF tool. The table will always begin with a number of columns that specifies how wide each column is. The text table parser will use the number of columns and their width to be able to parse the lines that comes after the column definition. Some columns are optional, ie they does not contain any data and the line ends before the optional column begins.

An example of how a separator definition may look. The table consists of 3 columns; column 1 contains a string with at most 5 chars, column 2 contains a string with at most 2 chars and column 3 may contain a string with at most 4 chars. The third column is optional.

 ----- -- ----
 Data1 A  Data
 Data2 B
 Data3 C  Data
 
TextTableParser t = new TextTableParser(reader, 1); t.nextRow() // first row assertEquals("Data1", t.getColumn(0)); assertEquals("Data", t.getColumn(2)); t.nextRow(); // Second row assertEquals("Data2", t.getColumn(0)); assertNull(t.getColumn(2)); t.nextRow(); // Third row assertEquals("Data3", t.getColumn(0)); assertEquals("Data", t.getColumn(2));

Author:
Erik Ramfelt

Constructor Summary
TextTableParser(java.io.Reader reader)
           
TextTableParser(java.io.Reader reader, int optionalColumnCount)
           
 
Method Summary
 java.lang.String getColumn(int index)
          Return the value in the specified column
 int getColumnCount()
          Returns the number of columns
 boolean nextRow()
          Move to the next row
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextTableParser

public TextTableParser(java.io.Reader reader)
                throws java.io.IOException
Throws:
java.io.IOException

TextTableParser

public TextTableParser(java.io.Reader reader,
                       int optionalColumnCount)
                throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getColumnCount

public int getColumnCount()
                   throws java.io.IOException
Returns the number of columns

Returns:
the number of columns
Throws:
java.io.IOException

getColumn

public java.lang.String getColumn(int index)
                           throws java.io.IOException
Return the value in the specified column

Parameters:
index - the column index
Returns:
the value in the specified column; null if there is no value (the column is optional)
Throws:
java.io.IOException

nextRow

public boolean nextRow()
                throws java.io.IOException
Move to the next row

Returns:
true, if there was a next row; false, if there is no next row.
Throws:
java.io.IOException


Copyright © 2008. All Rights Reserved.