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

com.github.TKnudsen.ComplexDataObject.model.processors.complexDataObject.AttributeValueMultiplier 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.

The newest version!
package com.github.TKnudsen.ComplexDataObject.model.processors.complexDataObject;

import java.util.Arrays;
import java.util.List;

import com.github.TKnudsen.ComplexDataObject.data.complexDataObject.ComplexDataContainer;
import com.github.TKnudsen.ComplexDataObject.data.complexDataObject.ComplexDataObject;

/**
 * 

* Multiplies a scalar with the numerical values in the given numerical * attribute. *

* *

* Copyright: Copyright (c) 2017-2019 *

* * @author Juergen Bernard * @version 1.01 */ public class AttributeValueMultiplier implements IComplexDataObjectProcessor { private final String attribute; private final double scalar; public AttributeValueMultiplier(String attribute, double scalar) { this.attribute = attribute; this.scalar = scalar; } @Override public void process(List data) { for (ComplexDataObject cdo : data) { if (cdo == null) return; Object o = cdo.getAttribute(attribute); if (o == null) continue; if (!(o instanceof Number)) continue; Number value = (Number) o; if (Double.isNaN(value.doubleValue())) continue; cdo.add(attribute, value.doubleValue() * scalar); } } @Override public void process(ComplexDataContainer container) { for (ComplexDataObject complexDataObject : container) process(Arrays.asList(complexDataObject)); } @Override public DataProcessingCategory getPreprocessingCategory() { return DataProcessingCategory.SECONDARY_DATA_PROVIDER; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy