Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public static final byte RANGE_EXCLUSIVE = 0; // 00
  2. public static final byte RANGE_INCLUSIVE = 3; // 11
  3. public static final byte RANGE_MAX_INCLUSIVE = 1; // 01
  4. public static final byte RANGE_MIN_INCLUSIVE = 2; // 10
  5.  
  6. public static boolean inRange(long value, long range_a, long range_b, byte checkMode) {
  7. if (range_a > range_b) {
  8. long tmp = range_a;
  9. range_a = range_b;
  10. range_b = tmp;
  11. }
  12.  
  13. // If value is on the left edge - check if it is inclusive
  14. if (value == range_a && (checkMode & RANGE_MIN_INCLUSIVE) == 0) return false;
  15. // If value is on the right edge - check if it is inclusive
  16. if (value == range_b && (checkMode & RANGE_MAX_INCLUSIVE) == 0) return false;
  17.  
  18. // If value is out of range - return false
  19. if (value < range_a) return false;
  20. if (value > range_b) return false;
  21.  
  22. return true;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement