org.decisiondeck.xmcda_oo.structure
Class Weights

java.lang.Object
  extended by org.decisiondeck.xmcda_oo.structure.Weights
All Implemented Interfaces:
Iterable<Criterion>

public class Weights
extends Object
implements Iterable<Criterion>

A set of criteria weights (retrievable by their respective criterion). This object allows to check whether this set of weights is normalized, and to retrieve the equivalent set after normalization.

TODO remove Iterable, it's stupid: this is a map!.


Field Summary
static double DEFAULT_TOLERANCE
          The default allowed tolerance between the sum of the weights and one when assessing whether the weights are normalized.
 
Constructor Summary
Weights()
           
Weights(Weights source)
           
 
Method Summary
 boolean approxEquals(Weights w2, double tolerance)
           
 boolean equals(Object obj)
           
 Set<Criterion> getCriteria()
           
 Weights getNormalized()
          TODO do it with a view that divides by the sum!
 double getSum()
           
 double getTolerance()
           
 Double getWeight(Criterion criterion)
          Returns the weight of the given criterion, or null if no weight has been associated to that criterion.
 int hashCode()
           
 boolean isNormalized()
           
 Iterator<Criterion> iterator()
           
 void putAll(Weights weights)
          Puts all the weights contained in the given object in this object, replacing any current value if the given object contains weights for some criteria already in this object.
 Double putWeight(Criterion criterion, double weight)
          Associates the given weight to the given criterion.
 Double removeWeight(Criterion criterion)
          Removes the weight associated to the given criterion, if it exists.
 void setTolerance(double tolerance)
           
 int size()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_TOLERANCE

public static final double DEFAULT_TOLERANCE
The default allowed tolerance between the sum of the weights and one when assessing whether the weights are normalized.

See Also:
Constant Field Values
Constructor Detail

Weights

public Weights()

Weights

public Weights(Weights source)
Method Detail

getTolerance

public double getTolerance()

setTolerance

public void setTolerance(double tolerance)

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getNormalized

public Weights getNormalized()
TODO do it with a view that divides by the sum! Provides a copy of this set of weights, but where the weights have been normalized. If this set is already normalized, the returned set contains equivalent entries as this one, but is not this one (i.e. modifications to the returned set do not reflect in this one).

Returns:
a set of normalized weights.

getSum

public double getSum()
Returns:
the sum of the weights contained in this set.

getWeight

public Double getWeight(Criterion criterion)
Returns the weight of the given criterion, or null if no weight has been associated to that criterion.

Parameters:
criterion - the criterion to consider. Not null.
Returns:
the weight associated to the given criterion (or null).

hashCode

public int hashCode()
Overrides:
hashCode in class Object

isNormalized

public boolean isNormalized()
Returns:
true if the weights sum to one plus or minus the allowed tolerance.

iterator

public Iterator<Criterion> iterator()
Specified by:
iterator in interface Iterable<Criterion>

putAll

public void putAll(Weights weights)
Puts all the weights contained in the given object in this object, replacing any current value if the given object contains weights for some criteria already in this object.

Parameters:
weights - the weights to add to this object. Not null (but may be empty).

putWeight

public Double putWeight(Criterion criterion,
                        double weight)
Associates the given weight to the given criterion.

Parameters:
criterion - the criterion to consider. Not null.
weight - the weight to associate to the given criterion.
Returns:
the weight that was previously associated to that criterion, or null if there was no.

removeWeight

public Double removeWeight(Criterion criterion)
Removes the weight associated to the given criterion, if it exists. If not, this call has no effect.

Parameters:
criterion - not null.
Returns:
the weight that was previously associated to the given criterion, or null iff there was no.

size

public int size()

toString

public String toString()
Overrides:
toString in class Object

getCriteria

public Set<Criterion> getCriteria()

approxEquals

public boolean approxEquals(Weights w2,
                            double tolerance)


Copyright © 2011. All Rights Reserved.