Package org.openmuc.jeebus.spine.utils
Class SpineObjects
- java.lang.Object
-
- org.openmuc.jeebus.spine.utils.SpineObjects
-
public final class SpineObjects extends java.lang.ObjectUtility 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> TcreateNewDataWithTaggedElements(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> TdataCopy(T data)Create a deep copy of the given data and return it.static booleandataEquals(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 voiddeleteElements(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.PropertyDescriptorgetDataListPropertyDescriptorForCmdType(java.lang.Class<DATA_LIST> dataListType)Returns the property descriptor for a given object type for theCmdTypeclass.static booleanwriteDeleteElements(java.lang.Object elements, java.lang.Object oldData, java.lang.Object updateData)This method writes the given elements type by creating aElementTagTypefor every attribute that is null in the update and not null in the old data.static voidwriteForAllNonNullProperties(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.
-
-
-
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 copyelements- 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 aElementTagTypefor 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 typeElementTagType. The first call of this method should always use an instance of theELEMENTStype and the given data should be of typeDATA.- Parameters:
elements- the elements type object to writeoldData- the old dataupdateData- 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 ab- 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 byBASE_DATA_TYPES. For all other types this function will recursively call itself (for none null objects) to update these with the same logic. NOTE: theBASE_DATA_TYPESlist possibly may not be complete and should be updated if this causes an issue.- Parameters:
writable- the writable objectupdate- 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 fromelements- 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 theCmdTypeclass.- 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 processELEMENTS- type of elements objects to check against- Parameters:
elements- the elements that tags elements (attributes) to includeselectedData- the data object list to filter- Returns:
- a list of data objects with only elements (attributes) set that are tagged by the elements
-
-