Interface IValueDescriptor<V,TBuilder extends IValueBuilder<V>>
-
- Type Parameters:
V
- Type of the Java object representing the data.TBuilder
- Type of the builder for creating a new instance of the data type described by this descriptor.
- All Superinterfaces:
Serializable
- All Known Subinterfaces:
IAnyValueDescriptor
,IBooleanValueDescriptor
,IConstValueDescriptor<V>
,IFloatValueDescriptor
,IIntegerValueDescriptor
,ILargeStringValueDescriptor
,IListValueDescriptor<V>
,IMapValueDescriptor<V>
,INullValueDescriptor
,IRecordValueDescriptor
,IStringValueDescriptor
,ITupleValueDescriptor
,IUnionValueDescriptor<D>
,IVoidValueDescriptor
public interface IValueDescriptor<V,TBuilder extends IValueBuilder<V>> extends Serializable
Base class for all value descriptors that describe the shape of (mostly JSON-like) data. A value descriptor indicates the type a value must have and may impose additional restrictions on the allowed values.IValueBuilderFactory f = ValueBuilderFactory.getInstance(); IListValueDescriptor descriptor = f.listBuilder(f.string()).description("i18n.key").build(); // Obtain a list of available properties, to create an overview table etc. List<IProperty> properties = descriptor.getKnownProperties("Root"); // Property[path=Root, type=List, description="i18n.key"] System.out.println(properties.get(0)); // Property[path=Root[i], type=String, description="Root[i]"] System.out.println(properties.get(1)); List<String> list = descriptor.builder().set(0, "foo").set(1, "bar").build(); // ["foo", "bar"] System.out.println(list);
- Since:
- 7.0.0
- Author:
- XIMA MEDIA GmbH
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
acceptsValue(Object value)
default IBooleanValueDescriptor
asBoolean()
Casts this descriptor to a boolean value descriptor type.default <T> IConstValueDescriptor<T>
asConst()
Casts this descriptor to a constant value descriptor type.default IFloatValueDescriptor
asFloat()
Casts this descriptor to a float value descriptor type.default IIntegerValueDescriptor
asInteger()
Casts this descriptor to an integer value descriptor type.default <T> IListValueDescriptor<T>
asList()
Casts this descriptor to a list value descriptor type.default <T> IMapValueDescriptor<T>
asMap()
Casts this descriptor to a map value descriptor type.default INullValueDescriptor
asNull()
Casts this descriptor to a null value descriptor type.default IRecordValueDescriptor
asRecord()
Casts this descriptor to a record value descriptor type.default IStringValueDescriptor
asString()
Casts this descriptor to a string value descriptor type.default ITupleValueDescriptor
asTuple()
Casts this descriptor to a tuple value descriptor type.default <E> IUnionValueDescriptor<E>
asUnion()
Casts this descriptor to a union value descriptor type.default IVoidValueDescriptor
asVoid()
Casts this descriptor to a void value descriptor type.TBuilder
builder()
Creates a new value builder for creating a value that conforms to the restrictions imposed by this value descriptor.EValueType
getBaseType()
V
getDefaultValue()
String
getDescription()
String
getFullType()
Class<?>
getJavaClass()
List<IProperty>
getKnownProperties(String basePath)
default boolean
is(Class<? extends IValueDescriptor> clazz)
default <TItem,TDesc extends IValueDescriptor<TItem,? extends IValueBuilder<TItem>>>
TDescunwrap(Class<? extends TDesc> clazz)
Casts this descriptor to the given type.
-
-
-
Method Detail
-
acceptsValue
boolean acceptsValue(Object value)
- Parameters:
value
- A value to check.- Returns:
true
when the given value conforms to the restrictions imposed by this value descriptor,false
otherwise.
-
asBoolean
default IBooleanValueDescriptor asBoolean()
Casts this descriptor to a boolean value descriptor type.- Returns:
- This value descriptor cast to a boolean value descriptor.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the desired type.
-
asConst
default <T> IConstValueDescriptor<T> asConst()
Casts this descriptor to a constant value descriptor type.- Type Parameters:
T
- Type of the constant.- Returns:
- This value descriptor cast to a constant value descriptor.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the desired type.
-
asFloat
default IFloatValueDescriptor asFloat()
Casts this descriptor to a float value descriptor type.- Returns:
- This value descriptor cast to a float value descriptor.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the desired type.
-
asInteger
default IIntegerValueDescriptor asInteger()
Casts this descriptor to an integer value descriptor type.- Returns:
- This value descriptor cast to an integer value descriptor.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the desired type.
-
asList
default <T> IListValueDescriptor<T> asList()
Casts this descriptor to a list value descriptor type.- Type Parameters:
T
- Type of the elements contained in the list.- Returns:
- This value descriptor cast to a list value descriptor.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the desired type.
-
asMap
default <T> IMapValueDescriptor<T> asMap()
Casts this descriptor to a map value descriptor type.- Type Parameters:
T
- Type of the values contained in the map.- Returns:
- This value descriptor cast to a map value descriptor.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the desired type.
-
asNull
default INullValueDescriptor asNull()
Casts this descriptor to a null value descriptor type.- Returns:
- This value descriptor cast to a null value descriptor.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the desired type.
-
asRecord
default IRecordValueDescriptor asRecord()
Casts this descriptor to a record value descriptor type.- Returns:
- This value descriptor cast to a record value descriptor.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the desired type.
-
asString
default IStringValueDescriptor asString()
Casts this descriptor to a string value descriptor type.- Returns:
- This value descriptor cast to a string value descriptor.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the desired type.
-
asTuple
default ITupleValueDescriptor asTuple()
Casts this descriptor to a tuple value descriptor type.- Returns:
- This value descriptor cast to a tuple value descriptor.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the desired type.
-
asUnion
default <E> IUnionValueDescriptor<E> asUnion()
Casts this descriptor to a union value descriptor type.- Type Parameters:
E
- Type of the union discriminator.- Returns:
- This value descriptor cast to a union value descriptor.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the desired type.
-
asVoid
default IVoidValueDescriptor asVoid()
Casts this descriptor to a void value descriptor type.- Returns:
- This value descriptor cast to a void value descriptor.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the desired type.
-
builder
TBuilder builder()
Creates a new value builder for creating a value that conforms to the restrictions imposed by this value descriptor.- Returns:
- A new value builder for values as indicated by this value descriptor.
-
getBaseType
EValueType getBaseType()
- Returns:
- The basic type of value described by this value descriptor.
-
getDefaultValue
V getDefaultValue()
- Returns:
- The default value used if no explicit is provided when a value for this descriptor is created.
-
getDescription
String getDescription()
- Returns:
- Description for this value. This is passed through as set when the descriptor was created. May be either a localized message or an I18N key.
-
getFullType
String getFullType()
- Returns:
- The full value type of this value descriptors, including the type of list elements or map values.
-
getJavaClass
Class<?> getJavaClass()
- Returns:
- The Java class of the values described by this descriptor.
-
getKnownProperties
List<IProperty> getKnownProperties(String basePath)
- Parameters:
basePath
- Prefix added to the property paths.- Returns:
- A list of all properties known to exist when a value of this type is created. For example, if a record has required properties, these properties are included in the returned list.
-
is
default boolean is(Class<? extends IValueDescriptor> clazz)
- Parameters:
clazz
- Class to check.- Returns:
- Whether this descriptor can be cast to the given class.
- See Also:
unwrap(Class)
-
unwrap
default <TItem,TDesc extends IValueDescriptor<TItem,? extends IValueBuilder<TItem>>> TDesc unwrap(Class<? extends TDesc> clazz)
Casts this descriptor to the given type. Make sure you are certain it is of the given type.- Type Parameters:
TItem
- Type of the values described by the descriptor.TDesc
- Type of the descriptor.- Parameters:
clazz
- Class to which to cast this descriptor.- Returns:
- This value descriptor cast to the given type.
- Throws:
ClassCastException
- When this descriptor cannot be cast to the given type.- See Also:
is(Class)
-
-