protected Date nextDay(Date d, int dayOfWeek) {
    date.setTimeInDays(d.toEpochDay());

    int currDayOfWeek = date.getDayOfWeek();

    int daysToAdd;
    if (currDayOfWeek < dayOfWeek) {
      daysToAdd = dayOfWeek - currDayOfWeek;
    } else {
      daysToAdd = 7 - currDayOfWeek + dayOfWeek;
    }

    date.setTimeInDays(date.toEpochDay() + daysToAdd);

    return date;
  }
GenericUDFNextDay.

Returns the first date which is later than start_date and named as indicated
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFNextDay.java