public final class TableColumnCollection
extends java.lang.Object
Constructor and Description |
---|
TableColumnCollection(java.lang.Class<? extends java.lang.Enum<?>> enumClass)
Creates a new table-column collection from a set of enum constants.
|
TableColumnCollection(java.lang.Iterable<java.lang.String> names)
Creates a new table-column names collection.
|
TableColumnCollection(java.lang.Object... names)
Creates a new table-column names collection.
|
TableColumnCollection(java.lang.String... names)
Creates a new table-column names collection.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String[] |
checkNames(java.lang.Object[] columnNames,
java.util.function.Function<java.lang.String,java.lang.RuntimeException> exceptionFactory)
Checks that a column name, as objects, array is valid.
|
static java.lang.String[] |
checkNames(java.lang.String[] columnNames,
java.util.function.Function<java.lang.String,java.lang.RuntimeException> exceptionFactory)
Checks that a column name array is valid.
|
int |
columnCount()
Returns the number of columns.
|
boolean |
contains(java.lang.String name)
Check whether there is such a column by name.
|
boolean |
containsAll(java.lang.Iterable<java.lang.String> names)
Checks whether columns contain all the names in an array.
|
boolean |
containsAll(java.lang.String... names)
Checks whether columns contain all the names in an array.
|
boolean |
containsExactly(java.lang.String... names)
Checks whether columns contain all the names in an array and no other.
|
boolean |
equals(java.lang.Object o) |
int |
hashCode() |
int |
indexOf(java.lang.String name)
Returns the index of a column by its name.
|
boolean |
matches(int index,
java.lang.String name)
Checks a column names matches given one.
|
boolean |
matchesAll(int offset,
java.lang.String... names)
Checks an array of column matches the column names starting from a given index.
|
boolean |
matchesExactly(java.lang.String... names)
Checks whether columns contain all the names in an array and no other and in the very same order.
|
java.lang.String |
nameAt(int index)
Returns the name of a column by its index.
|
java.util.List<java.lang.String> |
names()
Returns the column names ordered by column index.
|
public TableColumnCollection(java.lang.Iterable<java.lang.String> names)
The new instance will have its own copy of the input name array, thus is safe to modify such an array after calling this constructor; it won't modify the state of this object.
names
- the column names.java.lang.IllegalArgumentException
- if names
is not a valid column name iterable
of names as determined by checkNames
.public TableColumnCollection(java.lang.String... names)
The new instance will have its own copy of the input name array, thus is safe to modify such an array after calling this constructor; it won't modify the state of this object.
names
- the column names.java.lang.IllegalArgumentException
- if names
is not a valid column name array
of names as determined by checkNames
.public TableColumnCollection(java.lang.Object... names)
The new instance will have its own copy of the input name array, thus is safe to modify such an array after calling this constructor; it won't modify the state of this object.
names
- the column names. They will be transformed into strings using toString
.java.lang.IllegalArgumentException
- if names
is not a valid column name array
of names as determined by checkNames
.public TableColumnCollection(java.lang.Class<? extends java.lang.Enum<?>> enumClass)
The new instance will have one column for enum value in enumClass
, in their
ordinal order.
The toString
transformation of each constant is used
as the column name. Notice that this might differ from the constant name if
this method is overloaded by the enum.
enumClass
- the input enum class.java.lang.IllegalArgumentException
- if enumClass
is null
or is actually
not an enum class or the corresponding names are illegal.public java.util.List<java.lang.String> names()
null
, a unmodifiable view to this collection column names.public java.lang.String nameAt(int index)
Column indexes are 0-based.
index
- the target column index.null
.java.lang.IllegalArgumentException
- if index
is not a valid column index.public int indexOf(java.lang.String name)
name
- the query column name.-1
if there is not such a column, 0 or greater otherwise.public boolean contains(java.lang.String name)
name
- the query name.true
iff there is a column with such a name
.java.lang.IllegalArgumentException
- if name
is null
.public boolean containsAll(java.lang.String... names)
names
- the names to test.true
iff all the names in names
correspond to columns in this collection.java.lang.IllegalArgumentException
- if names
is null
or contains any null
.public boolean containsAll(java.lang.Iterable<java.lang.String> names)
names
- the names to test.true
iff all the names in names
correspond to columns in this collection.java.lang.IllegalArgumentException
- if names
is null
or contains any null
.public boolean containsExactly(java.lang.String... names)
names
- the names to test.true
iff all the names in names
correspond to columns in this collection, and there
is no other column name.java.lang.IllegalArgumentException
- if names
is null
or contains null
.public boolean matches(int index, java.lang.String name)
A match against a column index beyond the last column returns false
.
index
- the column index to test.name
- the expected column name.true
iff the the column at index
's name is equal to the input name
.java.lang.IllegalArgumentException
- if name
is null
or index
is negative.public boolean matchesAll(int offset, java.lang.String... names)
offset
- the column index to match to the first name in names
test.names
- the expected column names.true
iff the the column names starting from index
is equal to the input names
.java.lang.IllegalArgumentException
- if names
is null
, contains any null
or index
is not a valid index.public boolean matchesExactly(java.lang.String... names)
names
- the names to test.true
iff all the names in names
correspond to columns in this collection in the same
order, and there is no other column.java.lang.IllegalArgumentException
- if names
is null
or contains null
.public int columnCount()
column
public static java.lang.String[] checkNames(java.lang.Object[] columnNames, java.util.function.Function<java.lang.String,java.lang.RuntimeException> exceptionFactory)
The actual column names to test are obtained by mapping its object to its string representation using
toString
.
Assuming that it is null-value free, a column name array is invalid if:
When the input array is invalid, an exception is thrown using the exception factory function provided.
The message passed to the factory explains why the column name array is invalid
.Notice that a null
array or a null
containing array is considered a illegal argument caused by
a bug and a IllegalArgumentException
will be thrown instead.
null
, the same reference as the input column name array columnNames
.java.lang.IllegalArgumentException
- if columnNames
is null
, or it contains any null
, or exceptionFactory
is null
or ir returns a null
when invoked.java.lang.RuntimeException
- if columnNames
does not contain a valid list of column names. The exact type will depend on the
input exceptionFactory
.public static java.lang.String[] checkNames(java.lang.String[] columnNames, java.util.function.Function<java.lang.String,java.lang.RuntimeException> exceptionFactory)
Assuming that it is null-value free, a column name array is invalid if:
When the input array is invalid, an exception is thrown using the exception factory function provided.
The message passed to the factory explains why the column name array is invalid
.Notice that a null
array or a null
containing array is considered a illegal argument caused by
a bug an a IllegalArgumentException
will be thrown instead.
null
, the same reference as the input column name array columnNames
.java.lang.IllegalArgumentException
- if columnNames
is null
, or it contains any null
, or exceptionFactory
is null
or ir returns a null
when invoked.java.lang.RuntimeException
- if columnNames
does not contain a valid list of column names. The exact type will depend on the
input exceptionFactory
.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object