Class PropertyIndex
- All Implemented Interfaces:
Iterable<PropertyBase>
-
Constructor Summary
ConstructorsConstructorDescriptionPropertyIndex(PropertyBusinessObject parent, String name, PropertyBase... properties) The constructor is essential for a proper property business object -
Method Summary
Modifier and TypeMethodDescriptionReturns an element object mapping to the current object hierarchy similar to the map objectReturns an externalizable object for serialization of this business object, unlike regular externalizables this implementation is robust to changes, additions and removals of propertiesbooleanReturns true if the given object equals the property indexvoidPopulates the object from a JSON stringvoidConverts the XML element to this object hierarchyget(int i) Allows us to get an individual property within the object instanceReturns a property by its namegetIgnoreCase(String name) Returns a property by its name regardless of case sensitivity for the namegetMetaDataOfClass(String meta) Allows us to fetch class meta data not to be confused with standard propertiesgetName()The name of the parent business objectintgetSize()The number of properties in the classReturns the property that contains the XML text e.g.inthashCode()The hashcode of the objectvoidThis method works similarly to a constructor, it accepts the values for the properties in the order they appear within the indexbooleanIndicates whether the given property is excluded from the#toJSON()method outputbooleanIndicates whether the given property is excluded from the#toMapRepresentation()method outputbooleanToggles whether a given property should act as a text element for this objectiterator()Allows us to traverse the properties with a for-each statementvoidloadJSON(InputStream stream) Loads JSON for the object from the given input streamvoidLoads JSON for the object from storage with the given name if it exists.<X extends PropertyBusinessObject>
List<X> loadJSONList(InputStream stream) Loads JSON containing a list of property objects of this type<X extends PropertyBusinessObject>
List<X> loadJSONList(String name) Loads JSON containing a list of property objects of this typeCreates a new instance of the parent classvoidThis is useful for JSON parsing, it allows converting JSON map data to objectsvoidpopulateFromMap(Map<String, Object> m, Class<? extends PropertyBusinessObject> recursiveType) This is useful for JSON parsing, it allows converting JSON map data to objectsvoidputMetaDataOfClass(String meta, Object o) Sets class specific metadatavoidInvoking this method will allow a property object to be serialized seamlesslyvoidsetExcludeFromJSON(PropertyBase pb, boolean exclude) Allows us to exclude a specific property from the toJSON processvoidsetExcludeFromMap(PropertyBase pb, boolean exclude) Allows us to exclude a specific property from the#toMapRepresentation()processbooleansetSimpleObject(PropertyBase p, Object val) Sets one of the builtin simple objects into a propertyvoidsetXmlTextElement(PropertyBase p, boolean t) Toggles whether a given property should act as a text element for this objectvoidWrites the JSON string to storage, it's a shortcut for writing/generating the JSONstatic voidstoreJSONList(String name, List<? extends PropertyBusinessObject> objs) Writes the JSON string to storage, it's a shortcut for writing/generating the JSONtoJSON()Converts the object to a JSON representationstatic StringtoJSONList(List<? extends PropertyBusinessObject> objs) Creates a JSON string, containing the list of property business objectsThis is useful in converting a property object to JSONtoString()Returns a user readable printout of the property values which is useful for debuggingtoString(boolean includeNewline) Returns a user readable printout of the property values which is useful for debuggingtoXML()Converts the object to an XML representationMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
PropertyIndex
The constructor is essential for a proper property business object
Parameters
-
parent: the parent object instance -
name: the name of the parent class -
properties: the list of properties in the object
-
-
-
Method Details
-
storeJSONList
Writes the JSON string to storage, it's a shortcut for writing/generating the JSON
Parameters
-
name: the name of the storage file -
objs: a list of business objects
-
-
toJSONList
Creates a JSON string, containing the list of property business objects
Parameters
objs: a list of business objects
Returns
the JSON string
-
getName
The name of the parent business object
Returns
a unique name for the parent
-
get
Returns a property by its name
Parameters
name: the name of the property (case sensitive)
Returns
the property or null
-
getIgnoreCase
Returns a property by its name regardless of case sensitivity for the name
Parameters
name: the name of the property (case insensitive)
Returns
the property or null
-
get
Allows us to get an individual property within the object instance
Parameters
i: the index of the property
Returns
the property instance
-
getSize
public int getSize()The number of properties in the class
Returns
number of properties in the class
-
iterator
Allows us to traverse the properties with a for-each statement
Returns
an iterator instance
- Specified by:
iteratorin interfaceIterable<PropertyBase>
-
getMetaDataOfClass
-
putMetaDataOfClass
-
toString
-
toString
Returns a user readable printout of the property values which is useful for debugging
Parameters
includeNewline: true to indicate that newline characters should be included
Returns
user readable printout of the property values which is useful for debugging
-
populateFromMap
-
setSimpleObject
Sets one of the builtin simple objects into a property
Parameters
-
p: the property base -
val: the object value
Returns
true if successful
-
-
populateFromMap
public void populateFromMap(Map<String, Object> m, Class<? extends PropertyBusinessObject> recursiveType) This is useful for JSON parsing, it allows converting JSON map data to objects
Parameters
-
m: the map -
recursiveType: when running into map types we create this object type
-
-
toMapRepresentation
-
toJSON
Converts the object to a JSON representation
Returns
a JSON String
-
asElement
Returns an element object mapping to the current object hierarchy similar to the map object
Returns
an XML parser element
-
toXML
Converts the object to an XML representation
Returns
an XML String
-
setXmlTextElement
Toggles whether a given property should act as a text element for this object
Parameters
-
p: the property that should act as a text element -
t: true to activate the text element false to remove it
-
-
isXmlTextElement
Toggles whether a given property should act as a text element for this object
Parameters
p: the property
Returns
true if this is a text element
-
getXmlTextElement
Returns the property that contains the XML text e.g.
property valueReturns
the property representing text XML or null if no such property was set
-
fromXml
Converts the XML element to this object hierarchy
Parameters
e: the element
-
init
This method works similarly to a constructor, it accepts the values for the properties in the order they appear within the index
Parameters
values: values of properties in the order they appear in the index
-
storeJSON
Writes the JSON string to storage, it's a shortcut for writing/generating the JSON
Parameters
name: the name of the storage file
-
loadJSONList
Loads JSON containing a list of property objects of this type
Parameters
name: the name of the storage
Returns
list of property objects matching this type
-
loadJSONList
public <X extends PropertyBusinessObject> List<X> loadJSONList(InputStream stream) throws IOException Loads JSON containing a list of property objects of this type
Parameters
stream: the input stream
Returns
list of property objects matching this type
- Throws:
IOException
-
newInstance
Creates a new instance of the parent class
Returns
an instance of the parent class or null if this failed
-
fromJSON
Populates the object from a JSON string
Parameters
jsonString: the JSON String
-
loadJSON
Loads JSON for the object from storage with the given name if it exists. If the storage file doesn't exist getResources() will be used to find a default JSON file in the root of the package
Parameters
name: the name of the storage
-
loadJSON
Loads JSON for the object from the given input stream
Parameters
stream: the input stream containing the JSON file
- Throws:
IOException
-
equals
-
hashCode
-
setExcludeFromJSON
Allows us to exclude a specific property from the toJSON process
Parameters
-
pb: the property -
exclude: true to exclude and false to reinclude
-
-
isExcludeFromMap
Indicates whether the given property is excluded from the
#toMapRepresentation()method outputParameters
pb: the property
Returns
true if the property is excluded and false otherwise
-
setExcludeFromMap
Allows us to exclude a specific property from the
#toMapRepresentation()processParameters
-
pb: the property -
exclude: true to exclude and false to reinclude
-
-
isExcludeFromJSON
Indicates whether the given property is excluded from the
#toJSON()method outputParameters
pb: the property
Returns
true if the property is excluded and false otherwise
-
registerExternalizable
public void registerExternalizable()Invoking this method will allow a property object to be serialized seamlessly -
asExternalizable
Returns an externalizable object for serialization of this business object, unlike regular externalizables this implementation is robust to changes, additions and removals of properties
Returns
an externalizable instance
-