java.io.Serializable, Bean, DynamicBeanpublic final class FlexiBean extends java.lang.Object implements DynamicBean, java.io.Serializable
Bean.
Properties are dynamic, and can be added and removed at will from the map. The internal storage is created lazily to allow a flexi-bean to be used as a lightweight extension to another bean.
Each flexi-bean has a different set of properties. As such, there is one instance of meta-bean for each flexi-bean.
The keys of a flexi-bean must be simple identifiers as per '[a-zA-z_][a-zA-z0-9_]*'.
| Constructor | Description |
|---|---|
FlexiBean() |
Constructor.
|
FlexiBean(FlexiBean copyFrom) |
Constructor that copies all the data entries from the specified bean.
|
| Modifier and Type | Method | Description |
|---|---|---|
FlexiBean |
append(java.lang.String propertyName,
java.lang.Object newValue) |
Sets a property in this bean to the specified value.
|
void |
clear() |
Removes all properties.
|
FlexiBean |
clone() |
Clones this bean, returning an independent copy.
|
boolean |
contains(java.lang.String propertyName) |
Checks if the bean contains a specific property.
|
boolean |
equals(java.lang.Object obj) |
Compares this bean to another based on the property names and content.
|
java.lang.Object |
get(java.lang.String propertyName) |
Gets the value of the property.
|
<T> T |
get(java.lang.String propertyName,
java.lang.Class<T> type) |
Gets the value of the property cast to a specific type.
|
boolean |
getBoolean(java.lang.String propertyName) |
Gets the value of the property as a
boolean. |
double |
getDouble(java.lang.String propertyName) |
Gets the value of the property as a
double. |
double |
getDouble(java.lang.String propertyName,
double defaultValue) |
Gets the value of the property as a
double using a default value. |
int |
getInt(java.lang.String propertyName) |
Gets the value of the property as a
int. |
int |
getInt(java.lang.String propertyName,
int defaultValue) |
Gets the value of the property as a
int using a default value. |
long |
getLong(java.lang.String propertyName) |
Gets the value of the property as a
long. |
long |
getLong(java.lang.String propertyName,
long defaultValue) |
Gets the value of the property as a
long using a default value. |
java.lang.String |
getString(java.lang.String propertyName) |
Gets the value of the property as a
String. |
int |
hashCode() |
Returns a suitable hash code.
|
static DynamicMetaBean |
meta() |
Creates a standalone meta-bean.
|
DynamicMetaBean |
metaBean() |
Gets the meta-bean representing the parts of the bean that are
common across all instances, such as the set of meta-properties.
|
Property<java.lang.Object> |
property(java.lang.String name) |
Gets a property by name.
|
void |
propertyDefine(java.lang.String propertyName,
java.lang.Class<?> propertyType) |
Adds a property to those allowed to be stored in the bean.
|
boolean |
propertyExists(java.lang.String propertyName) |
Checks if the property exists.
|
java.lang.Object |
propertyGet(java.lang.String propertyName) |
Gets the value of the property.
|
java.util.Set<java.lang.String> |
propertyNames() |
Gets the set of property names.
|
void |
propertyRemove(java.lang.String propertyName) |
Removes a property by name.
|
void |
propertySet(java.lang.String propertyName,
java.lang.Object newValue) |
Sets the value of the property.
|
java.lang.Object |
put(java.lang.String propertyName,
java.lang.Object newValue) |
Sets a property in this bean to the specified value.
|
void |
putAll(java.util.Map<java.lang.String,? extends java.lang.Object> map) |
Puts the properties in the specified map into this bean.
|
void |
putAll(FlexiBean other) |
Puts the properties in the specified bean into this bean.
|
void |
remove(java.lang.String propertyName) |
Removes a property.
|
void |
set(java.lang.String propertyName,
java.lang.Object newValue) |
Sets a property in this bean to the specified value.
|
int |
size() |
Gets the number of properties.
|
java.util.Map<java.lang.String,java.lang.Object> |
toMap() |
Returns a map representing the contents of the bean.
|
java.lang.String |
toString() |
Returns a string that summarises the bean.
|
public FlexiBean()
public FlexiBean(FlexiBean copyFrom)
copyFrom - the bean to copy from, not nullpublic static DynamicMetaBean meta()
This creates a new instance each time in line with dynamic bean principles.
public int size()
public boolean contains(java.lang.String propertyName)
propertyName - the property name, null returns falsepublic java.lang.Object get(java.lang.String propertyName)
This returns null if the property does not exist.
propertyName - the property name, not emptypublic <T> T get(java.lang.String propertyName,
java.lang.Class<T> type)
This returns null if the property does not exist.
T - the value typepropertyName - the property name, not emptytype - the type to cast to, not nulljava.lang.ClassCastException - if the type is incorrectpublic java.lang.String getString(java.lang.String propertyName)
String.
This will use Object.toString().
This returns null if the property does not exist.
propertyName - the property name, not emptypublic boolean getBoolean(java.lang.String propertyName)
boolean.propertyName - the property name, not emptyjava.lang.ClassCastException - if the value is not compatiblejava.lang.NullPointerException - if the property does not exist or is nullpublic int getInt(java.lang.String propertyName)
int.propertyName - the property name, not emptyjava.lang.ClassCastException - if the value is not compatiblejava.lang.NullPointerException - if the property does not exist or is nullpublic int getInt(java.lang.String propertyName,
int defaultValue)
int using a default value.propertyName - the property name, not emptydefaultValue - the default value for null or invalid propertyjava.lang.ClassCastException - if the value is not compatiblepublic long getLong(java.lang.String propertyName)
long.propertyName - the property name, not emptyjava.lang.ClassCastException - if the value is not compatiblejava.lang.NullPointerException - if the property does not exist or is nullpublic long getLong(java.lang.String propertyName,
long defaultValue)
long using a default value.propertyName - the property name, not emptydefaultValue - the default value for null or invalid propertyjava.lang.ClassCastException - if the value is not compatiblepublic double getDouble(java.lang.String propertyName)
double.propertyName - the property name, not emptyjava.lang.ClassCastException - if the value is not compatiblejava.lang.NullPointerException - if the property does not exist or is nullpublic double getDouble(java.lang.String propertyName,
double defaultValue)
double using a default value.propertyName - the property name, not emptydefaultValue - the default value for null or invalid propertyjava.lang.ClassCastException - if the value is not compatiblepublic FlexiBean append(java.lang.String propertyName, java.lang.Object newValue)
This creates a property if one does not exist.
propertyName - the property name, not emptynewValue - the new value, may be nullthis for chaining, not nullpublic void set(java.lang.String propertyName,
java.lang.Object newValue)
This creates a property if one does not exist.
propertyName - the property name, not emptynewValue - the new value, may be nullpublic java.lang.Object put(java.lang.String propertyName,
java.lang.Object newValue)
This creates a property if one does not exist.
propertyName - the property name, not emptynewValue - the new value, may be nullpublic void putAll(java.util.Map<java.lang.String,? extends java.lang.Object> map)
This creates properties if they do not exist.
map - the map of properties to add, not nullpublic void putAll(FlexiBean other)
This creates properties if they do not exist.
other - the map of properties to add, not nullpublic void remove(java.lang.String propertyName)
No error occurs if the property does not exist.
propertyName - the property name, not emptypublic void clear()
public boolean propertyExists(java.lang.String propertyName)
propertyName - the property name, not emptypublic java.lang.Object propertyGet(java.lang.String propertyName)
propertyName - the property name, not emptypublic void propertySet(java.lang.String propertyName,
java.lang.Object newValue)
propertyName - the property name, not emptynewValue - the new value of the property, may be nullpublic DynamicMetaBean metaBean()
DynamicBeanmetaBean in interface BeanmetaBean in interface DynamicBeanpublic Property<java.lang.Object> property(java.lang.String name)
DynamicBeanThis will not throw an exception if the property name does not exist. Whether a property is immediately created or not is implementation dependent.
property in interface Beanproperty in interface DynamicBeanname - the property name to retrieve, not nullpublic java.util.Set<java.lang.String> propertyNames()
BeanEach bean consists of a known set of properties. This method returns the known property names.
propertyNames in interface Beanpublic void propertyDefine(java.lang.String propertyName,
java.lang.Class<?> propertyType)
DynamicBeanSome implementations will automatically add properties, in which case this method will have no effect.
propertyDefine in interface DynamicBeanpropertyName - the property name to check, not empty, not nullpropertyType - the property type, not nullpublic void propertyRemove(java.lang.String propertyName)
DynamicBeanpropertyRemove in interface DynamicBeanpropertyName - the property name to remove, null ignoredpublic java.util.Map<java.lang.String,java.lang.Object> toMap()
public FlexiBean clone()
clone in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - the object to compare to, null returns falsepublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
The string contains the class name and properties.
toString in class java.lang.ObjectCopyright © 2007–2018 Joda.org. All rights reserved.