org.opensha.commons.data
Class WeightedList<E>

java.lang.Object
  extended by org.opensha.commons.data.WeightedList<E>
All Implemented Interfaces:
XMLSaveable

public class WeightedList<E>
extends Object
implements XMLSaveable


Field Summary
static String XML_METADATA_NAME
           
 
Constructor Summary
WeightedList()
           
WeightedList(ArrayList<E> objects, ArrayList<Double> weights)
           
 
Method Summary
 void add(E object, double weight)
           
 boolean areWeightsEqual()
           
 E get(int i)
           
static String getName(Object obj)
           
 double getWeight(E object)
           
 double getWeight(int i)
           
 double getWeightedAverage(ArrayList<Double> values)
          Returns the sum of each value multiplied by its respective weight.
 double getWeightedAverage(double[] values)
          Returns the sum of each value multiplied by its respective weight.
 double getWeightSum()
           
 double getWeightValueMax()
          Get the maximum weight value allowed.
 double getWeightValueMin()
          Get the minumum weight value allowed.
 boolean isForceNormalization()
           
 boolean isNormalized()
           
 boolean isWeightWithinRange(double weight)
           
 void normalize()
           
 void set(ArrayList<E> objects, ArrayList<Double> weights)
          Set both the objects and the weights
 void setForceNormalization(boolean forceNormalization)
           
 void setObjects(ArrayList<E> objects)
          Set the list of objects
 void setWeight(int i, double weight)
           
 void setWeights(ArrayList<Double> newWeights)
          Sets and validates the weights
 void setWeightsEqual()
           
 void setWeightsFromXMLMetadata(Element el)
           
 void setWeightsToConstant(double weight)
           
 void setWeightValueMax(double weightValueMax)
          Set the maximum weight value allowed.
 void setWeightValueMin(double weightValueMin)
          Set the minimum weight value allowed.
 int size()
           
 String toString()
           
 Element toXMLMetadata(Element root)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

XML_METADATA_NAME

public static final String XML_METADATA_NAME
See Also:
Constant Field Values
Constructor Detail

WeightedList

public WeightedList()

WeightedList

public WeightedList(ArrayList<E> objects,
                    ArrayList<Double> weights)
Method Detail

add

public void add(E object,
                double weight)
         throws IllegalStateException
Throws:
IllegalStateException

setWeights

public void setWeights(ArrayList<Double> newWeights)
                throws IllegalStateException
Sets and validates the weights

Parameters:
newWeights -
Throws:
IllegalStateException - if the weights are invalid

setObjects

public void setObjects(ArrayList<E> objects)
                throws IllegalStateException
Set the list of objects

Parameters:
objects -
Throws:
IllegalStateException - if the objects and weights are invalid

setWeight

public void setWeight(int i,
                      double weight)

set

public void set(ArrayList<E> objects,
                ArrayList<Double> weights)
         throws IllegalStateException
Set both the objects and the weights

Parameters:
objects -
weights -
Throws:
IllegalStateException - if the objects and weights are invalid

size

public int size()

getWeight

public double getWeight(int i)

getWeight

public double getWeight(E object)

get

public E get(int i)

areWeightsEqual

public boolean areWeightsEqual()

setWeightsEqual

public void setWeightsEqual()

setWeightsToConstant

public void setWeightsToConstant(double weight)

normalize

public void normalize()

getWeightSum

public double getWeightSum()

isNormalized

public boolean isNormalized()

setForceNormalization

public void setForceNormalization(boolean forceNormalization)

isForceNormalization

public boolean isForceNormalization()

getName

public static String getName(Object obj)

toXMLMetadata

public Element toXMLMetadata(Element root)
Specified by:
toXMLMetadata in interface XMLSaveable

setWeightsFromXMLMetadata

public void setWeightsFromXMLMetadata(Element el)

toString

public String toString()
Overrides:
toString in class Object

getWeightValueMin

public double getWeightValueMin()
Get the minumum weight value allowed.

Returns:
minumum weight value allowed.

setWeightValueMin

public void setWeightValueMin(double weightValueMin)
Set the minimum weight value allowed.

Parameters:
weightValueMax -

getWeightValueMax

public double getWeightValueMax()
Get the maximum weight value allowed.

Returns:
maximum weight value allowed.

setWeightValueMax

public void setWeightValueMax(double weightValueMax)
Set the maximum weight value allowed.

Parameters:
listValueMax -

isWeightWithinRange

public boolean isWeightWithinRange(double weight)

getWeightedAverage

public double getWeightedAverage(ArrayList<Double> values)
Returns the sum of each value multiplied by its respective weight.

Parameters:
values - values to return the weighted average
Returns:
weighted average
Throws:
IllegalArgumentException - if the size of values doesn't match the size of this list.

getWeightedAverage

public double getWeightedAverage(double[] values)
Returns the sum of each value multiplied by its respective weight.

Parameters:
values - values to return the weighted average
Returns:
weighted average
Throws:
IllegalArgumentException - if the size of values doesn't match the size of this list.