Guest User

Untitled

a guest
Jan 21st, 2013
226
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * some javadoc would be helpful.  Often when trying to describe method arguments, you'll stumble on better names
  3.  * @param interval
  4.  * @param selectedIntervals
  5.  */
  6. private boolean nonOverlapping(Pair interval, SortedSet<Pair> selectedIntervals) {
  7.     if(selectedIntervals.contains(interval)){  
  8.         return true;  
  9.     }
  10.  
  11.     Pair[] sortedSelections = selectedIntervals.toArray(new Pair[0]);
  12.     int pos = Arrays.binarySearch(sortedSelections, interval);  
  13.    
  14.     // Its a good idea to explain little snippets like this.  Otherwise arbitrary math looks quite cryptic
  15.     pos = (-pos) -1;  
  16.  
  17.     // Check for an overlap on the preceeding element, unless pos == 0 and there cannot be a preceeding element.
  18.     if(pos != 0) {
  19.         if(sortedSelections[pos - 1].getEnd() > interval.getStart()) {
  20.             return false;
  21.         }
  22.     }
  23.  
  24.     // Check for an overlap on the following element, unless pos == len and there cannot be a following element.
  25.     if(pos != sortedSelections.length) {
  26.         if(sortedSelections[pos].getStart > interval.getEnd()) {
  27.             return false;
  28.         }
  29.     }
  30.  
  31.     return true;
  32. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×