SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
WeightsComparable.java
1package umontreal.ssj.latnetbuilder.weights;
2
3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.List;
6
15
16public abstract class WeightsComparable<T extends Comparable<T>> extends Weights<T> {
17
18 protected ArrayList<SingletonWeightComparable<T>> weights; // actual weights
19 boolean sorted = false;
20
27 weights = new ArrayList<SingletonWeightComparable<T>>(w);
28 }
29
34 weights = new ArrayList<SingletonWeightComparable<T>>();
35 }
36
42 // TODO: changing return type with getWeights() does not work. do we really need
43 // this?
44 public ArrayList<SingletonWeightComparable<T>> getComparableWeights() {
45 return weights;
46 }
47
54 public void add(SingletonWeightComparable<T> singletonWeight) {
55 boolean added = false;
56 for (SingletonWeightComparable<T> w : weights) {
57 if (w.getIndex() == singletonWeight.getIndex() && (!added)) {
58 weights.set(weights.indexOf(w), singletonWeight);
59 added = true;
60 }
61 }
62 if (!added)
63 weights.add(singletonWeight);
64
65 sorted = false;
66 }
67
71 public void sort() {
72 Collections.sort(weights);
73 sorted = true;
74 }
75
83 public void add(T index, double weight) {
84 add(new SingletonWeightComparable<T>(index, weight));
85 }
86
87}
void add(T index, double weight)
Adds a new weight with index 'index' and weight 'weight' or overwrites it, if the index already exist...
WeightsComparable(List< SingletonWeightComparable< T > > w)
Constructs weights from a list of SingletonWeightsComparable.
WeightsComparable()
Initializes an empty list of comparable weights.
ArrayList< SingletonWeightComparable< T > > getComparableWeights()
Returns the current comparable weights.
void add(SingletonWeightComparable< T > singletonWeight)
Adds a new comparable weight to the list.
Weights(List< SingletonWeight< T > > w)
Constructs weights from a list of SingletonWeights.
Definition Weights.java:33