com.github.TKnudsen.ComplexDataObject.data.complexDataObject.ComplexDataContainer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of complex-data-object Show documentation
Show all versions of complex-data-object Show documentation
A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.
The newest version!
package com.github.TKnudsen.ComplexDataObject.data.complexDataObject;
import java.util.Map;
import com.github.TKnudsen.ComplexDataObject.data.DataContainer;
import com.github.TKnudsen.ComplexDataObject.data.DataSchema;
import com.github.TKnudsen.ComplexDataObject.data.complexDataObject.events.IComplexDataObjectListener;
/**
*
* Title: ComplexDataContainer
*
*
*
* Description: ComplexDataContainer stores and manages ComplexDataObjects. A
* DataSchema contains all keys of the ComplexDataObjects.
*
*
*
* Copyright: Copyright (c) 2015-2019
*
*
* @author Juergen Bernard
* @version 1.03
*/
public class ComplexDataContainer extends DataContainer implements IComplexDataObjectListener {
public ComplexDataContainer(DataSchema dataSchema) {
super(dataSchema);
}
public ComplexDataContainer(Map objectsMap) {
super(objectsMap);
for (ComplexDataObject cdo : objectsMap.values())
cdo.addComplexDataObjectListener(this);
}
public ComplexDataContainer(Iterable objects) {
super(objects);
for (ComplexDataObject cdo : objects)
cdo.addComplexDataObjectListener(this);
}
/**
* adds a new object. updates data schema and attribute values.
*
* @param object
* @return
*/
public boolean add(ComplexDataObject object) {
Boolean b = super.add(object);
object.addComplexDataObjectListener(this);
return b;
}
@Override
public void attributeValueChanged(ComplexDataObject cdo, String attribute) {
// extend schema if attribute does not exist and meaningful(value !=null)
if (!dataSchema.contains(attribute) && cdo.getAttribute(attribute) != null)
extendDataSchema(cdo);
// update attribute
if (attributeValues.get(attribute) != null)
this.attributeValues.get(attribute).put(cdo.getID(), cdo.getAttribute(attribute));
else
calculateEntities(attribute);
}
@Override
public void attributeRemoved(ComplexDataObject cdo, String attribute) {
if (attributeValues.get(attribute) != null)
if (this.attributeValues.get(attribute).get(cdo.getID()) != null)
this.attributeValues.get(attribute).remove(cdo.getID());
}
}