All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.TKnudsen.ComplexDataObject.data.complexDataObject.ComplexDataObjectTools Maven / Gradle / Ivy

Go to download

A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.

There is a newer version: 0.2.13
Show newest version
package com.github.TKnudsen.ComplexDataObject.data.complexDataObject;

/**
 * 

* Title: ComplexDataObjectTools *

* *

* Description: Provides little helpers for the work with ComplexDataObjects. *

* *

* Copyright: Copyright (c) 2015-2016 *

* * @author Juergen Bernard * @version 1.01 */ public class ComplexDataObjectTools { public static ComplexDataObject clone(ComplexDataObject object) { if (object == null) return null; ComplexDataObject newObject = new ComplexDataObject(object.getName(), object.getDescription()); for (String string : object) { newObject.add(string, object.getAttribute(string)); } return newObject; } /** * Merges ComplexDataObjects. Conflicting attributes are defined by the last * occurrence in the input data. * * @param objects * @return */ public static ComplexDataObject mergeObjects(Iterable objects) { ComplexDataObject mergedObject = new ComplexDataObject(); for (ComplexDataObject object : objects) { for (String attribute : object.keySet()) { if (mergedObject.getAttribute(attribute) != null) System.out.println("overwriting attribute " + attribute + "(" + object.getAttribute(attribute) + "->" + mergedObject.getAttribute(attribute) + ")"); mergedObject.add(attribute, object.getAttribute(attribute)); } if (object.getName() != null) mergedObject.setName(object.getName()); if (object.getDescription() != null) mergedObject.setDescription(object.getDescription()); } return mergedObject; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy