Botre Posted September 7, 2014 Share Posted September 7, 2014 (edited) public class Interval { private final long firstEntry; private final long lastEntry; private final boolean includeFirstEntry; private final boolean includeLastEntry; public Interval(final boolean includeFirstEntry, final long firstEntry, final long lastEntry, final boolean includeLastEntry) { this.firstEntry = firstEntry; this.lastEntry = lastEntry; this.includeFirstEntry = includeFirstEntry; this.includeLastEntry = includeLastEntry; } public boolean contains(long n) { return (n == firstEntry && includeFirstEntry) || (n == lastEntry && includeLastEntry) || (n > firstEntry && n < lastEntry); } } Edited September 7, 2014 by Botrepreneur 1 Link to comment Share on other sites More sharing options...
darkxor Posted September 7, 2014 Share Posted September 7, 2014 Can just make always not including firstEntry, lastEntry? And like if(includeFirstEntry) firstEntry--; if(includeLastEntry) lastEntry++; Link to comment Share on other sites More sharing options...
Botre Posted September 7, 2014 Author Share Posted September 7, 2014 (edited) Can just make always not including firstEntry, lastEntry? And like if(includeFirstEntry) firstEntry--; if(includeLastEntry) lastEntry++; I see what you mean, I could but I prefer the boolean specification because it mimics the mathematical notation for intervals. [ 1, 40 [ = Edited September 7, 2014 by Botrepreneur Link to comment Share on other sites More sharing options...
Joseph Posted September 7, 2014 Share Posted September 7, 2014 (edited) I see what you mean, I could but I prefer the boolean specification because it mimics the mathematical notation for intervals. [ 1, 40 [ = i see what you mean, it does look like it i think you meant [ 1,40 ) Edited September 7, 2014 by josedpay Link to comment Share on other sites More sharing options...
Botre Posted September 7, 2014 Author Share Posted September 7, 2014 i see what you mean, it does look like it i think you meant [ 1,40 ) Both notations are accepted by the ISO 80000-2 Link to comment Share on other sites More sharing options...