public class PropertyIndex

  1. Object
  2. PropertyIndex

ImplementsIterable<PropertyBase>

Maps the properties that are in a class/object and provides access to them so tools such as ORM can implicitly access them for us. This class also holds the class level meta-data for a specific property or class. It also provides utility level tools e.g. toString implementation etc.

Constructors

public PropertyIndex(PropertyBusinessObject parent, String name, PropertyBase... properties)The constructor is essential for a proper property business object

Methods

public static void storeJSONList(String name, List<? extends PropertyBusinessObject> objs)Writes the JSON string to storage, it’s a shortcut for writing/generating the JSON
public static String toJSONList(List<? extends PropertyBusinessObject> objs)Creates a JSON string, containing the list of property business objects
public String getName()The name of the parent business object
public PropertyBase get(String name)Returns a property by its name
public PropertyBase getIgnoreCase(String name)Returns a property by its name regardless of case sensitivity for the name
public PropertyBase get(int i)Allows us to get an individual property within the object instance
public int getSize()The number of properties in the class
public Iterator<PropertyBase> iterator()Allows us to traverse the properties with a for-each statement
public Object getMetaDataOfClass(String meta)Allows us to fetch class meta data not to be confused with standard properties
public void putMetaDataOfClass(String meta, Object o)Sets class specific metadata
public String toString()Returns a user readable printout of the property values which is useful for debugging
public String toString(boolean includeNewline)Returns a user readable printout of the property values which is useful for debugging
public void populateFromMap(Map<String, Object> m)This is useful for JSON parsing, it allows converting JSON map data to objects
public boolean setSimpleObject(PropertyBase p, Object val)Sets one of the builtin simple objects into a property
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
public Map<String, Object> toMapRepresentation()This is useful in converting a property object to JSON
public String toJSON()Converts the object to a JSON representation
public Element asElement()Returns an element object mapping to the current object hierarchy similar to the map object
public String toXML()Converts the object to an XML representation
public void setXmlTextElement(PropertyBase p, boolean t)Toggles whether a given property should act as a text element for this object
public boolean isXmlTextElement(PropertyBase p)Toggles whether a given property should act as a text element for this object
public PropertyBase getXmlTextElement()Returns the property that contains the XML text e.g. property value
public void fromXml(Element e)Converts the XML element to this object hierarchy
public void init(Object... values)This method works similarly to a constructor, it accepts the values for the properties in the order they appear within the index
public void storeJSON(String name)Writes the JSON string to storage, it’s a shortcut for writing/generating the JSON
public <X extends PropertyBusinessObject> List<X> loadJSONList(String name)Loads JSON containing a list of property objects of this type
public <X extends PropertyBusinessObject> List<X> loadJSONList(InputStream stream) throws IOExceptionLoads JSON containing a list of property objects of this type
public PropertyBusinessObject newInstance()Creates a new instance of the parent class
public void fromJSON(String jsonString)Populates the object from a JSON string
public void loadJSON(String name)Loads JSON for the object from storage with the given name if it exists.
public void loadJSON(InputStream stream) throws IOExceptionLoads JSON for the object from the given input stream
public boolean equals(Object o)Returns true if the given object equals the property index
public int hashCode()The hashcode of the object
public void setExcludeFromJSON(PropertyBase pb, boolean exclude)Allows us to exclude a specific property from the toJSON process
public boolean isExcludeFromMap(PropertyBase pb)Indicates whether the given property is excluded from the #toMapRepresentation() method output
public void setExcludeFromMap(PropertyBase pb, boolean exclude)Allows us to exclude a specific property from the #toMapRepresentation() process
public boolean isExcludeFromJSON(PropertyBase pb)Indicates whether the given property is excluded from the #toJSON() method output
public void registerExternalizable()Invoking this method will allow a property object to be serialized seamlessly
public Externalizable 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

Inherited methods

Constructor details

PropertyIndex

public PropertyIndex(PropertyBusinessObject parent, String name, PropertyBase... properties)
The constructor is essential for a proper property business object

Parameters

parent PropertyBusinessObject
the parent object instance
name String
the name of the parent class
properties PropertyBase...
the list of properties in the object

Method details

storeJSONList

public static void storeJSONList(String name, List<? extends PropertyBusinessObject> objs)
Writes the JSON string to storage, it’s a shortcut for writing/generating the JSON

Parameters

name String
the name of the storage file
objs List<? extends PropertyBusinessObject>
a list of business objects

toJSONList

public static String toJSONList(List<? extends PropertyBusinessObject> objs)
Creates a JSON string, containing the list of property business objects

Parameters

objs List<? extends PropertyBusinessObject>
a list of business objects

Returns

the JSON string

getName

public String getName()
The name of the parent business object

Returns

a unique name for the parent

get

public PropertyBase get(String name)
Returns a property by its name

Parameters

name String
the name of the property (case sensitive)

Returns

the property or null

getIgnoreCase

public PropertyBase getIgnoreCase(String name)
Returns a property by its name regardless of case sensitivity for the name

Parameters

name String
the name of the property (case insensitive)

Returns

the property or null

get

public PropertyBase get(int i)
Allows us to get an individual property within the object instance

Parameters

i int
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

public Iterator<PropertyBase> iterator()
Allows us to traverse the properties with a for-each statement

Returns

an iterator instance

getMetaDataOfClass

public Object getMetaDataOfClass(String meta)
Allows us to fetch class meta data not to be confused with standard properties

Parameters

meta String
the meta data unique name

Returns

the object instance

putMetaDataOfClass

public void putMetaDataOfClass(String meta, Object o)
Sets class specific metadata

Parameters

meta String
the name of the meta data
o Object
object value for the meta data

toString

public String toString()
Returns a user readable printout of the property values which is useful for debugging

Returns

user readable printout of the property values which is useful for debugging

toString

public String toString(boolean includeNewline)
Returns a user readable printout of the property values which is useful for debugging

Parameters

includeNewline boolean
true to indicate that newline characters should be included

Returns

user readable printout of the property values which is useful for debugging

populateFromMap

public void populateFromMap(Map<String, Object> m)
This is useful for JSON parsing, it allows converting JSON map data to objects

Parameters

m Map<String, Object>
the map

setSimpleObject

public boolean setSimpleObject(PropertyBase p, Object val)
Sets one of the builtin simple objects into a property

Parameters

p PropertyBase
the property base
val Object
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 Map<String, Object>
the map
recursiveType Class<? extends PropertyBusinessObject>
when running into map types we create this object type

toMapRepresentation

public Map<String, Object> toMapRepresentation()
This is useful in converting a property object to JSON

Returns

a map representation of the properties

toJSON

public String toJSON()
Converts the object to a JSON representation

Returns

a JSON String

asElement

public Element asElement()
Returns an element object mapping to the current object hierarchy similar to the map object

Returns

an XML parser element

toXML

public String toXML()
Converts the object to an XML representation

Returns

an XML String

setXmlTextElement

public void setXmlTextElement(PropertyBase p, boolean t)
Toggles whether a given property should act as a text element for this object

Parameters

p PropertyBase
the property that should act as a text element
t boolean
true to activate the text element false to remove it

isXmlTextElement

public boolean isXmlTextElement(PropertyBase p)
Toggles whether a given property should act as a text element for this object

Parameters

p PropertyBase
the property

Returns

true if this is a text element

getXmlTextElement

public PropertyBase getXmlTextElement()
Returns the property that contains the XML text e.g. property value

Returns

the property representing text XML or null if no such property was set

fromXml

public void fromXml(Element e)
Converts the XML element to this object hierarchy

Parameters

e Element
the element

init

public void init(Object... values)
This method works similarly to a constructor, it accepts the values for the properties in the order they appear within the index

Parameters

values Object...
values of properties in the order they appear in the index

storeJSON

public void storeJSON(String name)
Writes the JSON string to storage, it’s a shortcut for writing/generating the JSON

Parameters

name String
the name of the storage file

loadJSONList

public <X extends PropertyBusinessObject> List<X> loadJSONList(String name)
Loads JSON containing a list of property objects of this type

Parameters

name String
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 InputStream
the input stream

Returns

list of property objects matching this type

newInstance

public PropertyBusinessObject newInstance()
Creates a new instance of the parent class

Returns

an instance of the parent class or null if this failed

fromJSON

public void fromJSON(String jsonString)
Populates the object from a JSON string

Parameters

jsonString String
the JSON String

loadJSON

public void loadJSON(String name)
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 String
the name of the storage

loadJSON

public void loadJSON(InputStream stream) throws IOException
Loads JSON for the object from the given input stream

Parameters

stream InputStream
the input stream containing the JSON file

equals

public boolean equals(Object o)
Returns true if the given object equals the property index

Parameters

o Object
the object

Returns

true if equals

hashCode

public int hashCode()
The hashcode of the object

Returns

a composite of the hashcodes of the properties

setExcludeFromJSON

public void setExcludeFromJSON(PropertyBase pb, boolean exclude)
Allows us to exclude a specific property from the toJSON process

Parameters

pb PropertyBase
the property
exclude boolean
true to exclude and false to reinclude

isExcludeFromMap

public boolean isExcludeFromMap(PropertyBase pb)
Indicates whether the given property is excluded from the #toMapRepresentation() method output

Parameters

pb PropertyBase
the property

Returns

true if the property is excluded and false otherwise

setExcludeFromMap

public void setExcludeFromMap(PropertyBase pb, boolean exclude)
Allows us to exclude a specific property from the #toMapRepresentation() process

Parameters

pb PropertyBase
the property
exclude boolean
true to exclude and false to reinclude

isExcludeFromJSON

public boolean isExcludeFromJSON(PropertyBase pb)
Indicates whether the given property is excluded from the #toJSON() method output

Parameters

pb PropertyBase
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

public Externalizable 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