code: public static List<Range> union(List<Range> ranges){
          ranges = new ArrayList<Range>(ranges);
          Collections.sort(ranges, new Comparator<Range>(){
              @Override
              public int compare(Range r1, Range r2){
                  return r1.min-r2.min;
              }
          });
          List<Range> union = new ArrayList<Range>();
          for(Range r: ranges){
              if(union.isEmpty())
                  union.add(r);
              else
                  CollectionUtil.addAll(union, union.remove(union.size() - 1).union(r));
          }
          return union;
      }
docs: /*-------------------------------------------------[ Helpers ]---------------------------------------------------