2016-03-16 15:12:05 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.accounting.analytics;
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class NumberedFilter extends Filter {
|
|
|
|
|
|
|
|
protected Double d;
|
2016-03-16 15:53:59 +01:00
|
|
|
protected String orderingProperty;
|
2016-03-16 15:12:05 +01:00
|
|
|
|
2016-03-16 15:53:59 +01:00
|
|
|
public NumberedFilter(String key, String value, Number n, String orderingProperty) {
|
2016-03-16 15:12:05 +01:00
|
|
|
super(key, value);
|
|
|
|
this.d = n.doubleValue();
|
2016-03-16 15:53:59 +01:00
|
|
|
this.orderingProperty = orderingProperty;
|
2016-03-16 15:12:05 +01:00
|
|
|
}
|
|
|
|
|
2016-03-16 15:53:59 +01:00
|
|
|
public NumberedFilter(Filter filter, Number n, String orderingProperty) {
|
|
|
|
this(filter.key, filter.value, n, orderingProperty);
|
2016-03-16 15:12:05 +01:00
|
|
|
}
|
|
|
|
|
2016-03-16 15:53:59 +01:00
|
|
|
public NumberedFilter(Filter filter, Map<Calendar, Info> timeSeries, String orderingProperty) throws Exception {
|
2016-03-16 15:12:05 +01:00
|
|
|
super(filter.key, filter.value);
|
|
|
|
|
2016-03-16 15:53:59 +01:00
|
|
|
this.d = new Double(0);
|
|
|
|
this.orderingProperty = orderingProperty;
|
|
|
|
|
2016-03-16 15:12:05 +01:00
|
|
|
for(Info info : timeSeries.values()){
|
|
|
|
JSONObject value = info.getValue();
|
2016-03-16 15:53:59 +01:00
|
|
|
if(this.d == null){
|
|
|
|
this.d = value.getDouble(orderingProperty);
|
2016-03-16 15:12:05 +01:00
|
|
|
}else{
|
2016-03-16 15:53:59 +01:00
|
|
|
this.d = this.d + value.getDouble(orderingProperty);
|
2016-03-16 15:12:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-16 15:53:59 +01:00
|
|
|
* @return the d
|
2016-03-16 15:12:05 +01:00
|
|
|
*/
|
2016-03-16 15:53:59 +01:00
|
|
|
public Double getDouble() {
|
2016-03-16 15:12:05 +01:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-16 15:53:59 +01:00
|
|
|
* @param d the d to set
|
2016-03-16 15:12:05 +01:00
|
|
|
*/
|
2016-03-16 15:53:59 +01:00
|
|
|
public void setDouble(Double d) {
|
|
|
|
this.d = d;
|
2016-03-16 15:12:05 +01:00
|
|
|
}
|
2016-03-16 15:53:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the orderingProperty
|
|
|
|
*/
|
|
|
|
public String getOrderingProperty() {
|
|
|
|
return orderingProperty;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param orderingProperty the orderingProperty to set
|
|
|
|
*/
|
|
|
|
public void setOrderingProperty(String orderingProperty) {
|
|
|
|
this.orderingProperty = orderingProperty;
|
|
|
|
}
|
|
|
|
|
2016-03-16 15:12:05 +01:00
|
|
|
/** {@inheritDoc} */
|
|
|
|
public int compareTo(NumberedFilter numberedFilter) {
|
|
|
|
int compareResult = this.d.compareTo(numberedFilter.d);
|
|
|
|
if(compareResult==0){
|
|
|
|
super.compareTo(numberedFilter);
|
|
|
|
}
|
|
|
|
return compareResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
final int prime = 31;
|
|
|
|
int result = super.hashCode();
|
|
|
|
result = prime * result + ((d == null) ? 0 : d.hashCode());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (this == obj) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!super.equals(obj)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!(obj instanceof NumberedFilter)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
NumberedFilter other = (NumberedFilter) obj;
|
|
|
|
if (d == null) {
|
|
|
|
if (other.d != null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (!d.equals(other.d)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|