Java Number Between between(T subject, T lower, T upper, boolean exclLowerEnd, boolean exclUpperEnd)

Here you can find the source of between(T subject, T lower, T upper, boolean exclLowerEnd, boolean exclUpperEnd)

Description

between

License

Open Source License

Declaration

public static <T extends Comparable<? super T>> boolean between(T subject, T lower, T upper,
            boolean exclLowerEnd, boolean exclUpperEnd) 

Method Source Code

//package com.java2s;

public class Main {
    public static <T extends Comparable<? super T>> boolean between(T subject, T lower, T upper,
            boolean exclLowerEnd, boolean exclUpperEnd) {
        if (subject == null)
            return false;

        boolean validExclEnds = (lower == null ? true : lower.compareTo(subject) < 0)
                && (upper == null ? true : upper.compareTo(subject) > 0);

        return validExclEnds || (!exclLowerEnd && subject.equals(lower))
                || (!exclUpperEnd && subject.equals(upper));
    }//from   ww  w.  j  ava2s  .c o m

    public static <T extends Comparable<? super T>> boolean between(T subject, T lower, T upper) {
        return between(subject, lower, upper, false, false);
    }
}

Related

  1. between(Comparable obj, Comparable from, Comparable to)
  2. between(T lower, T upper, T value)