com.cogpunk.math.probability.EventLessThanSelector 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;
/**
* Selectors for defining those less than the defined event, as defined by the comparable
*
* @param Event type
* @param Probability type
*/
public class EventLessThanSelector , P extends Number> implements EventSelector {
private E threshold;
public EventLessThanSelector(E threshold) {
this.threshold = threshold;
}
@Override
public Set selectEvents(EventProbabilityProfile profile) {
TreeMap map = new TreeMap();
map.putAll(profile.map());
return map.headMap(threshold, false).keySet();
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(final Object other) {
if (!(other instanceof EventLessThanSelector)) {
return false;
}
EventLessThanSelector, ?> castOther = (EventLessThanSelector, ?>) other;
return new EqualsBuilder().append(threshold, castOther.threshold).isEquals();
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return new HashCodeBuilder().append(threshold).toHashCode();
}
}