List of usage examples for java.util Calendar DAY_OF_WEEK_IN_MONTH
int DAY_OF_WEEK_IN_MONTH
To view the source code for java.util Calendar DAY_OF_WEEK_IN_MONTH.
Click Source Link
get
and set
indicating the ordinal number of the day of the week within the current month. From source file:com.gsr.myschool.server.service.impl.SettingsServiceImpl.java
@Override public void deleteDossiers(Boolean isPrepa) { DossierFilterDTO filter = new DossierFilterDTO(); filter.setStatus(DossierStatus.CREATED); List<Dossier> dossiers = dossierService.findAllDossiersByCriteria(filter, null, null).getDossiers(); for (Dossier dossier : dossiers) { // ne supprimer que les dossier cres non soumis des prepa Boolean skipCondition = isPrepa ? dossier.getFiliere() != null && dossier.getFiliere().getId().longValue() < GlobalParameters.PREPA_FILIERE_FROM : dossier.getFiliere() != null && dossier.getFiliere().getId().longValue() >= GlobalParameters.PREPA_FILIERE_FROM; if (skipCondition) continue; if (dossier.getCreateDate() != null) { Calendar date = new GregorianCalendar(); date.setTime(dossier.getCreateDate()); date.add(Calendar.DAY_OF_WEEK_IN_MONTH, 1); Calendar deleteAfterThis = new GregorianCalendar(); if (deleteAfterThis.after(date)) { try { inscriptionService.deleteInscription(dossier.getId()); } catch (Exception e) { e.printStackTrace(); }/* ww w . j a va 2 s . c o m*/ } } } }
From source file:com.netflix.simianarmy.basic.BasicCalendar.java
/** * Day of year./*from w w w. j a v a2 s .c om*/ * * @param year * the year * @param month * the month * @param dayOfWeek * the day of week * @param weekInMonth * the week in month * @return the day of the year */ private int dayOfYear(int year, int month, int dayOfWeek, int weekInMonth) { Calendar holiday = now(); holiday.set(Calendar.YEAR, year); holiday.set(Calendar.MONTH, month); holiday.set(Calendar.DAY_OF_WEEK, dayOfWeek); holiday.set(Calendar.DAY_OF_WEEK_IN_MONTH, weekInMonth); return holiday.get(Calendar.DAY_OF_YEAR); }
From source file:com.clustercontrol.calendar.util.CalendarUtil.java
/** * detailInfo?timeFrom,timeTo??0-24????//w ww. j av a 2 s .com * @param detailInfo * @param date ? * @return */ public static boolean isRunByDetailDate(CalendarDetailInfo detailInfo, Date date) { // from, to?0-24?????? long timezoneOffset = HinemosTime.getTimeZoneOffset(); long hour24 = 24 * 60 * 60 * 1000 - timezoneOffset; if (detailInfo.getTimeFrom() < (0 - timezoneOffset) || hour24 < (detailInfo.getTimeFrom())) { m_log.trace("detailInfo.getTimeFrom = " + detailInfo.getTimeFrom()); return false; } if ((detailInfo.getTimeTo()) < (0 - timezoneOffset) || hour24 < (detailInfo.getTimeTo())) { m_log.trace("detailInfo.getTimeTo = " + (detailInfo.getTimeTo())); return false; } //null? if (detailInfo.getMonth() == null) { m_log.warn("detailInfo.getMonth() is NULL"); return false; } //? Calendar detailCal = HinemosTime.getCalendarInstance(); //??? detailCal.setTime(new Date(date.getTime() - (long) detailInfo.getAfterday() * 24 * 3600 * 1000)); // int year = detailCal.get(Calendar.YEAR); // int month = detailCal.get(Calendar.MONTH) + 1; // int weekXth = detailCal.get(Calendar.DAY_OF_WEEK_IN_MONTH); // int weekday = detailCal.get(Calendar.DAY_OF_WEEK); // int dateNo = detailCal.get(Calendar.DATE); m_log.debug("detailCal=" + detailCal.getTime()); /** * */ //? ? ?????????0? if (detailInfo.getYear() != year && detailInfo.getYear() != 0) { m_log.trace("Year is false : Schdule year =" + detailInfo.getYear() + ", Current Year =" + year); return false; } m_log.trace("Year is TRUE : Schduler Year =" + detailInfo.getYear() + ", Current Year =" + year); /** * */ //? ? ?????????0? if (detailInfo.getMonth() != month && detailInfo.getMonth() != 0) { m_log.trace("Month is False : Schduler Month =" + detailInfo.getMonth() + ", Current Month =" + month); return false; } m_log.trace("Month is TRUE : Schduler Month =" + detailInfo.getMonth() + ", Current Month =" + month); /** * */ //null? if (detailInfo.getDayType() == null) { m_log.warn("detailInfo.getDayType() is NULL"); return false; } //??? ? ?????? //???? if (detailInfo.getDayType() == 0) { m_log.trace( "DateALL is TRUE : Schduler dayType=" + detailInfo.getDayType() + ", Current Date =" + dateNo); return true; } //??? else if (detailInfo.getDayType() == 1) { //null? if (detailInfo.getDayOfWeekInMonth() == null) { m_log.trace("detailInfo.getDayOfWeekInMonth() is NULL"); return false; } //null? if (detailInfo.getDayOfWeek() == null) { m_log.warn("detailInfo.getDayOfWeek() is NULL"); return false; } if (detailInfo.getDayOfWeekInMonth() == weekXth || detailInfo.getDayOfWeekInMonth() == 0) { m_log.trace("WeekXth is TRUE : Schduler Xth =" + detailInfo.getDayOfWeekInMonth() + ", Current weekXth =" + weekXth); if (detailInfo.getDayOfWeek() == weekday) { m_log.trace("Weekday is TRUE : Schduler Weekday =" + detailInfo.getDayOfWeek() + ", Current Weekday =" + weekday); return true; } } } // ??? else if (detailInfo.getDayType() == 2) { //null? if (detailInfo.getDate() == null) { m_log.trace("detailInfo.getDate() is NULL"); return false; } if (detailInfo.getDate() == dateNo) { m_log.trace("Date is TRUE : Schduler Date =" + detailInfo.getDate() + ", Current Date =" + dateNo); return true; } } //??? else if (detailInfo.getDayType() == 3) { //null? if (detailInfo.getCalPatternId() == null) { m_log.trace("detailInfo.getCalPatternId() is NULL"); return false; } m_log.trace("CalendarPatternID = " + detailInfo.getCalPatternId()); CalendarPatternInfo calPatternInfo = null; calPatternInfo = detailInfo.getCalPatternInfo(); if (calPatternInfo.isRun(year, month, dateNo)) { m_log.trace(year + "/" + month + "/" + dateNo); return true; } } return false; }
From source file:com.application.utils.FastDatePrinter.java
/** * <p>Returns a list of Rules given a pattern.</p> * * @return a {@code List} of Rule objects * @throws IllegalArgumentException if pattern is invalid *//*from ww w . ja v a 2 s. c o m*/ protected List<Rule> parsePattern() { final DateFormatSymbols symbols = new DateFormatSymbols(mLocale); final List<Rule> rules = new ArrayList<Rule>(); final String[] ERAs = symbols.getEras(); final String[] months = symbols.getMonths(); final String[] shortMonths = symbols.getShortMonths(); final String[] weekdays = symbols.getWeekdays(); final String[] shortWeekdays = symbols.getShortWeekdays(); final String[] AmPmStrings = symbols.getAmPmStrings(); final int length = mPattern.length(); final int[] indexRef = new int[1]; for (int i = 0; i < length; i++) { indexRef[0] = i; final String token = parseToken(mPattern, indexRef); i = indexRef[0]; final int tokenLen = token.length(); if (tokenLen == 0) { break; } Rule rule; final char c = token.charAt(0); switch (c) { case 'G': // era designator (text) rule = new TextField(Calendar.ERA, ERAs); break; case 'y': // year (number) if (tokenLen == 2) { rule = TwoDigitYearField.INSTANCE; } else { rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen); } break; case 'M': // month in year (text and number) if (tokenLen >= 4) { rule = new TextField(Calendar.MONTH, months); } else if (tokenLen == 3) { rule = new TextField(Calendar.MONTH, shortMonths); } else if (tokenLen == 2) { rule = TwoDigitMonthField.INSTANCE; } else { rule = UnpaddedMonthField.INSTANCE; } break; case 'd': // day in month (number) rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen); break; case 'h': // hour in am/pm (number, 1..12) rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen)); break; case 'H': // hour in day (number, 0..23) rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen); break; case 'm': // minute in hour (number) rule = selectNumberRule(Calendar.MINUTE, tokenLen); break; case 's': // second in minute (number) rule = selectNumberRule(Calendar.SECOND, tokenLen); break; case 'S': // millisecond (number) rule = selectNumberRule(Calendar.MILLISECOND, tokenLen); break; case 'E': // day in week (text) rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays); break; case 'D': // day in year (number) rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen); break; case 'F': // day of week in month (number) rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen); break; case 'w': // week in year (number) rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen); break; case 'W': // week in month (number) rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen); break; case 'a': // am/pm marker (text) rule = new TextField(Calendar.AM_PM, AmPmStrings); break; case 'k': // hour in day (1..24) rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen)); break; case 'K': // hour in am/pm (0..11) rule = selectNumberRule(Calendar.HOUR, tokenLen); break; case 'z': // time zone (text) if (tokenLen >= 4) { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG); } else { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT); } break; case 'Z': // time zone (value) if (tokenLen == 1) { rule = TimeZoneNumberRule.INSTANCE_NO_COLON; } else { rule = TimeZoneNumberRule.INSTANCE_COLON; } break; case '\'': // literal text final String sub = token.substring(1); if (sub.length() == 1) { rule = new CharacterLiteral(sub.charAt(0)); } else { rule = new StringLiteral(sub); } break; default: throw new IllegalArgumentException("Illegal pattern component: " + token); } rules.add(rule); } return rules; }
From source file:com.discovery.darchrow.date.DateUtil.java
/** * <code>week</code>./* www .j a v a 2s .co m*/ * * <pre> * 2015-7-29 14:08 * * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.FRIDAY) * return 2015-01-02 00:00:00.000 * * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.MONDAY) * return 2015-01-05 00:00:00.000 * </pre> * * @param date * * @param week * 1 ?2 3 4 5 6 7, ? {@link Calendar#SUNDAY}, {@link Calendar#MONDAY}, {@link Calendar#TUESDAY}, * {@link Calendar#WEDNESDAY}, {@link Calendar#THURSDAY}, {@link Calendar#FRIDAY}, {@link Calendar#SATURDAY} * @return the first week of specify date year * @see Calendar#SUNDAY * @see Calendar#MONDAY * @see Calendar#TUESDAY * @see Calendar#WEDNESDAY * @see Calendar#THURSDAY * @see Calendar#FRIDAY * @see Calendar#SATURDAY * @since 1.3.0 */ public static Date getFirstWeekOfSpecifyDateYear(Date date, int week) { Calendar calendar = toCalendar(date); calendar.clear(); calendar.set(Calendar.YEAR, getYear(date)); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1); calendar.set(Calendar.DAY_OF_WEEK, week); //DAY_OF_WEEK_IN_MONTH ? DAY_OF_WEEK ??? // WEEK_OF_MONTH WEEK_OF_YEAR ??? ? getFirstDayOfWeek() getMinimalDaysInFirstWeek() //DAY_OF_MONTH 1 7 DAY_OF_WEEK_IN_MONTH 1 //8 14 DAY_OF_WEEK_IN_MONTH 2? //DAY_OF_WEEK_IN_MONTH 0 DAY_OF_WEEK_IN_MONTH 1 ? //?? DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1 //????? // 31 DAY_OF_WEEK_IN_MONTH -1 DAY_OF_WEEK_IN_MONTH 5 DAY_OF_WEEK_IN_MONTH 4 ?? return CalendarUtil.toDate(calendar); }
From source file:com.sunchenbin.store.feilong.core.date.DateUtil.java
/** * <code>week</code>.//from ww w . j av a2 s. co m * * <pre> * 2015-7-29 14:08 * * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.FRIDAY) * return 2015-01-02 00:00:00.000 * * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.MONDAY) * return 2015-01-05 00:00:00.000 * </pre> * * @param date * * @param week * 1 ?2 3 4 5 6 7, ? {@link Calendar#SUNDAY}, {@link Calendar#MONDAY}, {@link Calendar#TUESDAY}, * {@link Calendar#WEDNESDAY}, {@link Calendar#THURSDAY}, {@link Calendar#FRIDAY}, {@link Calendar#SATURDAY} * @return the first week of specify date year * @see Calendar#SUNDAY * @see Calendar#MONDAY * @see Calendar#TUESDAY * @see Calendar#WEDNESDAY * @see Calendar#THURSDAY * @see Calendar#FRIDAY * @see Calendar#SATURDAY * @since 1.3.0 */ public static Date getFirstWeekOfSpecifyDateYear(Date date, int week) { Calendar calendar = toCalendar(date); calendar.clear(); calendar.set(Calendar.YEAR, getYear(date)); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1); calendar.set(Calendar.DAY_OF_WEEK, week); //DAY_OF_WEEK_IN_MONTH ? DAY_OF_WEEK ,??? // WEEK_OF_MONTH WEEK_OF_YEAR ??,? ? getFirstDayOfWeek() getMinimalDaysInFirstWeek() //DAY_OF_MONTH 1 7 DAY_OF_WEEK_IN_MONTH 1 //8 14 DAY_OF_WEEK_IN_MONTH 2,? //DAY_OF_WEEK_IN_MONTH 0 DAY_OF_WEEK_IN_MONTH 1 ? //?,,? DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1 //?,???? //, 31 , DAY_OF_WEEK_IN_MONTH -1 DAY_OF_WEEK_IN_MONTH 5 DAY_OF_WEEK_IN_MONTH 4 ?? return CalendarUtil.toDate(calendar); }
From source file:com.feilong.core.date.DateUtil.java
/** * <code>date</code> <code>week</code>. * //from w w w. j a v a 2s. co m * <pre class="code"> * 2015-7-29 14:08 * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.FRIDAY) =2015-01-02 00:00:00.000 * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.MONDAY) =2015-01-05 00:00:00.000 * </pre> * * <p> * {@link Calendar#DAY_OF_WEEK_IN_MONTH} ?. DAY_OF_WEEK ,???.<br> * {@link Calendar#WEEK_OF_MONTH} {@link Calendar#WEEK_OF_YEAR} ??,?? {@link Calendar#getFirstDayOfWeek()} * {@link Calendar#getMinimalDaysInFirstWeek()}. * </p> * * <p> * DAY_OF_MONTH 1 7 DAY_OF_WEEK_IN_MONTH 1;<br> * 8 14 DAY_OF_WEEK_IN_MONTH 2,?.<br> * DAY_OF_WEEK_IN_MONTH 0 DAY_OF_WEEK_IN_MONTH 1 ?.<br> * ?,,? DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1.<br> * ?,????.<br> * , 31 , DAY_OF_WEEK_IN_MONTH -1 DAY_OF_WEEK_IN_MONTH 5 DAY_OF_WEEK_IN_MONTH 4 ?? * </p> * * @param date * * @param week * 1 ?2 3 4 5 6 7, ? {@link Calendar#SUNDAY}, {@link Calendar#MONDAY}, {@link Calendar#TUESDAY}, * {@link Calendar#WEDNESDAY}, {@link Calendar#THURSDAY}, {@link Calendar#FRIDAY}, {@link Calendar#SATURDAY} * @return <code>date</code> null, {@link NullPointerException} * @see Calendar#SUNDAY * @see Calendar#MONDAY * @see Calendar#TUESDAY * @see Calendar#WEDNESDAY * @see Calendar#THURSDAY * @see Calendar#FRIDAY * @see Calendar#SATURDAY * @since 1.3.0 */ public static Date getFirstWeekOfSpecifyDateYear(Date date, int week) { Calendar calendar = toCalendar(date); calendar.clear(); calendar.set(Calendar.YEAR, getYear(date)); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1); calendar.set(Calendar.DAY_OF_WEEK, week); return CalendarUtil.toDate(calendar); }
From source file:com.akretion.kettle.steps.terminatooor.ScriptValuesAddedFunctions.java
public static Object getDayNumber(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext) { if (ArgList.length == 2) { try {/*from w ww . j av a 2 s.co m*/ if (isNull(ArgList[0])) return new Double(Double.NaN); else if (isUndefined(ArgList[0])) return undefinedValue; else { java.util.Date dIn = (java.util.Date) ArgList[0]; String strType = (String) ArgList[1]; Calendar startDate = Calendar.getInstance(); startDate.setTime(dIn); if (strType.toLowerCase().equals("y")) return new Double(startDate.get(Calendar.DAY_OF_YEAR)); else if (strType.toLowerCase().equals("m")) return new Double(startDate.get(Calendar.DAY_OF_MONTH)); else if (strType.toLowerCase().equals("w")) return new Double(startDate.get(Calendar.DAY_OF_WEEK)); else if (strType.toLowerCase().equals("wm")) return new Double(startDate.get(Calendar.DAY_OF_WEEK_IN_MONTH)); return new Double(startDate.get(Calendar.DAY_OF_YEAR)); } } catch (Exception e) { return null; //throw new RuntimeException(e.toString()); } } else { throw new RuntimeException("The function call getDayNumber requires 2 arguments."); } }
From source file:com.panet.imeta.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java
public static Object getDayNumber(Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext) { if (ArgList.length == 2) { try {// ww w . ja v a 2s .c o m if (isNull(ArgList[0])) return new Double(Double.NaN); else if (isUndefined(ArgList[0])) return Context.getUndefinedValue(); else { java.util.Date dIn = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class); String strType = Context.toString(ArgList[1]); Calendar startDate = Calendar.getInstance(); startDate.setTime(dIn); if (strType.toLowerCase().equals("y")) return new Double(startDate.get(Calendar.DAY_OF_YEAR)); else if (strType.toLowerCase().equals("m")) return new Double(startDate.get(Calendar.DAY_OF_MONTH)); else if (strType.toLowerCase().equals("w")) return new Double(startDate.get(Calendar.DAY_OF_WEEK)); else if (strType.toLowerCase().equals("wm")) return new Double(startDate.get(Calendar.DAY_OF_WEEK_IN_MONTH)); else if (strType.toLowerCase().equals("l")) return new Long(startDate.getTimeInMillis()); return new Double(startDate.get(Calendar.DAY_OF_YEAR)); } } catch (Exception e) { return null; //throw Context.reportRuntimeError(e.toString()); } } else { throw Context.reportRuntimeError("The function call getDayNumber requires 2 arguments."); } }
From source file:DateFormatUtils.java
/** * <p>Returns a list of Rules given a pattern.</p> * /*from w w w .j a v a 2 s.c o m*/ * @return a <code>List</code> of Rule objects * @throws IllegalArgumentException if pattern is invalid */ protected List parsePattern() { DateFormatSymbols symbols = new DateFormatSymbols(mLocale); List rules = new ArrayList(); String[] ERAs = symbols.getEras(); String[] months = symbols.getMonths(); String[] shortMonths = symbols.getShortMonths(); String[] weekdays = symbols.getWeekdays(); String[] shortWeekdays = symbols.getShortWeekdays(); String[] AmPmStrings = symbols.getAmPmStrings(); int length = mPattern.length(); int[] indexRef = new int[1]; for (int i = 0; i < length; i++) { indexRef[0] = i; String token = parseToken(mPattern, indexRef); i = indexRef[0]; int tokenLen = token.length(); if (tokenLen == 0) { break; } Rule rule; char c = token.charAt(0); switch (c) { case 'G': // era designator (text) rule = new TextField(Calendar.ERA, ERAs); break; case 'y': // year (number) if (tokenLen >= 4) { rule = selectNumberRule(Calendar.YEAR, tokenLen); } else { rule = TwoDigitYearField.INSTANCE; } break; case 'M': // month in year (text and number) if (tokenLen >= 4) { rule = new TextField(Calendar.MONTH, months); } else if (tokenLen == 3) { rule = new TextField(Calendar.MONTH, shortMonths); } else if (tokenLen == 2) { rule = TwoDigitMonthField.INSTANCE; } else { rule = UnpaddedMonthField.INSTANCE; } break; case 'd': // day in month (number) rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen); break; case 'h': // hour in am/pm (number, 1..12) rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen)); break; case 'H': // hour in day (number, 0..23) rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen); break; case 'm': // minute in hour (number) rule = selectNumberRule(Calendar.MINUTE, tokenLen); break; case 's': // second in minute (number) rule = selectNumberRule(Calendar.SECOND, tokenLen); break; case 'S': // millisecond (number) rule = selectNumberRule(Calendar.MILLISECOND, tokenLen); break; case 'E': // day in week (text) rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays); break; case 'D': // day in year (number) rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen); break; case 'F': // day of week in month (number) rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen); break; case 'w': // week in year (number) rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen); break; case 'W': // week in month (number) rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen); break; case 'a': // am/pm marker (text) rule = new TextField(Calendar.AM_PM, AmPmStrings); break; case 'k': // hour in day (1..24) rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen)); break; case 'K': // hour in am/pm (0..11) rule = selectNumberRule(Calendar.HOUR, tokenLen); break; case 'z': // time zone (text) if (tokenLen >= 4) { rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.LONG); } else { rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.SHORT); } break; case 'Z': // time zone (value) if (tokenLen == 1) { rule = TimeZoneNumberRule.INSTANCE_NO_COLON; } else { rule = TimeZoneNumberRule.INSTANCE_COLON; } break; case '\'': // literal text String sub = token.substring(1); if (sub.length() == 1) { rule = new CharacterLiteral(sub.charAt(0)); } else { rule = new StringLiteral(sub); } break; default: throw new IllegalArgumentException("Illegal pattern component: " + token); } rules.add(rule); } return rules; }