]> git.mxchange.org Git - jcoreee.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 22 Jan 2023 00:34:27 +0000 (01:34 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 22 Jan 2023 00:34:27 +0000 (01:34 +0100)
- rewrote method, now with a local variable initialized with null. When the
  value from parameter 'day' cannot be solved, throw an IAE

src/org/mxchange/jcoreee/dates/DayOfTheWeek.java

index 059e387877a144551f266c3adccb16558b154647..d546c7b6e4f3a3dd25ebd8f0f590b6464fcbdb47 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jcoreee.dates;
 
+import java.text.MessageFormat;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
@@ -94,14 +95,27 @@ public enum DayOfTheWeek {
         * @return DateOfTheWeek instance
         */
        public static DayOfTheWeek fromCalendarDay (final int day) {
+               // Init with null instance
+               DayOfTheWeek dayOfTheWeek = null;
+
                // Walk through all values
                for (final DayOfTheWeek dayOfWeek : DayOfTheWeek.values()) {
+                       // Has the day being found?
                        if (dayOfWeek.toCalendar() == day) {
-                               return dayOfWeek;
+                               // Found it and break out from lopp
+                               dayOfTheWeek = dayOfWeek;
+                               break;
                        }
                }
 
-               return null; // Consider throwing IllegalArgumentException
+               // Is it null?
+               if (null == dayOfTheWeek) {
+                       // This means that the value of parameter 'day' is invalid
+                       throw new IllegalArgumentException(MessageFormat.format("Value for day='{0}' cannot be solved into any day of the week.", day));
+               }
+
+               // Return found instance
+               return dayOfTheWeek;
        }
 
        /**