V
- Base type of all values in the column identified by this instance.public class TableColumn<V> extends Object implements CheckedContainer<V>
TreeTable.Node
instances.
Each TableColumn
instance contains the column header and the type of values
for a particular column. TableColumn
s are used for fetching values from nodes
as in the following example:
public class CityLocation { public static final ColumnTable<String> CITY_NAME = new ColumnTable<>(String.class, "City name"); public static final ColumnTable<Float> LATITUDE = new ColumnTable<>(Float.class, "Latitude"); public static final ColumnTable<Float> LONGITUDE = new ColumnTable<>(Float.class, "Longitude"); private String name; private float latitude; private float longitude; CityLocation(TreeTable.Node myNode) { name = myNode.getValue(CITY_NAME); latitude = myNode.getValue(LATITUDE); longitude = myNode.getValue(LONGITUDE); } }
equals(Object)
method, because the element type
is not a sufficient criterion for differentiating the columns (many columns have values
of the same type) and the header is arbitrary. Consequently
developers who create their own instances are encouraged to declare them as static final
constants as in the above example, and use those constants consistently.
This base class is not serializable because the default deserialization mechanism does not resolve automatically the deserialized instances to the above-cited singleton instances. Developers who need serialization support for their own instances have to resolve them in their own subclass. The following example is one possible way to achieve that goal:
The constants defined in this class use a similar approach for providing serialization support.public class CityLocation { public static final ColumnTable<String> CITY_NAME = new Column<>("CITY_NAME", String.class, "City name"); public static final ColumnTable<Float> LATITUDE = new Column<>("LATITUDE", Float.class, "Latitude"); public static final ColumnTable<Float> LONGITUDE = new Column<>("LONGITUDE", Float.class, "Longitude"); private static final class Column<V> extends TableColumn<V> implements Serializable { private final String field; private Column(String field, Class<V> type, CharSequence header) { super(type, header); this.field = field; } private Object readResolve() throws ObjectStreamException { try { return CityLocation.class.getField(field).get(null); } catch (Exception cause) { // Many exceptions, including unchecked ones. throw new InvalidObjectException(cause.toString()); } } } }
Defined in the sis-utility
module
Modifier and Type | Field and Description |
---|---|
static TableColumn<String> |
IDENTIFIER
Frequently-used constant for a column of object identifiers.
|
static TableColumn<Integer> |
INDEX
Frequently-used constant for a column of index values.
|
static TableColumn<CharSequence> |
NAME
Frequently-used constant for a column of object names.
|
static TableColumn<Class<?>> |
TYPE
Frequently-used constant for a column of object types.
|
static TableColumn<Object> |
VALUE
Frequently-used constant for a column of object values.
|
static TableColumn<Number> |
VALUE_AS_NUMBER
Frequently-used constant for a column of object numerical values.
|
static TableColumn<CharSequence> |
VALUE_AS_TEXT
Frequently-used constant for a column of object textual values.
|
Modifier | Constructor and Description |
---|---|
protected |
TableColumn()
Invoked on deserialization for creating an initially empty instance.
|
|
TableColumn(Class<V> type,
CharSequence header)
Creates a new instance for the given type of values.
|
Modifier and Type | Method and Description |
---|---|
Class<V> |
getElementType()
Returns the base type of all values in any column identified by this
TableColumn
instance. |
InternationalString |
getHeader()
Returns the text to display as column header.
|
String |
toString()
Returns a string representation of this table column.
|
public static final TableColumn<CharSequence> NAME
String
or InternationalString
,
depending on whether the data provide localization support or not.public static final TableColumn<String> IDENTIFIER
public static final TableColumn<Integer> INDEX
public static final TableColumn<Class<?>> TYPE
public static final TableColumn<Object> VALUE
VALUE_AS_TEXT
,
VALUE_AS_NUMBER
public static final TableColumn<CharSequence> VALUE_AS_TEXT
String
or InternationalString
,
depending on whether the data provide localization support or not.public static final TableColumn<Number> VALUE_AS_NUMBER
protected TableColumn()
protected
visibility only because the Java deserialization
mechanism requires so; this constructor shall not be invoked in any other context.
See the Identity comparisons and serialization section in the class
javadoc for more information.public TableColumn(Class<V> type, CharSequence header)
type
- Base type of all values in the column identified by this instance.header
- The text to display as column header.public InternationalString getHeader()
public final Class<V> getElementType()
TableColumn
instance.getElementType
in interface CheckedContainer<V>
Copyright © 2010–2014 The Apache Software Foundation. All rights reserved.