Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package gedi.solutions.geode.operations.stats;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* A ComboValue is a value that is the logical combination of a set of other
* stat values.
For now ComboValue has a simple implementation that does
* not suppport updates.
*/
class ComboValue extends AbstractValue {
private final ResourceType type;
private final StatValue[] values;
/**
* Creates a ComboValue by adding all the specified values together.
*/
ComboValue(List> valueList) {
this((StatValue[]) valueList.toArray(new StatValue[valueList.size()]));
}
/**
* Creates a ComboValue by adding all the specified values together.
*/
ComboValue(StatValue[] values) {
this.values = values;
this.filter = this.values[0].getFilter();
String typeName = this.values[0].getType().getName();
String statName = this.values[0].getDescriptor().getName();
int bestTypeIdx = 0;
for (int i = 1; i < this.values.length; i++) {
if (this.filter != this.values[i].getFilter()) {
/* I'm not sure why this would happen.
* If it really can happen then this code should change
* the filter since a client has no way to select values
* based on the filter.
*/
throw new IllegalArgumentException(
"Can't combine values with different filters");
}
if (!typeName.equals(this.values[i].getType().getName())) {
throw new IllegalArgumentException(
"Can't combine values with different types");
}
if (!statName.equals(this.values[i].getDescriptor().getName())) {
throw new IllegalArgumentException("Can't combine different stats");
}
if (this.values[i].getDescriptor().isCounter()) {
// its a counter which is not the default
if (!this.values[i].getDescriptor().isLargerBetter()) {
// this guy has non-defaults for both use him
bestTypeIdx = i;
} else if (this.values[bestTypeIdx].getDescriptor().isCounter()
== this.values[bestTypeIdx].getDescriptor().isLargerBetter()) {
// as long as we haven't already found a guy with defaults
// make this guy the best type
bestTypeIdx = i;
}
} else {
// its a gauge, see if it has a non-default largerBetter
if (this.values[i].getDescriptor().isLargerBetter()) {
// as long as we haven't already found a guy with defaults
if (this.values[bestTypeIdx].getDescriptor().isCounter()
== this.values[bestTypeIdx].getDescriptor().isLargerBetter()) {
// make this guy the best type
bestTypeIdx = i;
}
}
}
}
this.type = this.values[bestTypeIdx].getType();
this.descriptor = this.values[bestTypeIdx].getDescriptor();
}
private ComboValue(ComboValue original, long startTime, long endTime) {
this.startTime = startTime;
this.endTime = endTime;
this.type = original.getType();
this.descriptor = original.getDescriptor();
this.filter = original.getFilter();
this.values = new StatValue[original.values.length];
for (int i = 0; i < this.values.length; i++) {
this.values[i] = original.values[i].createTrimmed(startTime, endTime);
}
}
public StatValue createTrimmed(long startTime, long endTime) {
if (startTime == this.startTime && endTime == this.endTime) {
return this;
} else {
return new ComboValue(this, startTime, endTime);
}
}
public ResourceType getType() {
return this.type;
}
public ResourceInst[] getResources() {
Set