Package nzilbb.labbcat.server.search
Class CsvResults
- java.lang.Object
-
- nzilbb.labbcat.server.search.CsvResults
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterator<String>
,SearchResults
public class CsvResults extends Object implements SearchResults
Search results constructed from a CSV file.- Author:
- Robert Fromont robert@fromont.net.nz
-
-
Constructor Summary
Constructors Constructor Description CsvResults(File csvFile, nzilbb.sql.ConnectionFactory db)
Constructor from CSV File.CsvResults(CsvResults other)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close all open resources (there are none).Connection
getConnection()
Getter forconnection
: Database connection.List<String>
getCsvColumns()
Getter forcsvColumns
: Columns available in csv source file, if any.char
getCsvFieldDelimiter()
Getter forcsvFieldDelimiter
: Field delimiter to use when reading the file.File
getCsvFile()
Getter forcsvFile
: The results file to parse.nzilbb.sql.ConnectionFactory
getDb()
Getter fordb
: Factory for generating connections to the database.String
getLastMatchId()
Getter forlastMatchId
: The ID of the last match the iterator returned fromnext()
org.apache.commons.csv.CSVRecord
getLastRecord()
Getter forlastRecord
: The last CSV record parsed, if any.String
getName()
SearchResults method: A descriptive name for the collection.int
getPageLength()
Getter forpageLength
: The maximum number of results to return fromnext()
, or 0 for no maximum.String
getTargetColumn()
Getter fortargetColumn
: Name of the column that identifies each match (default "MatchId").boolean
hasNext()
Iterator method: Returns true if the iteration has more elements.String
next()
Iterator method: Returns the next result ID.void
reset()
SearchResults method: Resets the iterator to the beginning of the listboolean
seek(int n)
Go to the nth item in the list, so it will be the next returned bynext()
.CsvResults
setConnection(Connection newConnection)
Setter forconnection
: Database connection.CsvResults
setCsvFieldDelimiter(char newCsvFieldDelimiter)
Setter forcsvFieldDelimiter
: Field delimiter to use when reading the file.CsvResults
setDb(nzilbb.sql.ConnectionFactory newDb)
Setter fordb
: Factory for generating connections to the database.CsvResults
setName(String newName)
Setter forname
: Name of result set.SearchResults
setPageLength(int newPageLength)
Setter forpageLength
: The maximum number of results to return fromnext()
, or 0 for no maximum.CsvResults
setTargetColumn(String newTargetColumn)
Setter fortargetColumn
: Name of the column that identifies each match (default "MatchId").int
size()
SearchResults method: Returns the number of utterances in the collection.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Constructor Detail
-
CsvResults
public CsvResults(File csvFile, nzilbb.sql.ConnectionFactory db) throws IOException
Constructor from CSV File.- Parameters:
csvFile
- The results file to parse.- Throws:
IOException
-
CsvResults
public CsvResults(CsvResults other) throws IOException
Copy constructor.- Parameters:
other
- The other results object.- Throws:
IOException
-
-
Method Detail
-
getCsvFile
public File getCsvFile()
Getter forcsvFile
: The results file to parse.- Returns:
- The results file to parse.
-
getCsvColumns
public List<String> getCsvColumns()
Getter forcsvColumns
: Columns available in csv source file, if any.- Returns:
- Columns available in csv source file, if any.
-
getCsvFieldDelimiter
public char getCsvFieldDelimiter()
Getter forcsvFieldDelimiter
: Field delimiter to use when reading the file.- Returns:
- Field delimiter to use when reading the file.
-
setCsvFieldDelimiter
public CsvResults setCsvFieldDelimiter(char newCsvFieldDelimiter)
Setter forcsvFieldDelimiter
: Field delimiter to use when reading the file.- Parameters:
newCsvFieldDelimiter
- Field delimiter to use when reading the file.
-
getTargetColumn
public String getTargetColumn()
Getter fortargetColumn
: Name of the column that identifies each match (default "MatchId").- Returns:
- Name of the column that identifies each match (default "MatchId").
-
setTargetColumn
public CsvResults setTargetColumn(String newTargetColumn)
Setter fortargetColumn
: Name of the column that identifies each match (default "MatchId").- Parameters:
newTargetColumn
- Name of the column that identifies each match (default "MatchId").
-
getName
public String getName()
SearchResults method: A descriptive name for the collection.- Specified by:
getName
in interfaceSearchResults
- Returns:
- A descriptive name for the collection.
-
setName
public CsvResults setName(String newName)
Setter forname
: Name of result set.- Parameters:
newName
- Name of result set.
-
getPageLength
public int getPageLength()
Getter forpageLength
: The maximum number of results to return fromnext()
, or 0 for no maximum.- Specified by:
getPageLength
in interfaceSearchResults
- Returns:
- The maximum number of results to return from
next()
, or 0 for no maximum.
-
setPageLength
public SearchResults setPageLength(int newPageLength)
Setter forpageLength
: The maximum number of results to return fromnext()
, or 0 for no maximum.- Specified by:
setPageLength
in interfaceSearchResults
- Parameters:
newPageLength
- The maximum number of results to return fromnext()
, or 0 for no maximum.
-
getLastMatchId
public String getLastMatchId()
Getter forlastMatchId
: The ID of the last match the iterator returned fromnext()
- Specified by:
getLastMatchId
in interfaceSearchResults
- Returns:
- The ID of the last match the iterator returned from
next()
-
getLastRecord
public org.apache.commons.csv.CSVRecord getLastRecord()
Getter forlastRecord
: The last CSV record parsed, if any.- Returns:
- The last CSV record parsed, if any.
-
getConnection
public Connection getConnection() throws SQLException
Getter forconnection
: Database connection.- Returns:
- Database connection.
- Throws:
SQLException
- If a new connection is required, but can't be created.
-
setConnection
public CsvResults setConnection(Connection newConnection)
Setter forconnection
: Database connection.- Parameters:
newConnection
- Database connection.
-
getDb
public nzilbb.sql.ConnectionFactory getDb()
Getter fordb
: Factory for generating connections to the database.- Returns:
- Factory for generating connections to the database.
-
setDb
public CsvResults setDb(nzilbb.sql.ConnectionFactory newDb)
Setter fordb
: Factory for generating connections to the database.- Parameters:
newDb
- Factory for generating connections to the database.
-
reset
public void reset()
SearchResults method: Resets the iterator to the beginning of the list- Specified by:
reset
in interfaceSearchResults
-
size
public int size()
SearchResults method: Returns the number of utterances in the collection.- Specified by:
size
in interfaceSearchResults
- Returns:
- The number of utterances in the collection.
-
seek
public boolean seek(int n)
Go to the nth item in the list, so it will be the next returned bynext()
.- Specified by:
seek
in interfaceSearchResults
- Parameters:
n
- The number of the item to seek to.- Returns:
- true if the nth item exists, false otherwise.
-
hasNext
public boolean hasNext()
Iterator method: Returns true if the iteration has more elements.
-
next
public String next()
Iterator method: Returns the next result ID.
-
close
public void close()
Close all open resources (there are none).- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-