org.jjoost.util.filters
Class PartialOrderOverride<S,T>

java.lang.Object
  extended by org.jjoost.util.filters.PartialOrderOverride<S,T>
All Implemented Interfaces:
FilterPartialOrder<T>

public class PartialOrderOverride<S,T>
extends java.lang.Object
implements FilterPartialOrder<T>

Constructs a FilterPartialOrder which delegates to the provided filter, but ignores the comparator provided to it, always using the one provided here instead. That is, this forces the comparator used by the provided filter to always be the one provided here. It also transforms the type of the FilterPartialOrder by accepting a method from a new type to the type accepted by the provided filter, thereby providing a filter over the domain type of the function. The function should be stable with regards to the comparator, i.e. a < b <==> f.f(a) < f.f(b)


Constructor Summary
PartialOrderOverride(FilterPartialOrder<S> underlying, java.util.Comparator<? super S> cmp, Function<? super T,? extends S> f)
          Constructs a FilterPartialOrder which delegates to the provided filter, but ignores the comparator provided to it, always using the one provided here instead.
 
Method Summary
 boolean accept(T test, java.util.Comparator<? super T> _)
          Return true iff this filter and comparator combination accept the provided value
static
<S,T> PartialOrderOverride<S,T>
get(FilterPartialOrder<S> filter, java.util.Comparator<? super S> cmp, Function<? super T,? extends S> f)
          Returns a FilterPartialOrder which delegates to the provided filter, but ignores the comparator provided to it, always using the one provided here instead.
 boolean mayAcceptBetween(T lb, boolean lbInclusive, T ub, boolean ubInclusive, java.util.Comparator<? super T> _)
          Returns true if there exists (in the total order defined by the comparator, not necessarily in any concrete data set this is being applied to) a value between lb and ub that this filter may accept.
 boolean mayRejectBetween(T lb, boolean lbInclusive, T ub, boolean ubInclusive, java.util.Comparator<? super T> _)
          Returns true if there exists (in the total order defined by the comparator, not necessarily in any concrete data set this is being applied to) a value between lb and ub that this filter may reject.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PartialOrderOverride

public PartialOrderOverride(FilterPartialOrder<S> underlying,
                            java.util.Comparator<? super S> cmp,
                            Function<? super T,? extends S> f)
Constructs a FilterPartialOrder which delegates to the provided filter, but ignores the comparator provided to it, always using the one provided here instead. That is, this forces the comparator used by the provided filter to always be the one provided here. It also transforms the type of the FilterPartialOrder by accepting a method from a new type to the type accepted by the provided filter, thereby providing a filter over the domain type of the function. The function should be stable with regards to the comparator, i.e. a < b <==> f.f(a) < f.f(b)

Parameters:
underlying - the partial order filter to wrap
cmp - the comparator to pass to its accepts() methods, overriding the one provided by utilising classes
f - a function whose range is the input type of the provided filter, and whose domain will be the input type of the filter returned
Method Detail

mayAcceptBetween

public boolean mayAcceptBetween(T lb,
                                boolean lbInclusive,
                                T ub,
                                boolean ubInclusive,
                                java.util.Comparator<? super T> _)
Description copied from interface: FilterPartialOrder
Returns true if there exists (in the total order defined by the comparator, not necessarily in any concrete data set this is being applied to) a value between lb and ub that this filter may accept. This method may return true if there is no such value, at the cost of more expensive execution but valid behaviour, however it cannot return false if there is such a value without breaking functionality. null values should be seen as both +/- infinity, i.e. containsBetween(null, o) should return containsBefore(o) and containsBetween(o, null) should return containsAfter(o) containsBetween should take arguments IN ORDER, i.e. o1 <= o2; behaviour where o2 < o1 is undefined.

Specified by:
mayAcceptBetween in interface FilterPartialOrder<T>
Parameters:
lb - the lower bound of the range to check
lbInclusive - if the lower bound should be taken as inclusive
ub - the upper bound of the range to check
ubInclusive - if the upper bound should be taken as inclusive
_ - the partial order
Returns:
true, if there may exists a value V such that lb <(/<=) V <(/<=) ub and accept(V, cmp) == true

mayRejectBetween

public boolean mayRejectBetween(T lb,
                                boolean lbInclusive,
                                T ub,
                                boolean ubInclusive,
                                java.util.Comparator<? super T> _)
Description copied from interface: FilterPartialOrder
Returns true if there exists (in the total order defined by the comparator, not necessarily in any concrete data set this is being applied to) a value between lb and ub that this filter may reject. This method may return true if there is no such value at the cost of more expensive execution but valid behaviour, however it cannot return false if there is such a value without breaking functionality. null values should be seen as both +/- infinity, i.e. containsBetween(null, o) should return containsBefore(o) and containsBetween(o, null) should return containsAfter(o) containsBetween should take arguments IN ORDER, i.e. o1 <= o2; behaviour where o2 < o1 is undefined.

Specified by:
mayRejectBetween in interface FilterPartialOrder<T>
Parameters:
lb - the lower bound of the range to check
lbInclusive - if the lower bound should be taken as inclusive
ub - the upper bound of the range to check
ubInclusive - if the upper bound should be taken as inclusive
_ - the partial order
Returns:
true, if there may exists a value V such that lb <(/<=) V <(/<=) ub and accept(V, cmp) == false

accept

public boolean accept(T test,
                      java.util.Comparator<? super T> _)
Description copied from interface: FilterPartialOrder
Return true iff this filter and comparator combination accept the provided value

Specified by:
accept in interface FilterPartialOrder<T>
Parameters:
test - the value to check
_ - the partial order
Returns:
true, if accepts

get

public static <S,T> PartialOrderOverride<S,T> get(FilterPartialOrder<S> filter,
                                                  java.util.Comparator<? super S> cmp,
                                                  Function<? super T,? extends S> f)
Returns a FilterPartialOrder which delegates to the provided filter, but ignores the comparator provided to it, always using the one provided here instead. That is, this forces the comparator used by the provided filter to always be the one provided here. It also transforms the type of the FilterPartialOrder by accepting a method from a new type to the type accepted by the provided filter, thereby providing a filter over the domain type of the function. The function should be stable with regards to the comparator, i.e. a < b <==> f.f(a) < f.f(b)

Parameters:
filter - the partial order filter to wrap
cmp - the comparator to pass to its accepts() methods, overriding the one provided by utilising classes
f - a function whose range is the input type of the provided filter, and whose domain will be the input type of the filter returned
Returns:
a FilterPartialOrder which always uses the provided comparator