/src/kilim/analysis/Range.java

http://github.com/kilim/kilim · Java · 37 lines · 21 code · 5 blank · 11 comment · 7 complexity · 97d2c8da6354a4cea6a3aefe4d9403d5 MD5 · raw file

  1. /* Copyright (c) 2006, Sriram Srinivasan
  2. *
  3. * You may distribute this software under the terms of the license
  4. * specified in the file "License"
  5. */
  6. package kilim.analysis;
  7. /**
  8. * Used by catch handlers to handle overlapping ranges
  9. *
  10. */
  11. public class Range {
  12. int from;
  13. int to;
  14. public Range(int aFrom, int aTo) {
  15. from = aFrom;
  16. to = aTo;
  17. }
  18. static Range intersect(int a1, int e1, int a2, int e2) {
  19. // a2 lies between a1 and e1 or a1 between a2 and e2
  20. // all comparisons are inclusive of endpoints
  21. assert a1 <= e1 && a2 <= e2;
  22. int a;
  23. if (a1 <= a2 && a2 <= e1) {
  24. a = a2;
  25. } else if (a2 <= a1 && a1 <= e2) {
  26. a = a1;
  27. } else {
  28. return null;
  29. }
  30. return new Range(a, e1 < e2 ? e1 : e2);
  31. }
  32. }