Beispiel #1
0
 /**
  * Creates {@code DayOfWeek} for given string.
  *
  * @param text the text to be parsed to {@code DayOfWeek}
  * @return the {@code DayOfWeek} created from text, null if {@code text} isn't equal to one of
  *     weekdays short names
  */
 public static DayOfWeek parse(String text) {
   for (DayOfWeek dayOfWeek : DayOfWeek.values()) {
     if (dayOfWeek.name().equalsIgnoreCase(text)
         || dayOfWeek.getShortName().equalsIgnoreCase(text)) {
       return dayOfWeek;
     }
   }
   return null;
 }
Beispiel #2
0
  /**
   * Returns {@code DayOfWeek} for given number.
   *
   * @param dayOfWeek the day of week as a number
   * @return the {@code DayOfWeek}
   * @throws IllegalArgumentException if given number isn't between 1 and 7
   */
  public static DayOfWeek getDayOfWeek(int dayOfWeek) {
    for (DayOfWeek day : DayOfWeek.values()) {
      if (day.getValue() == dayOfWeek) {
        return day;
      }
    }

    throw new IllegalArgumentException("Not a valid day");
  }