int value = ContentType.convert(ContentType.Text, "10", ContentType.IntegerType);
public class ContentType<T> extends Object
Encapsulates a content type. This class is the basis of all data conversions in CodeRAD. All properties have an assigned
ContentType
. When a property is bound to a view, the view will use the content type to convert the property’s
value into a form that it can handle.
BooleanType
- A Boolean
value.
IntegerType
- An Integer
value.
DoubleType
- A Double
value.
EntityType
- An Entity
value.
EntityListType
- An EntityList
value.
Use convert(com.codename1.rad.models.ContentType, java.lang.Object, com.codename1.rad.models.ContentType)
to convert data from one type to another. For example, to convert a String to an Integer, you could do:
int value = ContentType.convert(ContentType.Text, "10", ContentType.IntegerType);
Property
, EntityType
, and Entity
all include convenience methods for retrieving property values in the basic content types.
E.g. Entity.getText(com.codename1.rad.models.Property)
, which will return the property value as a String
no matter what content type the property actually stores.
If you have a property that has a custom content type, you can implement it by extending ContentType
and providing implementations for to(com.codename1.rad.models.ContentType, java.lang.Object)
and
canConvertTo(com.codename1.rad.models.ContentType)
; or from(com.codename1.rad.models.ContentType, java.lang.Object)
and canConvertFrom(com.codename1.rad.models.ContentType)
; or all of these methods.
Modifier and Type | Field and Description |
---|---|
static ContentType<Boolean> |
BooleanType |
static ContentType<Date> |
DateType |
static ContentType<Double> |
DoubleType |
static ContentType<EntityList> |
EntityListType |
static ContentType<Entity> |
EntityType |
static ContentType<Float> |
FloatType |
static ContentType<Integer> |
IntegerType |
static ContentType<Long> |
LongType |
static ContentType<String> |
Text |
Constructor and Description |
---|
ContentType(Property.Name name,
Class<T> representationClass) |
Modifier and Type | Method and Description |
---|---|
boolean |
canConvertFrom(ContentType otherType) |
boolean |
canConvertTo(ContentType otherType) |
static <T,V> T |
convert(ContentType<V> sourceType,
V sourceData,
ContentType<T> targetType) |
static <V> ContentType<V> |
createObjectType(Class<V> representationClass) |
boolean |
equals(Object obj) |
<V> T |
from(ContentType<V> otherType,
V data) |
Property.Name |
getName() |
Class<T> |
getRepresentationClass() |
int |
hashCode() |
boolean |
isEntity() |
boolean |
isEntityList() |
<V> V |
to(ContentType<V> otherType,
T data) |
String |
toString() |
public static final ContentType<String> Text
public static final ContentType<Boolean> BooleanType
public static final ContentType<Integer> IntegerType
public static final ContentType<Long> LongType
public static final ContentType<Float> FloatType
public static final ContentType<Double> DoubleType
public static final ContentType<Entity> EntityType
public static final ContentType<EntityList> EntityListType
public static final ContentType<Date> DateType
public ContentType(Property.Name name, Class<T> representationClass)
public boolean isEntity()
public boolean isEntityList()
public Property.Name getName()
public <V> V to(ContentType<V> otherType, T data)
public boolean canConvertTo(ContentType otherType)
public <V> T from(ContentType<V> otherType, V data)
public boolean canConvertFrom(ContentType otherType)
public static <T,V> T convert(ContentType<V> sourceType, V sourceData, ContentType<T> targetType)
public static <V> ContentType<V> createObjectType(Class<V> representationClass)
Copyright © 2021. All Rights Reserved.