@Immutable public interface Property extends Iterable<Object>, Comparable<Property>, Readable, Serializable
This class is designed to be used with the ValueFactories
interface and the particular ValueFactory
that
corresponds to the type of value you'd like to use. The ValueFactory
will then return the values (if no type
conversion is required) or will convert the values using the appropriate conversion algorithm.
The following example shows how to obtain the String
representations of the property values
:
ValueFactories valueFactories = ... Property property = ... Iterator<String> iter = valueFactories.getStringFactory().create(property.getValues()); while ( iter.hasNext() ) { System.out.println(iter.next()); }Meanwhile, the
long value factory
converts the values to long
, the
date value factory
converts the values to DateTime
instances, and so on.
This technique is much better and far safer than casting the values. It is possible that some Property instances contain heterogeneous values, so casting may not always work. Also, this technique guarantees that the values are properly converted if the type is not what you expected.
Modifier and Type | Interface and Description |
---|---|
static interface |
Property.ValueTypeTransformer<T>
Interface which allows the conversion of a property value to a given type.
|
Modifier and Type | Method and Description |
---|---|
Object |
getFirstValue()
Obtain the property's first value in its natural form.
|
Name |
getName()
Get the name of the property.
|
Object |
getValue(int index)
Returns the value of the property at the given index.
|
Iterator<?> |
getValues()
Obtain the property's values in their natural form.
|
Object[] |
getValuesAsArray()
Obtain the property's values as an array of objects in their natural form.
|
<T> T[] |
getValuesAsArray(Property.ValueTypeTransformer<T> valueTypeTransformer,
Class<T> type)
Convert the values of this property to the given type, using the specified type transformer.
|
<T> T[] |
getValuesAsArray(ValueFactory<T> valueFactory)
Convert the values of this property to whatever type the given value factory is used to create.
|
boolean |
isBinary()
Determine whether this property is a binary property or not.
|
boolean |
isEmpty()
Determine whether this property has no actual values.
|
boolean |
isMultiple()
Determine whether the property currently has multiple values.
|
boolean |
isReference()
Determine whether this property contains reference values, based upon the first value in the property.
|
boolean |
isSimpleReference()
Determine whether this property contains simple reference values, based upon the first value in the property.
|
boolean |
isSingle()
Determine whether the property currently has a single value.
|
int |
size()
Get the number of actual values in this property.
|
forEach, iterator, spliterator
compareTo
Name getName()
int size()
multiple values
, then this
method may return a value greater than 1. If the property only allows a single value
, then this method
will return either 0 or 1. This method may return 0 regardless of whether the property allows a single
value
, or multiple values
.boolean isMultiple()
isSingle()
,
isEmpty()
boolean isSingle()
isMultiple()
,
isEmpty()
boolean isEmpty()
true
regardless of whether the
property allows a single value
, or multiple values
.
This method is a convenience method that is equivalent to size() == 0
.
isMultiple()
,
isSingle()
boolean isReference()
PropertyType.SIMPLEREFERENCE
properties *are not* treated as references in order to avoid setting the
back-pointer.boolean isSimpleReference()
PropertyType.SIMPLEREFERENCE
boolean isBinary()
Object getFirstValue()
isEmpty() ? null : iterator().next()
empty
Iterable.iterator()
,
getValues()
,
getValuesAsArray()
,
isEmpty()
Iterator<?> getValues()
iterator()
.
A valid iterator is returned if the property has single valued
or multi-valued
.
The resulting iterator is immutable, and all property values are immutable.
getFirstValue()
,
Iterable.iterator()
,
getValuesAsArray()
,
ValueFactory.create(Iterator)
Object[] getValuesAsArray()
A valid array is return if the property has single valued
or multi-valued
, or a
null value is returned if the property is empty
.
The resulting array is a copy, guaranteeing immutability for the property.
getFirstValue()
,
Iterable.iterator()
,
getValues()
,
ValueFactory.create(Object[])
Object getValue(int index) throws IndexOutOfBoundsException
index
- an int
representing the index at which to retrieve the value. If the value is 0
, this is
equivalent to calling getFirstValue()
null
if the property is empty.IndexOutOfBoundsException
- if the given index is outside the interval of values of the property.<T> T[] getValuesAsArray(ValueFactory<T> valueFactory) throws ValueFormatException
valueFactory
- a AbstractValueFactory
representing the factory which will
be used to attempt the conversion of each value.ValueFormatException
- if the conversion cannot be performed for any value in the array of values.<T> T[] getValuesAsArray(Property.ValueTypeTransformer<T> valueTypeTransformer, Class<T> type) throws ValueFormatException
valueTypeTransformer
- a Property.ValueTypeTransformer
representing the transformer which will
be used to attempt the conversion of each value.type
- a Class
indicating the type to which the transformation is performed; required because of type erasure.ValueFormatException
- if the conversion cannot be performed for any value in the array of values.Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.