private static void accumulate(Vector ranges,int lb,int ub){
  if (lb <= ub) {
    ranges.add(new int[]{lb,ub});
    for (int j=ranges.size() - 2; j >= 0; --j) {
      int[] rangea=(int[])ranges.elementAt(j);
      int lba=rangea[0];
      int uba=rangea[1];
      int[] rangeb=(int[])ranges.elementAt(j + 1);
      int lbb=rangeb[0];
      int ubb=rangeb[1];
      if (Math.max(lba,lbb) - Math.min(uba,ubb) <= 1) {
        ranges.setElementAt(new int[]{Math.min(lba,lbb),Math.max(uba,ubb)},j);
        ranges.remove(j + 1);
      }
 else       if (lba > lbb) {
        ranges.setElementAt(rangeb,j);
        ranges.setElementAt(rangea,j + 1);
      }
 else {
        break;
      }
    }
  }
}

private static void accumulate ( Vector ranges , int lb , int ub ) { if ( lb <= ub ) { ranges . add ( new int [ ] { lb , ub } ) ; for ( int j = ranges . size ( ) - 2 ; j >= 0 ; -- j ) { int [ ] rangea = ( int [ ] ) ranges . elementAt ( j ) ; int lba = rangea [ 0 ] ; int uba = rangea [ 1 ] ; int [ ] rangeb = ( int [ ] ) ranges . elementAt ( j + 1 ) ; int lbb = rangeb [ 0 ] ; int ubb = rangeb [ 1 ] ; if ( Math . max ( lba , lbb ) - Math . min ( uba , ubb ) <= 1 ) { ranges . setElementAt ( new int [ ] { Math . min ( lba , lbb ) , Math . max ( uba , ubb ) } , j ) ; ranges . remove ( j + 1 ) ; } else if ( lba > lbb ) { ranges . setElementAt ( rangeb , j ) ; ranges . setElementAt ( rangea , j + 1 ) ; } else { break ; } } } }
accumulate the given range ( lb . . ub ) into the canonical array form into the given vector of int [ ] objects .
