Class SpineObjects


  • public final class SpineObjects
    extends java.lang.Object
    Utility class that bundles methods for generically copying, comparing, and writing to generated SPINE objects.

    Generics should be instantiated to generated SPINE objects only.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T createNewDataWithTaggedElements​(T data, java.lang.Object elements)
      This method copies the given data object but only sets elements (attributes) that are tagged by the given elements.
      static <T> T dataCopy​(T data)
      Create a deep copy of the given data and return it.
      static boolean dataEquals​(java.lang.Object a, java.lang.Object b)
      Checks if data a equals data b.
      static <T> java.util.List<T> deepCopyList​(java.util.List<T> data)  
      static void deleteElements​(java.lang.Object data, java.lang.Object elements)
      Deletes the elements that are defined by the given elements in the given data object.
      static <DATA,​ELEMENTS>
      java.util.List<DATA>
      getDataListForTaggedElements​(ELEMENTS elements, java.util.List<DATA> selectedData)
      This method filters the given data object list so that it returns a list of data objects that only hold attributes tagged by the given elements.
      static <DATA_LIST>
      java.beans.PropertyDescriptor
      getDataListPropertyDescriptorForCmdType​(java.lang.Class<DATA_LIST> dataListType)
      Returns the property descriptor for a given object type for the CmdType class.
      static boolean writeDeleteElements​(java.lang.Object elements, java.lang.Object oldData, java.lang.Object updateData)
      This method writes the given elements type by creating a ElementTagType for every attribute that is null in the update and not null in the old data.
      static void writeForAllNonNullProperties​(java.lang.Object writable, java.lang.Object update)
      Overwrites all attributes of the writeable by the base attributes of the update that are not null in the update.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createNewDataWithTaggedElements

        public static <T> T createNewDataWithTaggedElements​(T data,
                                                            java.lang.Object elements)
        This method copies the given data object but only sets elements (attributes) that are tagged by the given elements.
        Type Parameters:
        T - data object type
        Parameters:
        data - the data object to copy
        elements - the elements that tags elements (attributes) to include
        Returns:
        a copy of the given data object that only holds tagged elements (attributes)
      • writeDeleteElements

        public static boolean writeDeleteElements​(java.lang.Object elements,
                                                  java.lang.Object oldData,
                                                  java.lang.Object updateData)
        This method writes the given elements type by creating a ElementTagType for every attribute that is null in the update and not null in the old data. This is to be used to notify deletion of elements. The method is recursive for attributes of the elements type that are not of type ElementTagType. The first call of this method should always use an instance of the ELEMENTS type and the given data should be of type DATA.
        Parameters:
        elements - the elements type object to write
        oldData - the old data
        updateData - the new data
        Returns:
        if any element was written
      • dataEquals

        public static boolean dataEquals​(java.lang.Object a,
                                         java.lang.Object b)
        Checks if data a equals data b. Shall only be used for generated SPINE objects.
        Parameters:
        a - data object a
        b - data object b
        Returns:
        if a and b are equals
      • writeForAllNonNullProperties

        public static void writeForAllNonNullProperties​(java.lang.Object writable,
                                                        java.lang.Object update)
        Overwrites all attributes of the writeable by the base attributes of the update that are not null in the update. Base values are defined by BASE_DATA_TYPES. For all other types this function will recursively call itself (for none null objects) to update these with the same logic. NOTE: the BASE_DATA_TYPES list possibly may not be complete and should be updated if this causes an issue.
        Parameters:
        writable - the writable object
        update - the update object
      • dataCopy

        public static <T> T dataCopy​(T data)
        Create a deep copy of the given data and return it. Should only be used on generated SPINE objects, or lists thereof.
        Type Parameters:
        T - the type of data to copy
        Parameters:
        data - the object to copy from
        Returns:
        a new copy of data
      • deepCopyList

        public static <T> java.util.List<T> deepCopyList​(java.util.List<T> data)
      • deleteElements

        public static void deleteElements​(java.lang.Object data,
                                          java.lang.Object elements)
        Deletes the elements that are defined by the given elements in the given data object.
        Parameters:
        data - the data to delete from
        elements - the elements that defines the elements to delete
      • getDataListPropertyDescriptorForCmdType

        public static <DATA_LIST> java.beans.PropertyDescriptor getDataListPropertyDescriptorForCmdType​(java.lang.Class<DATA_LIST> dataListType)
        Returns the property descriptor for a given object type for the CmdType class.
        Type Parameters:
        DATA_LIST - the data list type to look for
        Parameters:
        dataListType - the class object for DATA_LIST
        Returns:
        the property descriptor for given type
      • getDataListForTaggedElements

        public static <DATA,​ELEMENTS> java.util.List<DATA> getDataListForTaggedElements​(ELEMENTS elements,
                                                                                              java.util.List<DATA> selectedData)
        This method filters the given data object list so that it returns a list of data objects that only hold attributes tagged by the given elements. The method does not alter the given data objects but instead creates a new instance of each data object and adds only the tagged elements. If elements is null the given dataList is returned.
        Type Parameters:
        DATA - type of data objects to process
        ELEMENTS - type of elements objects to check against
        Parameters:
        elements - the elements that tags elements (attributes) to include
        selectedData - the data object list to filter
        Returns:
        a list of data objects with only elements (attributes) set that are tagged by the elements