Class CsvRow
- java.lang.Object
-
- com.opengamma.strata.collect.io.CsvRow
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Checks if this CSV file equals another.String
field(int index)
Gets the specified field.int
fieldCount()
Gets the number of fields.ImmutableList<String>
fields()
Gets all fields in the row.Optional<String>
findField(String header)
Gets a single field value from the row by header.Optional<String>
findField(Pattern headerPattern)
Gets a single field value from the row by header pattern.Optional<String>
findValue(String header)
Gets a single value from the row by header.<T> Optional<T>
findValue(String header, Function<String,T> postProcessor)
Gets a single value from the row by header pattern, post processing the result.Optional<String>
findValue(Pattern headerPattern)
Gets a single value from the row by header pattern.<T> Optional<T>
findValue(Pattern headerPattern, Function<String,T> postProcessor)
Gets a single value from the row by header pattern, post processing the result.String
getField(String header)
Gets a single field value from the row by header.<T> T
getField(String header, Function<String,T> postProcessor)
Gets a single field value from the row by header, post processing the result.String
getField(Pattern headerPattern)
Gets a single field value from the row by header pattern.<T> T
getField(Pattern headerPattern, Function<String,T> postProcessor)
Gets a single field value from the row by header pattern, post processing the result.String
getValue(String header)
Gets a single field value from the row by header.<T> T
getValue(String header, Function<String,T> postProcessor)
Gets a single field value from the row by header, post processing the result.String
getValue(Pattern headerPattern)
Gets a single field value from the row by header pattern.<T> T
getValue(Pattern headerPattern, Function<String,T> postProcessor)
Gets a single field value from the row by header pattern, post processing the result.int
hashCode()
Returns a suitable hash code for the CSV file.ImmutableList<String>
headers()
Gets the header row.int
lineNumber()
Gets the line number in the source file.CsvRow
subRow(int startInclusive)
Obtains a sub-row, containing a selection of fields by index.CsvRow
subRow(int startInclusive, int endExclusive)
Obtains a sub-row, containing a selection of fields by index.String
toString()
Returns a string describing the CSV file.
-
-
-
Method Detail
-
headers
public ImmutableList<String> headers()
Gets the header row.If there is no header row, an empty list is returned.
- Returns:
- the header row
-
lineNumber
public int lineNumber()
Gets the line number in the source file.- Returns:
- the line number
-
fields
public ImmutableList<String> fields()
Gets all fields in the row.- Returns:
- the fields
-
fieldCount
public int fieldCount()
Gets the number of fields.This will never be less than the number of headers.
- Returns:
- the number of fields
-
field
public String field(int index)
Gets the specified field.- Parameters:
index
- the field index- Returns:
- the field
- Throws:
IndexOutOfBoundsException
- if the field index is invalid
-
getField
public String getField(String header)
Gets a single field value from the row by header.This returns the value of the first column where the header matches the specified header. Matching is case insensitive.
- Parameters:
header
- the column header- Returns:
- the field value, trimmed unless surrounded by quotes
- Throws:
IllegalArgumentException
- if the header is not found
-
getField
public <T> T getField(String header, Function<String,T> postProcessor)
Gets a single field value from the row by header, post processing the result.This returns the value of the first column where the header matches the specified header. Matching is case insensitive.
The value is post processed via the specified function.
- Type Parameters:
T
- the post process result type- Parameters:
header
- the column headerpostProcessor
- the post processor- Returns:
- the post processed field value
- Throws:
IllegalArgumentException
- if the header is not found
-
findField
public Optional<String> findField(String header)
Gets a single field value from the row by header.This returns the value of the first column where the header matches the specified header. Matching is case insensitive.
If the value needs post processing, use
Optional.map(Function)
.- Parameters:
header
- the column header- Returns:
- the field value, trimmed unless surrounded by quotes, empty if not found
-
getField
public String getField(Pattern headerPattern)
Gets a single field value from the row by header pattern.This returns the value of the first column where the header matches the specified header pattern.
- Parameters:
headerPattern
- the header pattern to match- Returns:
- the field value, trimmed unless surrounded by quotes
- Throws:
IllegalArgumentException
- if the header is not found
-
getField
public <T> T getField(Pattern headerPattern, Function<String,T> postProcessor)
Gets a single field value from the row by header pattern, post processing the result.This returns the value of the first column where the header matches the specified header pattern.
The value is post processed via the specified function.
- Type Parameters:
T
- the post process result type- Parameters:
headerPattern
- the header pattern to matchpostProcessor
- the post processor- Returns:
- the post processed field value
- Throws:
IllegalArgumentException
- if the header is not found
-
findField
public Optional<String> findField(Pattern headerPattern)
Gets a single field value from the row by header pattern.This returns the value of the first column where the header matches the specified header pattern.
If the value needs post processing, use
Optional.map(Function)
.- Parameters:
headerPattern
- the header pattern to match- Returns:
- the field value, trimmed unless surrounded by quotes, empty if not found
-
getValue
public String getValue(String header)
Gets a single field value from the row by header.This returns the value of the first column where the header matches the specified header. If the header is not found or the value found is an empty string, then an IllegalArgumentException is thrown.
- Parameters:
header
- the column header- Returns:
- the field value, trimmed unless surrounded by quotes
- Throws:
IllegalArgumentException
- if the header is not found or if the value in the field is empty.
-
getValue
public <T> T getValue(String header, Function<String,T> postProcessor)
Gets a single field value from the row by header, post processing the result.This returns the value of the first column where the header matches the specified header. If the header is not found or the value found is an empty string, then an IllegalArgumentException is thrown.
The value is post processed via the specified function.
- Type Parameters:
T
- the post process result type- Parameters:
header
- the column headerpostProcessor
- the post processor- Returns:
- the post processed field value
- Throws:
IllegalArgumentException
- if the header is not found or if the value in the field is empty.
-
findValue
public Optional<String> findValue(String header)
Gets a single value from the row by header.This returns the value of the first column where the header matches the specified header pattern. If the value is an empty string, then an empty optional is returned.
If the value needs post processing, use
findValue(String, Function)
.- Parameters:
header
- the column header- Returns:
- the field value, trimmed unless surrounded by quotes, empty if not found
-
findValue
public <T> Optional<T> findValue(String header, Function<String,T> postProcessor)
Gets a single value from the row by header pattern, post processing the result.This returns the value of the first column where the header matches the specified header pattern. If the value is an empty string, then an empty optional is returned.
- Type Parameters:
T
- the post process result type- Parameters:
header
- the column headerpostProcessor
- the post processor- Returns:
- the field value, trimmed unless surrounded by quotes, empty if not found
-
getValue
public String getValue(Pattern headerPattern)
Gets a single field value from the row by header pattern.This returns the value of the first column where the header matches the specified header pattern. If the header is not found or the value found is an empty string, then an IllegalArgumentException is thrown.
- Parameters:
headerPattern
- the header pattern to match- Returns:
- the field value, trimmed unless surrounded by quotes
- Throws:
IllegalArgumentException
- if the header is not found or if the value in the field is empty.
-
getValue
public <T> T getValue(Pattern headerPattern, Function<String,T> postProcessor)
Gets a single field value from the row by header pattern, post processing the result.This returns the value of the first column where the header matches the specified header pattern. If the header is not found or the value found is an empty string, then an IllegalArgumentException is thrown.
The value is post processed via the specified function.
- Type Parameters:
T
- the post process result type- Parameters:
headerPattern
- the header pattern to matchpostProcessor
- the post processor- Returns:
- the post processed field value
- Throws:
IllegalArgumentException
- if the header is not found or if the value in the field is empty.
-
findValue
public Optional<String> findValue(Pattern headerPattern)
Gets a single value from the row by header pattern.This returns the value of the first column where the header matches the specified header pattern. If the value is an empty string, then an empty optional is returned.
If the value needs post processing, use
findValue(Pattern, Function)
.- Parameters:
headerPattern
- the header pattern to match- Returns:
- the field value, trimmed unless surrounded by quotes, empty if not found
-
findValue
public <T> Optional<T> findValue(Pattern headerPattern, Function<String,T> postProcessor)
Gets a single value from the row by header pattern, post processing the result.This returns the value of the first column where the header matches the specified header pattern. If the value is an empty string, then an empty optional is returned.
- Type Parameters:
T
- the post process result type- Parameters:
headerPattern
- the header pattern to matchpostProcessor
- the post processor- Returns:
- the field value, trimmed unless surrounded by quotes, empty if not found
-
subRow
public CsvRow subRow(int startInclusive)
Obtains a sub-row, containing a selection of fields by index.All fields after the specified index are included.
- Parameters:
startInclusive
- the start index, zero-based, inclusive- Returns:
- the sub row
-
subRow
public CsvRow subRow(int startInclusive, int endExclusive)
Obtains a sub-row, containing a selection of fields by index.- Parameters:
startInclusive
- the start index, zero-based, inclusiveendExclusive
- the end index, zero-based, exclusive- Returns:
- the sub row
-
equals
public boolean equals(Object obj)
Checks if this CSV file equals another.The comparison checks the content.
-
hashCode
public int hashCode()
Returns a suitable hash code for the CSV file.
-
-