private int[] doUnion(int[] c2){
  int[] result=new int[chars.length + c2.length];
  int i=0;
  int j=0;
  int index=0;
  while (i < chars.length && j < c2.length) {
    int ub;
    if (chars[i] < c2[j]) {
      result[index++]=chars[i];
      ub=chars[++i];
    }
 else {
      result[index++]=c2[j];
      ub=c2[++j];
    }
    while (i % 2 == 1 || j % 2 == 1 || (i < chars.length && chars[i] <= ub + 1)) {
      while (i < chars.length && chars[i] <= ub + 1) {
        ++i;
      }
      if (i % 2 == 1) {
        ub=chars[i];
      }
 else       if (i > 0 && chars[i - 1] > ub) {
        ub=chars[i - 1];
      }
      while (j < c2.length && c2[j] <= ub + 1) {
        ++j;
      }
      if (j % 2 == 1) {
        ub=c2[j];
      }
 else       if (j > 0 && c2[j - 1] > ub) {
        ub=c2[j - 1];
      }
    }
    result[index++]=ub;
  }
  if (i < chars.length) {
    for (int k=i; k < chars.length; k++) {
      result[index++]=chars[k];
    }
  }
  if (j < c2.length) {
    for (int k=j; k < c2.length; k++) {
      result[index++]=c2[k];
    }
  }
  if (result.length > index) {
    int[] tmpbuf=new int[index];
    System.arraycopy(result,0,tmpbuf,0,index);
    return tmpbuf;
  }
  return result;
}

private int [ ] doUnion ( int [ ] c2 ) { int [ ] result = new int [ chars . length + c2 . length ] ; int i = 0 ; int j = 0 ; int index = 0 ; while ( i < chars . length && j < c2 . length ) { int ub ; if ( chars [ i ] < c2 [ j ] ) { result [ index ++ ] = chars [ i ] ; ub = chars [ ++ i ] ; } else { result [ index ++ ] = c2 [ j ] ; ub = c2 [ ++ j ] ; } while ( i % 2 == 1 || j % 2 == 1 || ( i < chars . length && chars [ i ] <= ub + 1 ) ) { while ( i < chars . length && chars [ i ] <= ub + 1 ) { ++ i ; } if ( i % 2 == 1 ) { ub = chars [ i ] ; } else if ( i > 0 && chars [ i - 1 ] > ub ) { ub = chars [ i - 1 ] ; } while ( j < c2 . length && c2 [ j ] <= ub + 1 ) { ++ j ; } if ( j % 2 == 1 ) { ub = c2 [ j ] ; } else if ( j > 0 && c2 [ j - 1 ] > ub ) { ub = c2 [ j - 1 ] ; } } result [ index ++ ] = ub ; } if ( i < chars . length ) { for ( int k = i ; k < chars . length ; k ++ ) { result [ index ++ ] = chars [ k ] ; } } if ( j < c2 . length ) { for ( int k = j ; k < c2 . length ; k ++ ) { result [ index ++ ] = c2 [ k ] ; } } if ( result . length > index ) { int [ ] tmpbuf = new int [ index ] ; System . arraycopy ( result , 0 , tmpbuf , 0 , index ) ; return tmpbuf ; } return result ; }
the actual implementation of the union functions
