-/*\r
- * Copyright (C) 2016, 2017 Roland Häder\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package org.mxchange.jcontactsbusiness.opening_times.dayofweek;\r
-\r
-import java.text.SimpleDateFormat;\r
-import java.util.Calendar;\r
-import java.util.Date;\r
-import java.util.GregorianCalendar;\r
-\r
-/**\r
- * An enumeration suitable for persisting\r
- * <p>\r
- * @author Roland Häder<roland@mxchange.org>\r
- */\r
-public enum DayOfTheWeek {\r
- SUNDAY {\r
- @Override\r
- public int toCalendar () {\r
- return Calendar.SUNDAY;\r
- }\r
-\r
- },\r
- MONDAY {\r
- @Override\r
- public int toCalendar () {\r
- return Calendar.MONDAY;\r
- }\r
- },\r
- TUESDAY {\r
- @Override\r
- public int toCalendar () {\r
- return Calendar.TUESDAY;\r
- }\r
- },\r
- WEDNESDAY {\r
- @Override\r
- public int toCalendar () {\r
- return Calendar.WEDNESDAY;\r
- }\r
- },\r
- THURSDAY {\r
- @Override\r
- public int toCalendar () {\r
- return Calendar.THURSDAY;\r
- }\r
- },\r
- FRIDAY {\r
- @Override\r
- public int toCalendar () {\r
- return Calendar.FRIDAY;\r
- }\r
- },\r
- SATURDAY {\r
- @Override\r
- public int toCalendar () {\r
- return Calendar.SATURDAY;\r
- }\r
- };\r
-\r
- public abstract int toCalendar ();\r
-\r
- public static DayOfTheWeek fromCalendarDay (final int day) {\r
-\r
- for (DayOfTheWeek dayOfWeek : DayOfTheWeek.values()) {\r
- if (dayOfWeek.toCalendar() == day) {\r
- return dayOfWeek;\r
- }\r
- }\r
-\r
- return null; // Consider throwing IllegalArgumentException\r
- }\r
-\r
- public static DayOfTheWeek getByDate (final Date date) {\r
- Calendar calendar = GregorianCalendar.getInstance();\r
- calendar.setTime(date);\r
- return fromCalendarDay(calendar.get(Calendar.DAY_OF_WEEK));\r
- }\r
-\r
- /*\r
- * Should return the localized day of the week\r
- */\r
- @Override\r
- public String toString () {\r
- Calendar c = new GregorianCalendar();\r
- c.set(Calendar.DAY_OF_WEEK, this.toCalendar());\r
- SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat\r
- .getInstance();\r
- sdf.applyPattern("EEEEEEEEEE"); //NOI18N\r
-\r
- return sdf.format(c.getTime());\r
- }\r
-\r
-}\r
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.opening_times.dayofweek;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+/**
+ * An enumeration suitable for persisting
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public enum DayOfTheWeek {
+ SUNDAY {
+ @Override
+ public int toCalendar () {
+ return Calendar.SUNDAY;
+ }
+
+ },
+ MONDAY {
+ @Override
+ public int toCalendar () {
+ return Calendar.MONDAY;
+ }
+ },
+ TUESDAY {
+ @Override
+ public int toCalendar () {
+ return Calendar.TUESDAY;
+ }
+ },
+ WEDNESDAY {
+ @Override
+ public int toCalendar () {
+ return Calendar.WEDNESDAY;
+ }
+ },
+ THURSDAY {
+ @Override
+ public int toCalendar () {
+ return Calendar.THURSDAY;
+ }
+ },
+ FRIDAY {
+ @Override
+ public int toCalendar () {
+ return Calendar.FRIDAY;
+ }
+ },
+ SATURDAY {
+ @Override
+ public int toCalendar () {
+ return Calendar.SATURDAY;
+ }
+ };
+
+ public abstract int toCalendar ();
+
+ public static DayOfTheWeek fromCalendarDay (final int day) {
+
+ for (DayOfTheWeek dayOfWeek : DayOfTheWeek.values()) {
+ if (dayOfWeek.toCalendar() == day) {
+ return dayOfWeek;
+ }
+ }
+
+ return null; // Consider throwing IllegalArgumentException
+ }
+
+ public static DayOfTheWeek getByDate (final Date date) {
+ Calendar calendar = GregorianCalendar.getInstance();
+ calendar.setTime(date);
+ return fromCalendarDay(calendar.get(Calendar.DAY_OF_WEEK));
+ }
+
+ /*
+ * Should return the localized day of the week
+ */
+ @Override
+ public String toString () {
+ Calendar c = new GregorianCalendar();
+ c.set(Calendar.DAY_OF_WEEK, this.toCalendar());
+ SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat
+ .getInstance();
+ sdf.applyPattern("EEEEEEEEEE"); //NOI18N
+
+ return sdf.format(c.getTime());
+ }
+
+}