Klasse DataElementList

java.lang.Object
de.esoco.lib.property.AbstractStringProperties
de.esoco.lib.property.StringProperties
Alle implementierten Schnittstellen:
de.esoco.lib.model.DataModel<DataElement<?>>, de.esoco.lib.property.HasProperties, de.esoco.lib.property.MutableProperties, Serializable, Iterable<DataElement<?>>
Bekannte direkte Unterklassen:
EntityDataElement

public class DataElementList extends ListDataElement<DataElement<?>>
A data element implementation that contains a hierarchical structure of data elements.
Siehe auch:
  • Konstruktordetails

    • DataElementList

      public DataElementList(String name, Collection<? extends DataElement<?>> elements)
      Creates a new instance that is initialized from a certain set of data elements. The contents of the collection argument will be copied into this list element but not the collection itself.
      Parameter:
      name - The name of this element
      elements - A collection containing the initial elements of this list element (may be NULL)
    • DataElementList

      public DataElementList(String name, String resourceId, DataElement<?>... elements)
      Creates a new instance with certain data elements and without a validator and flags.
      Parameter:
      name - The name of this element
      resourceId - A resource ID or NULL for the default
      elements - The child data elements
    • DataElementList

      public DataElementList(String name, String resourceId, Collection<? extends DataElement<?>> elements, Set<DataElement.Flag> flags)
      Creates a new instance that is initialized from a certain set of data elements. The contents of the collection argument will be copied into this list element but not the collection itself.
      Parameter:
      name - The name of this element
      resourceId - A resource ID or NULL for the default
      elements - A collection containing the initial elements of this list element (may be NULL)
      flags - The optional flags for this data element
    • DataElementList

      protected DataElementList()
      Default constructor for serialization.
  • Methodendetails

    • findDataElement

      public static DataElement<?> findDataElement(String name, Collection<DataElement<?>> elements)
      Searches for a data element with a certain name in a collection of data elements. If the collection contains data element lists these will be searched recursively.
      Parameter:
      name - The name of the data element
      elements - The elements to search
      Gibt zurück:
      The matching data element or NULL if no such element exists
    • init

      public static void init()
      This method should be invoked to initialize the property name constants for de-serialization.
    • add

      public void add(String name, String value)
      Shortcut method to add a new StringDataElement with a certain name and string value. See ListDataElement.addElement(Object) for more information.
      Parameter:
      name - The name of the data element to add
      value - The value of the new data element
    • add

      public void add(String name, Date value)
      Shortcut method to add a new DateDataElement with a certain name and Date value.
      Parameter:
      name - The name of the data element to add
      value - The value of the new data element
    • add

      public void add(String name, int value)
      Shortcut method to add a new IntegerDataElement with a certain name and value.
      Parameter:
      name - The name of the data element to add
      value - The value of the new data element
    • add

      public void add(String name, boolean value)
      Shortcut method to add a new BooleanDataElement with a certain name and value.
      Parameter:
      name - The name of the data element to add
      value - The value of the new data element
    • addElement

      public void addElement(int index, DataElement<?> element)
      Overridden to modify the parent reference of the argument data element.
      Setzt außer Kraft:
      addElement in Klasse ListDataElement<DataElement<?>>
      Parameter:
      index - The position index
      element - The element value to add
      Siehe auch:
    • copy

      public DataElementList copy(DataElement.CopyMode mode, de.esoco.lib.property.PropertyName<?>... copyProperties)
      Returns a copy of this data element that contains all or a subset of it's current state. Always copied are the name and flags. Never copied is the parent reference because upon copying typically a reference to a copied parent needs to be set. The further data the copy contains depends on the copy mode:

      The copy instance is created by invoking DataElement.newInstance() which has the recommendation to overwrite the return type to the concrete subtype to prevent the need for casting by the invoking code. For the same reason it is recommended that subclasses also override this method with the concrete return type and cast the result of super.copy() to that type.

      Setzt außer Kraft:
      copy in Klasse DataElement<List<DataElement<?>>>
      Parameter:
      mode - The copy mode
      copyProperties - An optional list of properties to copy. If not provided all properties will be copied (unless the mode is DataElement.CopyMode.PLACEHOLDER)
      Gibt zurück:
      The copied instance
    • findChild

      public DataElement<?> findChild(String name)
      Searches for a child data element in the full hierarchy of this instance and returns it if found. Invokes findDataElement(String, Collection) to perform the search.
      Parameter:
      name - The name of the data element to search
      Gibt zurück:
      The child data element with the given name or NULL for none
    • getBoolean

      public boolean getBoolean(String name)
      Returns the boolean value of a certain data element. The returned value will be the result of invoking Boolean.booleanValue() on the type-casted value of the data element with the given name if such exists. If not, FALSE will be returned. If the data element's value is not of type Boolean an exception will occur.
      Parameter:
      name - The name of the data element to return as a boolean value
      Gibt zurück:
      The boolean value of the data element or FALSE if none could be found
    • getChildList

      public DataElementList getChildList(String elementPath)
      A convenience method that casts the return value of the name-based method getElementAt(String) to a data element list. If the type of the named element is not DataElementList or if no such element exists NULL will be returned.
      Parameter:
      elementPath - The path of the element list to return
      Gibt zurück:
      The element list at the given path or NULL if no list with the given name exists
    • getDataElements

      public List<DataElement<?>> getDataElements()
      Returns the list of data elements in this instance. The list must not be modified by the invoking code.
      Gibt zurück:
      The list of data elements
    • getDate

      public Date getDate(String name)
      Returns the date value of a certain data element. The returned value will be the type-casted value of the data element with the given name if such exists. If not, NULL will be returned. If the data element's value is not of type Date an exception will occur.
      Parameter:
      name - The name of the data element to return as a date value
      Gibt zurück:
      The date value of the data element or NULL if none could be found
    • getElement

      public DataElement<?> getElement(String elementName)
      Returns the first element with a certain name from this list.
      Parameter:
      elementName - The name of the element to return
      Gibt zurück:
      The element or NULL if no element with the given name exists
    • getElementAt

      public DataElement<?> getElementAt(String elementPath)
      Returns a particular data element from the hierarchy of this list. The element path argument can either be a simple element name of a path to an element in the hierarchy of this list's sub-lists. The path separator is a forward slash as defined by DataElement.PATH_SEPARATOR_CHAR.

      If the path start with a separator it is considered to be absolute with the name of this list as the first path element. Without a leading separator it must be relative to this instance, i.e. the first element in the path must be the name of a child data element of this instance. The path must never end with a separator. Examples:

      • 'Test': returns the element 'Test' from this list
      • '/Data/Preferences/Setting1': returns the element 'Setting1' from the sub-list 'Preferences' of this element which is called 'Data'
      • 'Preferences/Setting1': returns the element 'Setting1' from the sub-list 'Preferences'
      • 'Preferences': returns the sub-list named 'Preferences'
      Parameter:
      elementPath - The path of the element to return
      Gibt zurück:
      The element with the given path or NULL if no such element exists
    • getElementHierarchy

      public String getElementHierarchy(String indent)
      Returns a formatted multi-line string that describes the data element hierarchy of this instance.
      Parameter:
      indent - The initial indent of the hierarchy (empty for none)
      Gibt zurück:
      The data element hierarchy string
    • getInt

      public int getInt(String name)
      Returns the integer value of a certain data element. The returned value will be the result of invoking Number.intValue() on the type-casted value of the data element with the given name if such exists. If not, 0 (zero) will be returned. If the data element's value is not of type Number an exception will occur.
      Parameter:
      name - The name of the data element to return as an integer value
      Gibt zurück:
      The integer value of the data element or 0 if none could be found
    • getString

      public String getString(String name)
      Returns the string value of a certain data element. The returned value will be the result of invoking Object.toString() on the value of the data element with the given name if such exists. If not, NULL will be returned.
      Parameter:
      name - The name of the data element to return the string value of
      Gibt zurück:
      The string value of the data element or NULL if none could be found
    • markAsChanged

      public void markAsChanged()
      Overridden to also mark the child hierarchy as modified.
      Setzt außer Kraft:
      markAsChanged in Klasse DataElement<List<DataElement<?>>>
    • removeElement

      public void removeElement(DataElement<?> element)
      Overridden to modify the parent reference of the argument data element.
      Setzt außer Kraft:
      removeElement in Klasse ListDataElement<DataElement<?>>
      Parameter:
      element - The element to remove
      Siehe auch:
    • replaceElement

      public boolean replaceElement(DataElement<?> newElement)
      Replaces the first data element in this list with a new element with the same name.
      Parameter:
      newElement - The element to replace another with the same name
      Gibt zurück:
      TRUE if an element has been replaced
    • set

      public void set(String name, String value)
      Shortcut method to set a StringDataElement with a certain name and string value. See setElement(DataElement) for more information.
      Parameter:
      name - The name of the data element to add
      value - The value of the new data element
    • setElement

      public void setElement(DataElement<?> element)
      Sets an element in this instance. If an element with the given name already exists it will be replaced. Otherwise a new element will be added to the end of the list.
      Parameter:
      element - The element to set
    • toDebugString

      public String toDebugString(String indent, boolean includeProperties)
      Creates a string that describes this element for debugging purposes.
      Setzt außer Kraft:
      toDebugString in Klasse DataElement<List<DataElement<?>>>
      Parameter:
      indent - The indentation of the returned string
      includeProperties - TRUE to include the properties, FALSE to omit
      Gibt zurück:
      The debug description
    • toHierarchyString

      public String toHierarchyString()
      Returns the full hierarchy of this data element list as a string.
      Gibt zurück:
      The hierarchy string
    • copyValue

      protected void copyValue(DataElement<List<DataElement<?>>> copy)
      Overridden to to nothing as the copying of the child data elements is handled in copy(CopyMode, PropertyName...).
      Setzt außer Kraft:
      copyValue in Klasse ListDataElement<DataElement<?>>
      Parameter:
      copy - The copied data element to copy the value into
      Siehe auch:
    • getChildResourceIdPrefix

      protected String getChildResourceIdPrefix()
      Can be overridden by subclasses to return a resource id prefix for child elements. This default implementation returns an empty string.
      Gibt zurück:
      The child resource id prefix
    • getList

      protected List<DataElement<?>> getList()
      Beschreibung aus Klasse kopiert: ListDataElement
      Returns the list of values of this data element. Must be implemented by subclasses to return the type-specific value list.
      Angegeben von:
      getList in Klasse ListDataElement<DataElement<?>>
      Gibt zurück:
      The list of values for this instance (must not be NULL)
      Siehe auch:
    • newInstance

      protected DataElementList newInstance()
      Returns a new instance of the respective data element sub-type on which it is invoked. This is needed for GWT which doesn't support reflection. Used by DataElement.copy(CopyMode, PropertyName...) for cloning an instance. Implementations should overwrite the return type with their concrete type to prevent the need for casting by the invoking code.
      Angegeben von:
      newInstance in Klasse DataElement<List<DataElement<?>>>
      Gibt zurück:
      The new instance
    • updateValue

      protected void updateValue(List<DataElement<?>> newElements)
      Updates the element value. Will be invoked by DataElement.setValue(Object) to store a new value after validation. If a subclass wants to reject certain values it should do so in the DataElement.isValidValue(Validator, Object) method. Subclasses that are always immutable should implement an assertion because if the element has been initialized correctly (validator = NULL) this method should then be reached.
      Angegeben von:
      updateValue in Klasse DataElement<List<DataElement<?>>>
      Parameter:
      newElements - The new value for this element