netflix.ocelli.algorithm.LinearWeightingStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ocelli-core Show documentation
Show all versions of ocelli-core Show documentation
ocelli-core developed by Netflix
package netflix.ocelli.algorithm;
import java.util.ArrayList;
import java.util.List;
import netflix.ocelli.WeightingStrategy;
import netflix.ocelli.selectors.ClientsAndWeights;
import rx.functions.Func1;
public class LinearWeightingStrategy implements WeightingStrategy {
private Func1 func;
public LinearWeightingStrategy(Func1 func) {
this.func = func;
}
@Override
public ClientsAndWeights call(List source) {
List clients = new ArrayList(source.size());
List weights = new ArrayList(source.size());
if (source.size() > 0) {
for (C context : source) {
clients.add(context);
weights.add(func.call(context));
}
int sum = 0;
for (int i = 0; i < weights.size(); i++) {
sum += weights.get(i);
weights.set(i, sum);
}
}
return new ClientsAndWeights(clients, weights);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy