com.github.TKnudsen.ComplexDataObject.model.processors.complexDataObject.NullAttributeValueObjectRemover 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.model.processors.complexDataObject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.github.TKnudsen.ComplexDataObject.data.complexDataObject.ComplexDataContainer;
import com.github.TKnudsen.ComplexDataObject.data.complexDataObject.ComplexDataObject;
/**
*
* Title: NullAttributeValueObjectRemover
*
*
*
* Description: Removes ComplexDataObjects with null values for a given
* Attribute.
*
*
*
* Copyright: Copyright (c) 2016
*
*
* @author Juergen Bernard
* @version 1.02
*/
public class NullAttributeValueObjectRemover implements IComplexDataObjectProcessor {
private String attribute;
public NullAttributeValueObjectRemover(String attribute) {
this.attribute = attribute;
}
@Override
public void process(ComplexDataContainer container) {
if (attribute == null)
return;
List removes = new ArrayList<>();
for (Iterator iterator = container.iterator(); iterator.hasNext();) {
ComplexDataObject complexDataObject = iterator.next();
Object value = complexDataObject.getAttribute(attribute);
if (value == null)
removes.add(complexDataObject);
}
for (ComplexDataObject complexDataObject : removes)
container.remove(complexDataObject);
}
@Override
public void process(List data) {
ComplexDataContainer container = new ComplexDataContainer(data);
process(container);
}
public String getAttribute() {
return attribute;
}
public void setAttribute(String attribute) {
this.attribute = attribute;
}
@Override
public DataProcessingCategory getPreprocessingCategory() {
return DataProcessingCategory.DATA_CLEANING;
}
}