com.github.TKnudsen.ComplexDataObject.data.attributes.AttributeValueDistribution 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.attributes;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.collections4.CollectionUtils;
import com.github.TKnudsen.ComplexDataObject.data.complexDataObject.ComplexDataObject;
/**
*
* Title: AttributeValueDistribution
*
*
*
* Description: stores the value distribution of an attribute AND the
* priorization of external entities w.r.t. attributes.
*
* Example: Distribution of horse power (attribute) of cars. Two different
* scoring functions A and B have different priorizations of horse power, e.g.,
* A: 100PS, B: 200PS.
*
*
*
* Copyright: Copyright (c) 2018
*
*
* @author Juergen Bernard
* @version 1.02
*/
public class AttributeValueDistribution extends ComplexDataObject implements Comparable {
private Map priorizations = new HashMap<>();
private Collection valueDistribution;
private Class valueType;
private String attributeName;
protected AttributeValueDistribution() {
super();
}
public AttributeValueDistribution(String attributeName, Class valueType, Collection valueDistribution) {
if (!CollectionUtils.isNotEmpty(valueDistribution))
throw new IllegalArgumentException(getName() + ": value distribution must not be null or empty.");
this.attributeName = attributeName;
this.valueType = valueType;
setValueDistribution(valueDistribution);
setName(attributeName);
// it may be necessary to do some validity checks, e.g., whether the attribute
// name contains a line break, etc.
}
public Double getPriorization(String characterOrPriorization) {
return priorizations.get(characterOrPriorization);
}
/**
*
* @param identifier
* @param value
* must not be null. otherwise JSON reader will interpret the value
* as string.
*/
public void setPriorization(String identifier, double value) {
if (Double.isNaN((double) value)) {
System.err.println(getName() + ": priorization must not be NaN. set to 0");
this.priorizations.put(identifier, 0.0);
} else
this.priorizations.put(identifier, value);
}
public Map getPriorizations() {
return priorizations;
}
public void setPriorizations(Map priorizations) {
this.priorizations = priorizations;
}
public Collection getValueDistribution() {
return valueDistribution;
}
public void setValueDistribution(Collection valueDistribution) {
this.valueDistribution = valueDistribution;
}
public Class getValueType() {
return valueType;
}
@Override
public int compareTo(T o) {
if (o == null)
return -1;
if (equals(o))
return 0;
return toString().compareTo(((T) o).toString());
}
public String getAttributeName() {
return this.attributeName;
}
@Override
public String getDescription() {
return "Stores information about the distribution of values of an attribute";
}
@Override
public String toString() {
return getName() + ", " + getAttributeName();
}
}