Example usage for java.util Calendar WEDNESDAY

List of usage examples for java.util Calendar WEDNESDAY

Introduction

In this page you can find the example usage for java.util Calendar WEDNESDAY.

Prototype

int WEDNESDAY

To view the source code for java.util Calendar WEDNESDAY.

Click Source Link

Document

Value of the #DAY_OF_WEEK field indicating Wednesday.

Usage

From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java

private static String[] mapShortWeekdaysStartingWithSunday(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getShortWeekdays();

    weekdays[0] = localeWeekdays[Calendar.SUNDAY];
    weekdays[1] = localeWeekdays[Calendar.MONDAY];
    weekdays[2] = localeWeekdays[Calendar.TUESDAY];
    weekdays[3] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[4] = localeWeekdays[Calendar.THURSDAY];
    weekdays[5] = localeWeekdays[Calendar.FRIDAY];
    weekdays[6] = localeWeekdays[Calendar.SATURDAY];

    return weekdays;
}

From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java

private static String[] mapShortWeekdaysStartingWithSaturday(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getShortWeekdays();

    weekdays[0] = localeWeekdays[Calendar.SATURDAY];
    weekdays[1] = localeWeekdays[Calendar.SUNDAY];
    weekdays[2] = localeWeekdays[Calendar.MONDAY];
    weekdays[3] = localeWeekdays[Calendar.TUESDAY];
    weekdays[4] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[5] = localeWeekdays[Calendar.THURSDAY];
    weekdays[6] = localeWeekdays[Calendar.FRIDAY];

    return weekdays;
}

From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java

private static String[] mapWeekdaysStartingWithSunday(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getWeekdays();

    weekdays[0] = localeWeekdays[Calendar.SUNDAY];
    weekdays[1] = localeWeekdays[Calendar.MONDAY];
    weekdays[2] = localeWeekdays[Calendar.TUESDAY];
    weekdays[3] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[4] = localeWeekdays[Calendar.THURSDAY];
    weekdays[5] = localeWeekdays[Calendar.FRIDAY];
    weekdays[6] = localeWeekdays[Calendar.SATURDAY];

    return weekdays;
}

From source file:com.icesoft.faces.component.selectinputdate.SelectInputDateRenderer.java

private static String[] mapWeekdays(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getShortWeekdays();

    weekdays[0] = localeWeekdays[Calendar.MONDAY];
    weekdays[1] = localeWeekdays[Calendar.TUESDAY];
    weekdays[2] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[3] = localeWeekdays[Calendar.THURSDAY];
    weekdays[4] = localeWeekdays[Calendar.FRIDAY];
    weekdays[5] = localeWeekdays[Calendar.SATURDAY];
    weekdays[6] = localeWeekdays[Calendar.SUNDAY];

    return weekdays;
}

From source file:com.icesoft.faces.component.selectinputdate.SelectInputDateRenderer.java

private static String[] mapWeekdaysLong(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getWeekdays();

    weekdays[0] = localeWeekdays[Calendar.MONDAY];
    weekdays[1] = localeWeekdays[Calendar.TUESDAY];
    weekdays[2] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[3] = localeWeekdays[Calendar.THURSDAY];
    weekdays[4] = localeWeekdays[Calendar.FRIDAY];
    weekdays[5] = localeWeekdays[Calendar.SATURDAY];
    weekdays[6] = localeWeekdays[Calendar.SUNDAY];

    return weekdays;
}

From source file:edu.jhuapl.openessence.controller.ReportController.java

private int getCalWeekStartDay(Map<String, ResolutionHandler> resolutionHandlers) {
    ResolutionHandler handler = resolutionHandlers.get("weekly");
    int startDay;
    if (handler == null || !(handler instanceof PgSqlWeeklyHandler)) {
        switch (Integer.parseInt(messageSource.getMessage("epidemiological.day.start",
                Integer.toString(DEFAULT_WEEK_STARTDAY)))) {
        case 0:/* w ww  .ja v  a  2s .c o m*/
            startDay = Calendar.SUNDAY;
            break;
        case 2:
            startDay = Calendar.TUESDAY;
            break;
        case 3:
            startDay = Calendar.WEDNESDAY;
            break;
        case 4:
            startDay = Calendar.THURSDAY;
            break;
        case 5:
            startDay = Calendar.FRIDAY;
            break;
        case 6:
            startDay = Calendar.SATURDAY;
            break;
        default:
            startDay = Calendar.MONDAY;
            break;
        }
        return startDay;
    }
    return ((PgSqlWeeklyHandler) handler).getCalWeekStartDay();
}

From source file:org.unitime.timetable.solver.studentsct.StudentSectioningDatabaseLoader.java

private String datePatternName(DatePattern dp, TimeLocation time) {
    if ("never".equals(iDatePatternFormat))
        return dp.getName();
    if ("extended".equals(iDatePatternFormat) && dp.getType() != DatePattern.sTypeExtended)
        return dp.getName();
    if ("alternate".equals(iDatePatternFormat) && dp.getType() == DatePattern.sTypeAlternate)
        return dp.getName();
    if (time.getWeekCode().isEmpty())
        return time.getDatePatternName();
    Calendar cal = Calendar.getInstance(Locale.US);
    cal.setLenient(true);/*from   ww  w . ja v  a  2 s .c  o m*/
    cal.setTime(iDatePatternFirstDate);
    int idx = time.getWeekCode().nextSetBit(0);
    cal.add(Calendar.DAY_OF_YEAR, idx);
    Date first = null;
    while (idx < time.getWeekCode().size() && first == null) {
        if (time.getWeekCode().get(idx)) {
            int dow = cal.get(Calendar.DAY_OF_WEEK);
            switch (dow) {
            case Calendar.MONDAY:
                if ((time.getDayCode() & DayCode.MON.getCode()) != 0)
                    first = cal.getTime();
                break;
            case Calendar.TUESDAY:
                if ((time.getDayCode() & DayCode.TUE.getCode()) != 0)
                    first = cal.getTime();
                break;
            case Calendar.WEDNESDAY:
                if ((time.getDayCode() & DayCode.WED.getCode()) != 0)
                    first = cal.getTime();
                break;
            case Calendar.THURSDAY:
                if ((time.getDayCode() & DayCode.THU.getCode()) != 0)
                    first = cal.getTime();
                break;
            case Calendar.FRIDAY:
                if ((time.getDayCode() & DayCode.FRI.getCode()) != 0)
                    first = cal.getTime();
                break;
            case Calendar.SATURDAY:
                if ((time.getDayCode() & DayCode.SAT.getCode()) != 0)
                    first = cal.getTime();
                break;
            case Calendar.SUNDAY:
                if ((time.getDayCode() & DayCode.SUN.getCode()) != 0)
                    first = cal.getTime();
                break;
            }
        }
        cal.add(Calendar.DAY_OF_YEAR, 1);
        idx++;
    }
    if (first == null)
        return time.getDatePatternName();
    cal.setTime(iDatePatternFirstDate);
    idx = time.getWeekCode().length() - 1;
    cal.add(Calendar.DAY_OF_YEAR, idx);
    Date last = null;
    while (idx >= 0 && last == null) {
        if (time.getWeekCode().get(idx)) {
            int dow = cal.get(Calendar.DAY_OF_WEEK);
            switch (dow) {
            case Calendar.MONDAY:
                if ((time.getDayCode() & DayCode.MON.getCode()) != 0)
                    last = cal.getTime();
                break;
            case Calendar.TUESDAY:
                if ((time.getDayCode() & DayCode.TUE.getCode()) != 0)
                    last = cal.getTime();
                break;
            case Calendar.WEDNESDAY:
                if ((time.getDayCode() & DayCode.WED.getCode()) != 0)
                    last = cal.getTime();
                break;
            case Calendar.THURSDAY:
                if ((time.getDayCode() & DayCode.THU.getCode()) != 0)
                    last = cal.getTime();
                break;
            case Calendar.FRIDAY:
                if ((time.getDayCode() & DayCode.FRI.getCode()) != 0)
                    last = cal.getTime();
                break;
            case Calendar.SATURDAY:
                if ((time.getDayCode() & DayCode.SAT.getCode()) != 0)
                    last = cal.getTime();
                break;
            case Calendar.SUNDAY:
                if ((time.getDayCode() & DayCode.SUN.getCode()) != 0)
                    last = cal.getTime();
                break;
            }
        }
        cal.add(Calendar.DAY_OF_YEAR, -1);
        idx--;
    }
    if (last == null)
        return time.getDatePatternName();
    Formats.Format<Date> dpf = Formats.getDateFormat(Formats.Pattern.DATE_PATTERN);
    return dpf.format(first) + (first.equals(last) ? "" : " - " + dpf.format(last));
}

From source file:lineage2.gameserver.model.Player.java

/**
 * Method restoreVitality./*from ww  w .ja va 2s  .  co  m*/
 */
public void restoreVitality() {
    Calendar temp = Calendar.getInstance();
    temp.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
    temp.set(Calendar.HOUR_OF_DAY, 6);
    temp.set(Calendar.MINUTE, 30);
    temp.set(Calendar.SECOND, 0);
    temp.set(Calendar.MILLISECOND, 0);
    if ((_lastAccess < (temp.getTimeInMillis() / 1000))
            && (System.currentTimeMillis() > temp.getTimeInMillis())) {
        setVitality(Config.MAX_VITALITY);
        return;
    }
    Connection con = null;
    PreparedStatement statement = null;
    ResultSet rset = null;
    try {
        con = DatabaseFactory.getInstance().getConnection();
        statement = con.prepareStatement("SELECT `points` FROM `vitality_points` WHERE `account_name`=?");
        statement.setString(1, getAccountName());
        rset = statement.executeQuery();
        if (rset.next()) {
            setVitality(rset.getInt(1));
        } else {
            setVitality(Config.MAX_VITALITY);
            DbUtils.closeQuietly(con, statement);
            con = DatabaseFactory.getInstance().getConnection();
            statement = con.prepareStatement(
                    "INSERT IGNORE INTO `vitality_points` (account_name, points) VALUES (?,?)");
            statement.setString(1, getAccountName());
            statement.setInt(2, Config.MAX_VITALITY);
            statement.execute();
        }
    } catch (SQLException e) {
        _log.error("Could not restore vitality points", e);
    } finally {
        DbUtils.closeQuietly(con, statement, rset);
    }
}

From source file:com.aimluck.eip.schedule.util.ScheduleUtils.java

public static boolean isDuplicateFacilitySchedule(EipTSchedule schedule, List<Integer> facilityIdList,
        Integer _old_scheduleid, Date _old_viewDate) {
    /*  *//*w  ww . j  a v a 2s.  c o  m*/
    GregorianCalendar cald = new GregorianCalendar();

    boolean result = false;
    {

        Date start_date;
        Date end_date;
        String repeat_pattern;
        String repeat_type;
        String repeat_week = null;
        boolean week_0;
        boolean week_1;
        boolean week_2;
        boolean week_3;
        boolean week_4;
        boolean week_5;
        boolean week_6;
        boolean day_of_week_in_month_1;
        boolean day_of_week_in_month_2;
        boolean day_of_week_in_month_3;
        boolean day_of_week_in_month_4;
        boolean day_of_week_in_month_5;
        boolean[] day_of_week_in_month_array = new boolean[5];
        String limit_flag;
        int month_day = -1;
        int year_month = -1;
        int year_day = -1;
        Integer db_scheduleid = null;
        boolean[] week_array = new boolean[7];
        boolean unlimited_repeat = false;
        try {
            start_date = schedule.getStartDate();

            end_date = schedule.getEndDate();

            repeat_pattern = schedule.getRepeatPattern();

            repeat_type = repeat_pattern.substring(0, 1);

            day_of_week_in_month_1 = repeat_pattern.matches("W.......1.?");

            day_of_week_in_month_2 = repeat_pattern.matches("W.......2.?");

            day_of_week_in_month_3 = repeat_pattern.matches("W.......3.?");

            day_of_week_in_month_4 = repeat_pattern.matches("W.......4.?");

            day_of_week_in_month_5 = repeat_pattern.matches("W.......5.?");

            if (repeat_type.equals("W")) {
                if (repeat_pattern.length() == 9) {
                    repeat_week = "0";
                    day_of_week_in_month_1 = true;
                    day_of_week_in_month_2 = true;
                    day_of_week_in_month_3 = true;
                    day_of_week_in_month_4 = true;
                    day_of_week_in_month_5 = true;
                } else {
                    repeat_week = repeat_pattern.substring(8, 9);
                }
            }

            limit_flag = repeat_pattern.substring(repeat_pattern.length() - 1);

            week_0 = repeat_pattern.matches("W1........?");

            week_1 = repeat_pattern.matches("W.1.......?");

            week_2 = repeat_pattern.matches("W..1......?");

            week_3 = repeat_pattern.matches("W...1.....?");

            week_4 = repeat_pattern.matches("W....1....?");

            week_5 = repeat_pattern.matches("W.....1...?");

            week_6 = repeat_pattern.matches("W......1..?");

            if (repeat_pattern.startsWith("M")) {
                month_day = Integer.parseInt(repeat_pattern.substring(1, 3));
            }

            if (repeat_pattern.startsWith("Y")) {
                year_month = Integer.parseInt(repeat_pattern.substring(1, 3));
                year_day = Integer.parseInt(repeat_pattern.substring(3, 5));
            }
            // ???1??????
            if (repeat_pattern.startsWith("N")) {
                Calendar cal = Calendar.getInstance();
                cal.setTime(start_date);
                int dow = cal.get(Calendar.DAY_OF_WEEK);
                week_0 = (dow == Calendar.SUNDAY);
                week_1 = (dow == Calendar.MONDAY);
                week_2 = (dow == Calendar.TUESDAY);
                week_3 = (dow == Calendar.WEDNESDAY);
                week_4 = (dow == Calendar.THURSDAY);
                week_5 = (dow == Calendar.FRIDAY);
                week_6 = (dow == Calendar.SATURDAY);
                month_day = cal.get(Calendar.DAY_OF_MONTH);
                int dowim = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
                day_of_week_in_month_1 = (dowim == 1);
                day_of_week_in_month_2 = (dowim == 2);
                day_of_week_in_month_3 = (dowim == 3);
                day_of_week_in_month_4 = (dowim == 4);
                day_of_week_in_month_5 = (dowim == 5);
                year_month = cal.get(Calendar.MONTH) + 1;
                year_day = cal.get(Calendar.DAY_OF_MONTH);
            } else if (repeat_pattern.endsWith("N")) {
                unlimited_repeat = true;
            }

            week_array[0] = week_0;
            week_array[1] = week_1;
            week_array[2] = week_2;
            week_array[3] = week_3;
            week_array[4] = week_4;
            week_array[5] = week_5;
            week_array[6] = week_6;

            day_of_week_in_month_array[0] = day_of_week_in_month_1;
            day_of_week_in_month_array[1] = day_of_week_in_month_2;
            day_of_week_in_month_array[2] = day_of_week_in_month_3;
            day_of_week_in_month_array[3] = day_of_week_in_month_4;
            day_of_week_in_month_array[4] = day_of_week_in_month_5;

        } catch (RuntimeException e) {
            logger.error("schedule", e);
            return false;
        } catch (Exception e) {
            logger.error("schedule", e);
            return false;
        }

        if (repeat_type.equals("S")) {
            // ??0:00:00?????23:59:59??
            Calendar cal = Calendar.getInstance();
            cal.setTime(end_date);
            cal.add(Calendar.DATE, 1);
            cal.add(Calendar.MINUTE, -1);
            end_date = cal.getTime();
        }

        // ???
        if (facilityIdList.size() > 0) {//
            List<Integer> fids = facilityIdList;
            SelectQuery<EipTScheduleMap> fquery = Database.query(EipTScheduleMap.class);
            Expression fexp1 = ExpressionFactory.inExp(EipTScheduleMap.USER_ID_PROPERTY, fids);
            fquery.setQualifier(fexp1);

            Expression fexp2 = ExpressionFactory.matchExp(EipTScheduleMap.TYPE_PROPERTY,
                    ScheduleUtils.SCHEDULEMAP_TYPE_FACILITY);
            fquery.andQualifier(fexp2);

            Expression oneexp = null;// 1
            Expression spanexp = null;// 
            Expression rdexp = null;// 
            Expression rwexp = null;// 
            Expression rwexp2 = null;
            // Expression rwlexp = null;
            Expression rmexp = null;// 
            Expression ryexp = null;

            { // ?
                Expression exp100 = ExpressionFactory.matchExp(
                        EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY,
                        "N");

                try {
                    if (!unlimited_repeat) {
                        Expression exp101 = ExpressionFactory.lessOrEqualExp(
                                EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.START_DATE_PROPERTY,
                                end_date);// EipTSchedule.START_DATE_PROPERTY <= end_date
                        Expression exp102 = ExpressionFactory.greaterExp(
                                EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.END_DATE_PROPERTY,
                                start_date);// EipTSchedule.END_DATE_PROPERTY > start_date

                        oneexp = exp100.andExp(exp101.andExp(exp102));

                    } else {
                        oneexp = exp100;
                    }
                } catch (Exception e) {

                }
            }

            { // ?
                Expression exp200 = ExpressionFactory.matchExp(
                        EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY,
                        "S");

                try {
                    if (!unlimited_repeat) {
                        // ??00:00??????
                        Calendar cal_end = Calendar.getInstance();
                        cal_end.setTime(end_date);
                        cal_end = DateUtils.truncate(cal_end, Calendar.DAY_OF_MONTH);
                        Expression exp201 = ExpressionFactory.lessOrEqualExp(
                                EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.START_DATE_PROPERTY,
                                cal_end.getTime());
                        // EipTSchedule.START_DATE_PROPERTY <= end_date
                        Calendar cal_start = Calendar.getInstance();
                        cal_start.setTime(start_date);
                        cal_start = DateUtils.truncate(cal_start, Calendar.DAY_OF_MONTH);
                        Expression exp202 = ExpressionFactory.greaterOrEqualExp(
                                EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.END_DATE_PROPERTY,
                                cal_start.getTime());
                        // EipTSchedule.END_DATE_PROPERTY >= start_date

                        spanexp = exp200.andExp(exp201.andExp(exp202));

                    } else {
                        spanexp = exp200;
                    }
                } catch (Exception e) {

                }
            }

            { // ??
              // char lim = 'N';
                if ("ON".equals(limit_flag)) {
                    // lim = 'L';
                }

                { // "D".equals(repeat_type.getValue())
                    Expression dexp01 = ExpressionFactory.likeExp(
                            EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY,
                            "D_");
                    rdexp = dexp01;
                }

                { // "W".equals(repeat_type.getValue())
                    Expression wexp = null;
                    List<Expression> wexps = new ArrayList<Expression>();
                    if (week_0 == true) {
                        wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W1_______");
                        wexps.add(wexp);
                    }
                    if (week_1 == true) {
                        wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_1______");
                        wexps.add(wexp);
                    }
                    if (week_2 == true) {
                        wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W__1_____");
                        wexps.add(wexp);
                    }
                    if (week_3 == true) {
                        wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W___1____");
                        wexps.add(wexp);
                    }
                    if (week_4 == true) {
                        wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W____1___");
                        wexps.add(wexp);
                    }
                    if (week_5 == true) {
                        wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_____1__");
                        wexps.add(wexp);
                    }
                    if (week_6 == true) {
                        wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W______1_");
                        wexps.add(wexp);
                    }
                    if (wexps.size() > 0) {
                        rwexp = wexps.get(0);
                        int wexpssize = wexps.size();
                        for (int k = 1; k < wexpssize; k++) {
                            rwexp = rwexp.orExp(wexps.get(k));
                        }
                    } else {
                        rwexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W________");
                    }
                }
                {
                    Expression wexp2 = null;
                    List<Expression> wexps2 = new ArrayList<Expression>();
                    Expression wnexp = null;
                    List<Expression> wnexp2 = new ArrayList<Expression>();

                    if (week_0 == true) {
                        wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W1________");
                        wexps2.add(wexp2);
                    }
                    if (week_1 == true) {
                        wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_1_______");
                        wexps2.add(wexp2);
                    }
                    if (week_2 == true) {
                        wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W__1______");
                        wexps2.add(wexp2);
                    }
                    if (week_3 == true) {
                        wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W___1_____");
                        wexps2.add(wexp2);
                    }
                    if (week_4 == true) {
                        wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W____1____");
                        wexps2.add(wexp2);
                    }
                    if (week_5 == true) {
                        wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_____1___");
                        wexps2.add(wexp2);
                    }
                    if (week_6 == true) {
                        wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W______1__");
                        wexps2.add(wexp2);
                    }
                    if (repeat_week != null && repeat_week.equals("1") || day_of_week_in_month_1) {
                        wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______1_");
                        wnexp2.add(wnexp);
                    }
                    if (repeat_week != null && repeat_week.equals("2") || day_of_week_in_month_2) {
                        wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______2_");
                        wnexp2.add(wnexp);
                    }
                    if (repeat_week != null && repeat_week.equals("3") || day_of_week_in_month_3) {
                        wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______3_");
                        wnexp2.add(wnexp);
                    }
                    if (repeat_week != null && repeat_week.equals("4") || day_of_week_in_month_4) {
                        wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______4_");
                        wnexp2.add(wnexp);
                    }
                    if (repeat_week != null && repeat_week.equals("5") || day_of_week_in_month_5) {
                        wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______5_");
                        wnexp2.add(wnexp);
                    }
                    if (wexps2.size() > 0 && wnexp2.size() > 0) {
                        for (int k = 0; k < wexps2.size(); k++) {
                            for (int l = 0; l < wnexp2.size(); l++) {
                                if (k == 0 && l == 0) {
                                    rwexp2 = wexps2.get(k).andExp(wnexp2.get(l));
                                } else {
                                    rwexp2 = rwexp2.orExp(wexps2.get(k).andExp(wnexp2.get(l)));
                                }
                            }
                        }
                    } else {
                        rwexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_________");
                    }

                }

                { // "M".equals(repeat_type.getValue())
                    if (month_day > 0) { // ????????
                        DecimalFormat exF = new DecimalFormat("00");
                        String md_str = exF.format(month_day);
                        rmexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "M" + md_str + "_");

                    } else if (year_day > 0 && year_month > 0) { // ??
                        DecimalFormat exG = new DecimalFormat("00");
                        String yd_str = exG.format(year_day);
                        rmexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "M" + yd_str + "_");
                    } else {
                        rmexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "M___");
                    }
                }

                { // "Y".equals(repeat_type.getValue())
                    if (year_day > 0 && year_month > 0) { // ????????
                        DecimalFormat exG = new DecimalFormat("00");
                        String ym_str = exG.format(year_month);
                        String yd_str = exG.format(year_day);

                        ryexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "Y" + ym_str + yd_str + "_");
                    } else if (month_day > 0) { // ??
                        DecimalFormat exF = new DecimalFormat("00");
                        String md_str = exF.format(month_day);
                        ryexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "Y__" + md_str + "_");
                    } else {
                        ryexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "."
                                + EipTSchedule.REPEAT_PATTERN_PROPERTY, "Y_____");
                    }
                }

                Expression repeatexp = oneexp;
                if (rdexp != null) {
                    repeatexp = repeatexp.orExp(rdexp);
                }
                if (rwexp != null) {
                    repeatexp = repeatexp.orExp(rwexp);
                }
                if (rwexp2 != null) {
                    repeatexp = repeatexp.orExp(rwexp2);
                }
                if (rmexp != null) {
                    repeatexp = repeatexp.orExp(rmexp);
                }
                if (spanexp != null) {
                    repeatexp = repeatexp.orExp(spanexp);
                }
                if (ryexp != null) {
                    repeatexp = repeatexp.orExp(ryexp);
                }
                fquery.andQualifier(repeatexp);
            }

            db_scheduleid = schedule.getScheduleId();
            if (db_scheduleid != null && db_scheduleid >= 0) {
                Expression exp00 = ExpressionFactory.noMatchDbExp(
                        EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.SCHEDULE_ID_PK_COLUMN,
                        db_scheduleid);
                fquery.andQualifier(exp00);
            }

            fquery.distinct(true);
            List<EipTScheduleMap> f_list = fquery.fetchList();
            if (f_list != null && f_list.size() > 0) {
                // ?????
                boolean existFacility = false;
                int f_list_size = f_list.size();
                for (int i = 0; i < f_list_size; i++) {
                    EipTScheduleMap map = f_list.get(i);

                    Date dbStartDate = map.getEipTSchedule().getStartDate();
                    Date dbEndDate = map.getEipTSchedule().getEndDate();

                    boolean containtsRs = false;
                    // ??????
                    String ptn = map.getEipTSchedule().getRepeatPattern();
                    if (ptn.charAt(0) == 'S') { // 
                        try {
                            // ??0:00:00?????23:59:59??
                            Calendar cal = Calendar.getInstance();
                            cal.setTime(dbEndDate);
                            cal.add(Calendar.DATE, 1);
                            cal.add(Calendar.MINUTE, -1);
                            dbEndDate = cal.getTime();

                            if ((end_date.after(dbStartDate) && start_date.before(dbEndDate))
                                    || unlimited_repeat) {
                                containtsRs = true;
                            }
                        } catch (Exception e) {
                            containtsRs = false;
                        }
                    } else if (ptn.charAt(0) == 'N') { // ?
                        if ("D".equals(repeat_type) || "N".equals(repeat_type)) { //  or
                            // ?
                            try {
                                if ((dbStartDate.before(end_date) && dbEndDate.after(start_date))
                                        || unlimited_repeat) {
                                    containtsRs = true;
                                }
                            } catch (Exception e) {
                                containtsRs = false;
                            }
                        } else {
                            if ((dbStartDate.before(end_date) && dbEndDate.after(start_date))
                                    || unlimited_repeat) {
                                containtsRs = true;
                            }
                        }
                    } else if (ptn.charAt(0) == 'D') {// 
                        if (ptn.charAt(1) == 'L') {
                            try {
                                if ((dbStartDate.before(end_date) && dbEndDate.after(start_date))
                                        || unlimited_repeat) {
                                    containtsRs = true;
                                }
                            } catch (Exception e) {
                                containtsRs = false;
                            }
                        } else {
                            containtsRs = true;
                        }
                    } else if (ptn.charAt(0) == 'W') {
                        if (ptn.length() == 9) {
                            if (ptn.charAt(8) == 'L') {
                                try {
                                    if ((dbStartDate.before(end_date) && dbEndDate.after(start_date))
                                            || unlimited_repeat) {
                                        containtsRs = true;
                                    }
                                } catch (Exception e) {
                                    containtsRs = false;
                                }
                            } else {
                                containtsRs = true;
                            }
                        } else if (ptn.length() == 10) {
                            if (ptn.charAt(9) == 'L') {
                                try {
                                    if ((dbStartDate.before(end_date) && dbEndDate.after(start_date))
                                            || unlimited_repeat) {
                                        containtsRs = true;
                                    }
                                } catch (Exception e) {
                                    containtsRs = false;
                                }
                            } else {
                                containtsRs = true;
                            }
                        }
                    } else if (ptn.charAt(0) == 'M') {
                        if (ptn.charAt(3) == 'L') {
                            try {
                                if ((dbStartDate.before(end_date) && dbEndDate.after(start_date))
                                        || unlimited_repeat) {
                                    containtsRs = true;
                                }
                            } catch (Exception e) {
                                containtsRs = false;
                            }
                        } else {
                            containtsRs = true;
                        }
                    } else if (ptn.charAt(0) == 'Y') {
                        if (ptn.charAt(5) == 'L') {
                            try {
                                if ((dbStartDate.before(end_date) && dbEndDate.after(start_date))
                                        || unlimited_repeat) {
                                    containtsRs = true;
                                }
                            } catch (Exception e) {
                                containtsRs = false;
                            }
                        } else {
                            containtsRs = true;
                        }
                    } else {
                        containtsRs = true;
                    }

                    if (containtsRs) {
                        /* ?????? */
                        int ss_flg = ScheduleUtils.compareTime(start_date, dbEndDate);
                        int se_flg = ScheduleUtils.compareTime(end_date, dbStartDate);
                        if (ss_flg > 0 && se_flg < 0) {
                            /* ???????????? */
                            if (!"N".equals(ptn) && ptn.endsWith("N") && unlimited_repeat) {// ?(?????&&???)&&????
                                existFacility = true;
                            } else {
                                Date _start_date = null;
                                Date _end_date = null;

                                if (!"N".equals(ptn) && ptn.endsWith("N") && !unlimited_repeat) {// ?(??&&???)&&???
                                    _start_date = (Date) start_date.clone();
                                    _end_date = (Date) end_date.clone();
                                } else if (("N".equals(ptn) || !ptn.endsWith("N")) && unlimited_repeat) {// ?(?||??)&&????
                                    _start_date = (Date) dbStartDate.clone();
                                    _end_date = (Date) dbEndDate.clone();
                                } else if (("N".equals(ptn) || !ptn.endsWith("N")) && !unlimited_repeat) {// ?(?||??)&&???

                                    if (dbStartDate.after(start_date)) {
                                        _start_date = (Date) dbStartDate.clone();
                                    } else {
                                        _start_date = (Date) start_date.clone();
                                    }

                                    if (dbEndDate.before(end_date)) {
                                        _end_date = (Date) dbEndDate.clone();
                                    } else {
                                        _end_date = (Date) end_date.clone();
                                    }

                                }

                                if ((_start_date == null) || (_end_date == null)) {
                                    continue;
                                }

                                /* ??? */
                                Expression dexp1 = ExpressionFactory.matchExp(EipTSchedule.NAME_PROPERTY,
                                        "dummy");// 

                                Expression dexp2 = ExpressionFactory.matchExp(EipTSchedule.PARENT_ID_PROPERTY,
                                        map.getScheduleId());

                                if (db_scheduleid != null) {
                                    Expression dexp21 = ExpressionFactory
                                            .matchExp(EipTSchedule.PARENT_ID_PROPERTY, db_scheduleid);
                                    dexp2 = dexp2.orExp(dexp21);
                                }
                                Expression dexp3 = null;

                                cald.setTime(_start_date);
                                cald.set(Calendar.MILLISECOND, 0);
                                cald.set(Calendar.SECOND, 0);
                                cald.set(Calendar.MINUTE, 0);
                                cald.set(Calendar.HOUR_OF_DAY, 0);
                                Date ddate = cald.getTime();// _start_date?
                                List<EipTSchedule> temp = null;

                                if ("N".equals(repeat_pattern)) {
                                    /* ?????????????? */
                                    if ((_old_scheduleid != null) && (_old_viewDate != null)) {
                                        if ((_old_scheduleid.intValue() == map.getScheduleId().intValue())
                                                && compareToDate(_start_date, _old_viewDate) == 0) {
                                            continue;
                                        }
                                    }

                                    try {
                                        dexp3 = ExpressionFactory.matchExp(EipTSchedule.START_DATE_PROPERTY,
                                                ddate);
                                        temp = Database
                                                .query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3))
                                                .fetchList();
                                        if (temp == null || temp.size() <= 0) {
                                            existFacility = true;
                                            break;
                                        }
                                    } catch (Exception e) {
                                        logger.error("[DuplicateFacilityCheck]: ", e);
                                        existFacility = true;
                                        break;
                                    }
                                } else if (repeat_pattern.startsWith("D")) {
                                    while (!ddate.after(_end_date)) {
                                        if (matchDay(cald, ptn)) {
                                            try {
                                                dexp3 = ExpressionFactory
                                                        .matchExp(EipTSchedule.START_DATE_PROPERTY, ddate);
                                                temp = Database.query(EipTSchedule.class,
                                                        dexp1.andExp(dexp2).andExp(dexp3)).fetchList();
                                                if (temp == null || temp.size() <= 0) {
                                                    existFacility = true;
                                                    break;
                                                }
                                            } catch (Exception e) {
                                                logger.error("[DuplicateFacilityCheck]: ", e);
                                                existFacility = true;
                                                break;
                                            }
                                        }
                                        cald.add(Calendar.DATE, 1);
                                        ddate = cald.getTime();
                                    }
                                } else if (repeat_pattern.startsWith("S")) {
                                    while (!ddate.after(_end_date)) {
                                        try {
                                            dexp3 = ExpressionFactory.matchExp(EipTSchedule.START_DATE_PROPERTY,
                                                    ddate);
                                            temp = Database.query(EipTSchedule.class,
                                                    dexp1.andExp(dexp2).andExp(dexp3)).fetchList();
                                            if (temp == null || temp.size() <= 0) {
                                                existFacility = true;
                                                break;
                                            }
                                        } catch (Exception e) {
                                            logger.error("[DuplicateFacilityCheck]: ", e);
                                            existFacility = true;
                                            break;
                                        }
                                        cald.add(Calendar.DATE, 1);
                                        ddate = cald.getTime();
                                    }
                                } else if (repeat_pattern.startsWith("W")) {
                                    /* ? */
                                    int wlen = week_array.length;
                                    int wlen2 = day_of_week_in_month_array.length;
                                    if (wlen < 1 || wlen2 < 1) {
                                        continue;
                                    }
                                    int k;
                                    int l;
                                    while (!ddate.after(_end_date)) {
                                        k = (cald.get(Calendar.DAY_OF_WEEK) - 1) % wlen;
                                        l = (cald.get(Calendar.DAY_OF_WEEK_IN_MONTH) - 1) % wlen2;
                                        if ((week_array[k] == true) && (day_of_week_in_month_array[l] == true)
                                                && matchDay(cald, ptn)) {
                                            try {
                                                dexp3 = ExpressionFactory
                                                        .matchExp(EipTSchedule.START_DATE_PROPERTY, ddate);
                                                temp = Database.query(EipTSchedule.class,
                                                        dexp1.andExp(dexp2).andExp(dexp3)).fetchList();// SQL
                                                if (temp == null || temp.size() <= 0) {
                                                    existFacility = true;// true????
                                                    break;
                                                }
                                            } catch (Exception e) {
                                                logger.error("[DuplicateFacilityCheck]: ", e);
                                                existFacility = true;
                                                break;
                                            }
                                        }
                                        cald.add(Calendar.DATE, 1);
                                        ddate = cald.getTime();
                                    }
                                } else if (repeat_pattern.startsWith("M")) {
                                    /* ?? */
                                    cald.setTime(dbStartDate);
                                    cald.set(Calendar.MILLISECOND, 0);
                                    cald.set(Calendar.SECOND, 0);
                                    cald.set(Calendar.MINUTE, 0);
                                    cald.set(Calendar.HOUR_OF_DAY, 0);

                                    if (month_day > 0) {
                                        cald.set(Calendar.DAY_OF_MONTH, month_day);
                                    } else {
                                        continue;
                                    }
                                    Date tmp_date = cald.getTime();
                                    while (tmp_date.before(ddate)) {
                                        cald.add(Calendar.MONTH, 1);
                                        /* ???????????????? */
                                        while (month_day > cald.getActualMaximum(Calendar.DAY_OF_MONTH)) {
                                            cald.add(Calendar.MONTH, 1);
                                            cald.set(Calendar.DAY_OF_MONTH, month_day);
                                            if (tmp_date.before(tmp_date)) {
                                                break;
                                            }
                                        }
                                        tmp_date = cald.getTime();
                                    }
                                    ddate = tmp_date;
                                    /*  */
                                    while (!ddate.after(_end_date)) {
                                        if (matchDay(cald, ptn)) {
                                            try {
                                                dexp3 = ExpressionFactory
                                                        .matchExp(EipTSchedule.START_DATE_PROPERTY, ddate);
                                                temp = Database.query(EipTSchedule.class,
                                                        dexp1.andExp(dexp2).andExp(dexp3)).fetchList();
                                                if (temp == null || temp.size() <= 0) {
                                                    existFacility = true;
                                                    break;
                                                }

                                            } catch (Exception e) {
                                                logger.error("[DuplicateFacilityCheck]: ", e);
                                                existFacility = true;
                                                break;
                                            }
                                        }
                                        cald.add(Calendar.MONTH, 1);
                                        /* ???????????????? */
                                        while (month_day > cald.getActualMaximum(Calendar.DAY_OF_MONTH)) {
                                            cald.add(Calendar.MONTH, 1);
                                            cald.set(Calendar.DAY_OF_MONTH, month_day);
                                            if (!ddate.after(_end_date)) {
                                                break;
                                            }
                                        }
                                        ddate = cald.getTime();
                                    }
                                } else if (repeat_pattern.startsWith("Y")) {
                                    /* ?? */
                                    cald.setTime(dbStartDate);
                                    cald.set(Calendar.MILLISECOND, 0);
                                    cald.set(Calendar.SECOND, 0);
                                    cald.set(Calendar.MINUTE, 0);
                                    cald.set(Calendar.HOUR_OF_DAY, 0);

                                    if (year_month > 0 && year_day > 0) {
                                        cald.set(Calendar.MONTH, year_month - 1);
                                        cald.set(Calendar.DAY_OF_MONTH, year_day);
                                    } else {
                                        continue;
                                    }
                                    Date tmp_date = cald.getTime();
                                    while (tmp_date.before(ddate)) {
                                        cald.add(Calendar.MONTH, 1);
                                        /* ???????????????? */
                                        while (year_day > cald.getActualMaximum(Calendar.DAY_OF_MONTH)) {
                                            cald.add(Calendar.MONTH, 1);
                                            cald.set(Calendar.DAY_OF_MONTH, year_day);
                                            if (tmp_date.before(tmp_date)) {
                                                break;
                                            }
                                        }
                                        tmp_date = cald.getTime();
                                    }
                                    ddate = tmp_date;
                                    /*  */
                                    while (!ddate.after(_end_date)) {
                                        if (matchDay(cald, ptn)) {
                                            try {
                                                dexp3 = ExpressionFactory
                                                        .matchExp(EipTSchedule.START_DATE_PROPERTY, ddate);
                                                temp = Database.query(EipTSchedule.class,
                                                        dexp1.andExp(dexp2).andExp(dexp3)).fetchList();
                                                if (temp == null || temp.size() <= 0) {
                                                    existFacility = true;
                                                    break;
                                                }
                                            } catch (Exception e) {
                                                logger.error("[DuplicateFacilityCheck]: ", e);
                                                existFacility = true;
                                                break;
                                            }
                                        }
                                        cald.add(Calendar.MONTH, 1);
                                        /* ???????????????? */
                                        while (year_day > cald.getActualMaximum(Calendar.DAY_OF_MONTH)) {
                                            cald.add(Calendar.MONTH, 1);
                                            cald.set(Calendar.DAY_OF_MONTH, year_day);
                                            if (!ddate.after(_end_date)) {
                                                break;
                                            }
                                        }
                                        ddate = cald.getTime();
                                    }
                                } else {
                                    continue;
                                }
                            }
                        }
                    }
                    if (existFacility) {
                        break;
                    }
                }
                if (existFacility) {
                    return existFacility;
                }
            }
        }
    }
    return result;
}

From source file:com.aimluck.eip.schedule.util.ScheduleUtils.java

public static boolean matchDay(Calendar cal, String repeat_ptn) { // ??????????
    if (repeat_ptn == null || "".equals(repeat_ptn)) {
        return false;
    }//from www .ja v  a  2 s.  co m
    if (repeat_ptn.startsWith("M")) {
        int month_day;
        // ?
        if (repeat_ptn.substring(1, 3).equals("XX")) {
            month_day = cal.getActualMaximum(Calendar.DATE);
        } else {
            month_day = Integer.parseInt(repeat_ptn.substring(1, 3));
        }
        int ptn_day = cal.get(Calendar.DAY_OF_MONTH);
        return (month_day == ptn_day);
    }
    if (repeat_ptn.startsWith("Y")) {
        int year_month = Integer.parseInt(repeat_ptn.substring(1, 3));
        int year_day = Integer.parseInt(repeat_ptn.substring(3, 5));
        int ptn_month = cal.get(Calendar.MONTH);
        int ptn_day = cal.get(Calendar.DAY_OF_MONTH);
        return (year_day == ptn_day && (year_month - 1) == ptn_month);
    } else if (repeat_ptn.startsWith("W")) {
        int dow = cal.get(Calendar.DAY_OF_WEEK);
        int dowim = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
        if (repeat_ptn.length() == 9 || dowim == Character.getNumericValue(repeat_ptn.charAt(8))) {
            if (dow == Calendar.SUNDAY) {
                return repeat_ptn.matches("W1........?");
            }
            if (dow == Calendar.MONDAY) {
                return repeat_ptn.matches("W.1.......?");
            }
            if (dow == Calendar.TUESDAY) {
                return repeat_ptn.matches("W..1......?");
            }
            if (dow == Calendar.WEDNESDAY) {
                return repeat_ptn.matches("W...1.....?");
            }
            if (dow == Calendar.THURSDAY) {
                return repeat_ptn.matches("W....1....?");
            }
            if (dow == Calendar.FRIDAY) {
                return repeat_ptn.matches("W.....1...?");
            }
            if (dow == Calendar.SATURDAY) {
                return repeat_ptn.matches("W......1..?");
            }
        }
        return false;
    } else {
        return true;
    }
}