com.cogpunk.math.probability.EventGreaterThanSelector Maven / Gradle / Ivy
Show all versions of cogpunk-math Show documentation
package com.cogpunk.math.probability;
import java.util.Set;
import java.util.TreeMap;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.EqualsBuilder;
/**
* Selector for identifying events 'greater than' a given, as defined by Comparable, from a given profile
*
* @param The event type
* @param The probability type
*/
public class EventGreaterThanSelector, P extends Number> implements EventSelector {
private E threshold;
public EventGreaterThanSelector(E threshold) {
this.threshold = threshold;
}
@Override
public Set selectEvents(EventProbabilityProfile profile) {
TreeMap map = new TreeMap();
map.putAll(profile.map());
return map.tailMap(threshold, false).keySet();
}
@Override
public boolean equals(final Object other) {
if (!(other instanceof EventGreaterThanSelector)) {
return false;
}
EventGreaterThanSelector, ?> castOther = (EventGreaterThanSelector, ?>) other;
return new EqualsBuilder().append(threshold, castOther.threshold).isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(threshold).toHashCode();
}
}