Providing a consistent interface for inRange function over modded values I want to write a function named inRange which will have below interface

inRange(long a, long b, boolean inclusiveStart, boolean inclusiveEnd)


This function calculates if this.value is in between a &amp; b. However there are two important points to note:


Two boolean values (inclusiveStart &amp; inclusiveEnd) specify if a (or b) should be included in the range.
All 3 values viz. a, b and this.value are modded values i.e they define a circular range.


I have tried writing this function but here is my concern,

How to provide a consistent interface so that client does not have to worry about circular range. Lets say, a == b then should the function consider complete range or should it just consider a single value for the range. Or when a = 0 &amp; b = MOD - 1 then what should be the function behavior for different combinations of boolean values.

Below is my code:

private boolean inRangeBothInclusive(long start, long end) {
    if (start == end)
    return this.value == start;
    else if (start &lt; end) {
    return start &lt;= this.value &amp;&amp;
        this.value &lt;= end;
    } else {
    return !(end &lt;= this.value &amp;&amp;
         this.value &lt;= start);
    }
}


public boolean inRange(long start, long end, boolean startInclusive,
               boolean endInclusive) {
    /* Ranges can have bigger start and smaller end value due to mod */

    if (!startInclusive) {
    start = (start + 1) % MOD;
    }
    if (!endInclusive) {
    end = (end - 1) % MOD;
    if (end &lt; 0)
        end += MOD;
    }
    return inRangeBothInclusive(start, end);
}
If you really need to present the boolean parameters in your client API I would do that as follows

private boolean inRangeBothInclusive(long start, long end) {
    if (start == end) {
        return this.value == start;
    }
    else if (start &lt; end) {
        return start &lt;= this.value &amp;&amp; 
               this.value &lt;= end;
    }
    return !(end &lt;= this.value &amp;&amp;
             this.value &lt;= start);
}




public boolean inRange(long start, long end, boolean startInclusive, boolean endInclusive) {
    start = startInclusive ? start : start + 1;
    end = endInclusive ? end : end - 1;
    return inRangeBothInclusive(start, end);
}