accounting-analytics/src/main/java/org/gcube/accounting/analytics/Filter.java

102 lines
1.8 KiB
Java

/**
*
*/
package org.gcube.accounting.analytics;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class Filter implements Comparable<Filter> {
protected String key;
protected String value;
/**
* @param key the key to filter
* @param value the value fo the key to filter
*/
public Filter(String key, String value) {
this.key = key;
this.value = value;
}
/**
* @return the key
*/
public String getKey() {
return key;
}
/**
* @param key the key to set
*/
public void setKey(String key) {
this.key = key;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
@Override
public String toString(){
return String.format("{ \"%s\" : \"%s\" }", key, value);
}
/** {@inheritDoc} */
@Override
public int compareTo(Filter filter) {
int compareResult = this.key.compareTo(filter.key);
if(compareResult == 0){
compareResult = this.value.compareTo(filter.value);
}
return compareResult;
}
/** {@inheritDoc} */
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((key == null) ? 0 : key.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
/** {@inheritDoc} */
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Filter other = (Filter) obj;
if (key == null) {
if (other.key != null)
return false;
} else if (!key.equals(other.key))
return false;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}
}