class DoublesScheduleGenerator {

  public static double[] combineSets(final double[] set1, final double[] set2) {
    final int n1 = set1.length;
    final int n2 = set2.length;
    final int n = n1 + n2;
    final double[] set = new double[n];
    System.arraycopy(set1, 0, set, 0, n1);
    System.arraycopy(set2, 0, set, n1, n2);
    Arrays.sort(set);

    final double[] temp = new double[n];
    temp[0] = set[0];
    int pos = 0;
    for (int i = 1; i < n; i++) {
      if (different(temp[pos], set[i])) {
        temp[++pos] = set[i];
      }
    }

    final int resLength = pos + 1;
    if (resLength == n) {
      return temp; // everything was unique
    }

    final double[] res = new double[resLength];
    System.arraycopy(temp, 0, res, 0, resLength);
    return res;
  }

}