static public List<Bounds> mergeBounds(List<Bounds> boundsList){
  List<Bounds> newBoundsList=new LinkedList<>();
  if (boundsList.isEmpty()) {
    return newBoundsList;
  }
  Collections.sort(boundsList);
  Bounds prevBounds=new Bounds(boundsList.get(0).start,boundsList.get(0).end);
  for (int i=1; i < boundsList.size(); i++) {
    Bounds currentBounds=boundsList.get(i);
    if (currentBounds.start <= prevBounds.end) {
      prevBounds.end=Math.max(currentBounds.end,prevBounds.end);
    }
 else {
      newBoundsList.add(prevBounds);
      prevBounds=new Bounds(currentBounds.start,currentBounds.end);
    }
  }
  newBoundsList.add(prevBounds);
  return newBoundsList;
}

static public List < Bounds > mergeBounds ( List < Bounds > boundsList ) { List < Bounds > newBoundsList = new LinkedList < > ( ) ; if ( boundsList . isEmpty ( ) ) { return newBoundsList ; } Collections . sort ( boundsList ) ; Bounds prevBounds = new Bounds ( boundsList . get ( 0 ) . start , boundsList . get ( 0 ) . end ) ; for ( int i = 1 ; i < boundsList . size ( ) ; i ++ ) { Bounds currentBounds = boundsList . get ( i ) ; if ( currentBounds . start <= prevBounds . end ) { prevBounds . end = Math . max ( currentBounds . end , prevBounds . end ) ; } else { newBoundsList . add ( prevBounds ) ; prevBounds = new Bounds ( currentBounds . start , currentBounds . end ) ; } } newBoundsList . add ( prevBounds ) ; return newBoundsList ; }
convert a list of bounds in a more compact representation ; this works with overlapping intervals too . remind that bounds define ranges with start inclusive and end inclusive index .
