*/
package org.mxchange.jcoreee.dates;
+import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
* @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;
}
/**