T - property's value typepublic class PropertyDef<T> extends Object implements Serializable
For a given instance, def. is the property ID
and you can access the value using getPropertyId()def..
read(item)
Example:
PropertyDef<Integer> def = new PropertyDef<Integer>("age", Integer.class, -1);
def.addTo(container);
def.addTo(item, property);
...
int age = def.read(item);
...
Property prop = this.get(container, itemId);
Instances are serializable if the default value is.
| Type | Property and Description |
|---|---|
ObjectProperty<T> |
create
Create a read/write
ObjectProperty using the default value. |
| Modifier and Type | Field and Description |
|---|---|
static Comparator<PropertyDef<?>> |
SORT_BY_NAME
Comparator that sorts instances by name.
|
| Constructor and Description |
|---|
PropertyDef(String name,
Class<T> type)
Convenience contructor.
|
PropertyDef(String name,
Class<T> type,
T defaultValue)
Primary constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addTo(Container container)
Add a property represented by this instance to the given
Container. |
boolean |
addTo(Item item,
Property<T> property)
Add a property represented by this instance to the given
Item. |
boolean |
addTo(Table table)
Add a property represented by this instance to the given
Table. |
Property<T> |
cast(Property<?> property)
Verify that the given property has the same Java type as this property definition.
|
ObjectProperty<T> |
createProperty()
Create a read/write
ObjectProperty using the default value. |
ObjectProperty<T> |
createProperty(T value)
Create a read/write
ObjectProperty using the given value. |
ObjectProperty<T> |
createProperty(T value,
boolean readOnly)
Create a simple
ObjectProperty using the given value. |
boolean |
equals(Object obj) |
Property<T> |
get(Container container,
Object itemId)
Get the property that this instance represents from the given
Container. |
Property<T> |
get(Item item)
Get the property that this instance represents from the given
Item. |
T |
getDefaultValue()
Get the default value for this property.
|
String |
getName()
Get the name of this property.
|
String |
getPropertyId()
Get the ID of this property.
|
Class<T> |
getType()
Get the type of the property value that this instance represents.
|
int |
hashCode() |
boolean |
isSortable()
Determine whether this instance supports sorting property values.
|
T |
read(Item item)
Read the property that this instance represents from the given
Item. |
int |
sort(T value1,
T value2)
Sort two values of this property.
|
String |
toString() |
public ObjectProperty<T> createProperty
ObjectProperty using the default value.
Equivalent to:
createProperty()(def.getDefaultValue());
public static final Comparator<PropertyDef<?>> SORT_BY_NAME
public PropertyDef(String name, Class<T> type)
Equivalent to:
PropertyDef(name, type, null);
name - property name; also serves as the property IDtype - property typeIllegalArgumentException - if name or type is nullpublic PropertyDef(String name, Class<T> type, T defaultValue)
name - property name; also serves as the property IDtype - property typedefaultValue - default value for the property; may be nullIllegalArgumentException - if name or type is nullpublic String getName()
public String getPropertyId()
getName().public Class<T> getType()
public T getDefaultValue()
public ObjectProperty<T> createProperty(T value, boolean readOnly)
ObjectProperty using the given value.value - property valuereadOnly - whether property should be read-onlypublic ObjectProperty<T> createProperty(T value)
ObjectProperty using the given value.
Equivalent to:
createProperty()(value, false);
value - property valuepublic ObjectProperty<T> createProperty()
ObjectProperty using the default value.
Equivalent to:
createProperty()(def.getDefaultValue());
public Property<T> get(Item item)
Item.item - item with propertyClassCastException - if the property found has a different type than this instancepublic Property<T> get(Container container, Object itemId)
Container.container - the container containing the itemsitemId - the ID of the item containing the propertyClassCastException - if the property found has a different type than this instancepublic Property<T> cast(Property<?> property)
This essentially verifies that property.getType() == this.getType().
property - the property to verify; may be nullproperty is null, otherwise propertyClassCastException - if property has a different type than this definitionpublic boolean addTo(Container container)
Container.container - the container to add the property toUnsupportedOperationException - if the operation is not supportedpublic boolean addTo(Item item, Property<T> property)
Item.item - the item to add the property toproperty - the property to be added to the item and identified by this instance's nameUnsupportedOperationException - if the operation is not supportedpublic boolean addTo(Table table)
Table.table - the table to add the property toUnsupportedOperationException - if the operation is not supportedpublic T read(Item item)
Item.item - item with propertyClassCastException - if the property in item has the wrong typepublic boolean isSortable()
The implementation in PropertyDef returns true if this instance's type implements Comparable.
sort()public int sort(T value1, T value2)
The implementation in PropertyDef sorts null values first, then delegates to Comparable
if the values implement it, or else throws UnsupportedOperationException.
value1 - first value, possibly nullvalue2 - second value, possibly nullvalue1 to value2UnsupportedOperationException - if this instance does not support sorting property valuesCopyright © 2017. All rights reserved.