# Class PropertyIndex

java.lang.Object
com.codename1.properties.PropertyIndex

All Implemented Interfaces:
  `Iterable<PropertyBase>`

public class PropertyIndex extends Object implements Iterable<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.

- ## Constructor Summary

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

- ## Method Summary

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

  ### Methods inherited from class Object

  `clone, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### PropertyIndex

    public PropertyIndex(PropertyBusinessObject parent, String name, PropertyBase... properties)

    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

    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`: the name of the storage file

    - `objs`: 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`: 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`: 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`: 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`: 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

    Specified by:
      `iterator` in interface `Iterable<PropertyBase>`
    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`: the meta data unique name

    ###### Returns

    the object instance

  - ### putMetaDataOfClass

    public void putMetaDataOfClass(String meta, Object o)

    Sets class specific metadata

    ###### Parameters

    - `meta`: the name of the meta data

    - `o`: 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

    Overrides:
      `toString` in class `Object`

  - ### toString

    public String toString(boolean includeNewline)

    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

    public void populateFromMap(Map<String,Object> m)

    This is useful for JSON parsing, it allows converting JSON map data to objects

    ###### Parameters

    - `m`: the map

  - ### setSimpleObject

    public boolean setSimpleObject(PropertyBase p, Object val)

    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

    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`: the property that should act as a text element

    - `t`: 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`: 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`: 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`: 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`: 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`: 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

    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`: 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`: 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`: the input stream containing the JSON file
    Throws:
      `IOException`

  - ### equals

    public boolean equals(Object o)

    Returns true if the given object equals the property index

    ###### Parameters

    - `o`: the object

    ###### Returns

    true if equals

    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()

    The hashcode of the object

    ###### Returns

    a composite of the hashcodes of the properties

    Overrides:
      `hashCode` in class `Object`

  - ### setExcludeFromJSON

    public void setExcludeFromJSON(PropertyBase pb, boolean exclude)

    Allows us to exclude a specific property from the toJSON process

    ###### Parameters

    - `pb`: the property

    - `exclude`: 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`: 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`: the property

    - `exclude`: 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`: 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