Java tutorial
//package com.java2s; import java.util.Comparator; public class Main { /** * Checks if the given object (or range upper bound) falls under another * upper bound. * * <p>Generally, this is used to test if an object is under the specified * upper bound (in which case, the parameter {@code oIncluded} will be true). * But we can also tell if the upper bound of one range (specified by the * parameters {@code o} and {@code oIncluded}) falls under the upper bound * of another range (specified by {@code to} and {@code toInclusive}). * * @param <T> the type of the element * @param o the object * @param oIncluded true if {@code o} needs to be included in the range * @param to the upper bound of the range * @param toInclusive true if {@code to} is included in the range, false * otherwise * @param comp the comparator used to compare {@code o} to {@code to} * (cannot be null) * @return true if the specified object is less than the bound and the * bound is exclusive, true if the object is less than or equal * to the bound and the bound is inclusive, and false otherwise */ public static <T> boolean isInRangeHigh(T o, boolean oIncluded, T to, boolean toInclusive, Comparator<? super T> comp) { if (to != null) { int c = comp.compare(o, to); if (c > 0 || (c == 0 && oIncluded && !toInclusive)) { return false; } } return true; } }