Example usage for java.util Calendar getActualMaximum

List of usage examples for java.util Calendar getActualMaximum

Introduction

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

Prototype

public int getActualMaximum(int field) 

Source Link

Document

Returns the maximum value that the specified calendar field could have, given the time value of this Calendar.

Usage

From source file:com.xpn.xwiki.plugin.chronopolys.Utils.java

/**
* Calculates the number of days between two calendar days 
* @param d1    The first date.// ww  w  .  ja va2  s  . com
* @param d2    The second date.
* @return      The number of days between the two dates.  Zero is
*              returned if the dates are the same, one if the dates are
*              adjacent, etc.  
*              If Calendar types of d1 and d2
*              are different, the result may not be accurate.
*/
public int getDaysBetween(java.util.Calendar d1, java.util.Calendar d2) {
    boolean neg = false;
    if (d1.after(d2)) { // swap dates so that d1 is start and d2 is end
        java.util.Calendar swap = d1;
        d1 = d2;
        d2 = swap;
        neg = true;
    }
    int days = d2.get(java.util.Calendar.DAY_OF_YEAR) - d1.get(java.util.Calendar.DAY_OF_YEAR);
    int y2 = d2.get(java.util.Calendar.YEAR);
    if (d1.get(java.util.Calendar.YEAR) != y2) {
        d1 = (java.util.Calendar) d1.clone();
        do {
            days += d1.getActualMaximum(java.util.Calendar.DAY_OF_YEAR);
            d1.add(java.util.Calendar.YEAR, 1);
        } while (d1.get(java.util.Calendar.YEAR) != y2);
    }
    if (neg)
        return (-1) * days;
    return days;
}

From source file:com.silverpeas.blog.control.BlogSessionController.java

private void setMonthLastDay(Calendar calendar) {
    int monthLastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    calendar.set(Calendar.DAY_OF_MONTH, monthLastDay);
    currentEndDate.setTime(calendar.getTime());
}

From source file:com.dpcsoftware.mn.CategoryStats.java

public void renderGraph() {
    SQLiteDatabase db = DatabaseHelper.quickDb(this, 0);
    if (date == null)
        date = Calendar.getInstance().getTime();

    String queryModifier = "";
    if (isByMonth)
        queryModifier = " AND strftime('%Y-%m'," + Db.Table1.TABLE_NAME + "." + Db.Table1.COLUMN_DATAT + ") = '"
                + app.dateToDb("yyyy-MM", date) + "'";

    Cursor c = db.rawQuery("SELECT " + Db.Table2.TABLE_NAME + "." + Db.Table2._ID + "," + Db.Table2.TABLE_NAME
            + "." + Db.Table2.COLUMN_NCAT + "," + Db.Table2.TABLE_NAME + "." + Db.Table2.COLUMN_CORCAT + ","
            + "SUM(" + Db.Table1.TABLE_NAME + "." + Db.Table1.COLUMN_VALORT + ")" + " FROM "
            + Db.Table1.TABLE_NAME + "," + Db.Table2.TABLE_NAME + " WHERE " + Db.Table1.TABLE_NAME + "."
            + Db.Table1.COLUMN_IDCAT + " = " + Db.Table2.TABLE_NAME + "." + Db.Table2._ID + " AND "
            + Db.Table1.TABLE_NAME + "." + Db.Table1.COLUMN_IDGRUPO + " = " + app.activeGroupId + queryModifier
            + " GROUP BY " + Db.Table1.TABLE_NAME + "." + Db.Table1.COLUMN_IDCAT + " ORDER BY "
            + Db.Table2.COLUMN_NCAT, null);

    float[] values = new float[c.getCount()];
    int[] colors = new int[c.getCount()];
    float total = 0;

    while (c.moveToNext()) {
        values[c.getPosition()] = c.getFloat(3);
        colors[c.getPosition()] = c.getInt(2);
        total += c.getFloat(3);/*from  w  w w. ja  va  2  s .  co m*/
    }

    BarChart v = new BarChart(this, values, colors);
    v.setPadding(10, 10, 10, 10);
    FrameLayout graphLayout = ((FrameLayout) findViewById(R.id.FrameLayout1));
    if (graphLayout.getChildCount() == 1)
        graphLayout.removeViewAt(0);
    graphLayout.addView(v);

    ListView lv = ((ListView) findViewById(R.id.listView1));
    ((TextView) footer.findViewById(R.id.textView2)).setText(app.printMoney(total));

    int days = 1;
    if (!isByMonth) {
        SimpleDateFormat dateF = new SimpleDateFormat("yyyy-MM-dd");
        dateF.setTimeZone(TimeZone.getDefault());

        Cursor cTemp = db.rawQuery("SELECT " + Db.Table1.COLUMN_DATAT + " FROM " + Db.Table1.TABLE_NAME
                + " WHERE " + Db.Table1.COLUMN_IDGRUPO + " = " + app.activeGroupId + " ORDER BY "
                + Db.Table1.COLUMN_DATAT + " DESC", null);
        try {
            cTemp.moveToFirst();
            Date date2 = dateF.parse(cTemp.getString(0));
            cTemp.moveToLast();
            Date date1 = dateF.parse(cTemp.getString(0));

            days = (int) Math.ceil((date2.getTime() - date1.getTime()) / (1000.0 * 24 * 60 * 60)) + 1;

            App.Log("" + days);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        Calendar now = Calendar.getInstance();
        if (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH)
                && cal.get(Calendar.YEAR) == now.get(Calendar.YEAR))
            days = now.get(Calendar.DAY_OF_MONTH);
        else
            days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    ((TextView) footer2.findViewById(R.id.textView2)).setText(app.printMoney(total / days));

    ((TextView) findViewById(R.id.textViewMonth)).setText(app.dateToUser("MMMM / yyyy", date));

    if (adapter == null) {
        adapter = new CategoryStatsAdapter(this, c, total);
        lv.setAdapter(adapter);
    } else {
        adapter.changeCursor(c, total);
        adapter.notifyDataSetChanged();
    }
}

From source file:com.huateng.ebank.framework.util.DateUtil.java

/**
 * //from www  . j ava  2  s.c o m
 *
 * @param startDate
 * @param endDate
 * @return
 */
public static int getDaysBetween(Date startDate, Date endDate) {
    Calendar calendarStartDate = Calendar.getInstance();
    Calendar calendarEndDate = Calendar.getInstance();

    // 
    calendarStartDate.setTime(startDate);
    calendarEndDate.setTime(endDate);
    if (startDate.after(endDate)) {
        Calendar swap = calendarStartDate;
        calendarStartDate = calendarEndDate;
        calendarEndDate = swap;
    }

    int days = calendarEndDate.get(Calendar.DAY_OF_YEAR) - calendarStartDate.get(Calendar.DAY_OF_YEAR);
    int y2 = calendarEndDate.get(Calendar.YEAR);
    while (calendarStartDate.get(Calendar.YEAR) < y2) {
        days += calendarStartDate.getActualMaximum(Calendar.DAY_OF_YEAR);
        calendarStartDate.add(Calendar.YEAR, 1);
    }

    return days;
}

From source file:org.openlmis.report.service.AverageConsumptionReportDataProvider.java

public AverageConsumptionReportParam getReportFilterData(Map<String, String[]> filterCriteria) {
    averageConsumptionReportParam = new AverageConsumptionReportParam();
    if (filterCriteria != null) {

        Date originalStart = new Date();
        Date originalEnd = new Date();

        averageConsumptionReportParam.setZoneId(StringUtils.isBlank(filterCriteria.get("zoneId")[0]) ? 0L
                : Long.parseLong(filterCriteria.get("zoneId")[0])); //defaults to 0
        averageConsumptionReportParam/*from w  w  w .  j a v  a  2  s . c o  m*/
                .setFacilityTypeId(StringUtils.isBlank(filterCriteria.get("facilityTypeId")[0]) ? 0
                        : Integer.parseInt(filterCriteria.get("facilityTypeId")[0])); //defaults to 0
        averageConsumptionReportParam.setFacilityType(
                StringUtils.isBlank(filterCriteria.get("facilityType")[0]) ? "All Facility Types"
                        : filterCriteria.get("facilityType")[0]);
        averageConsumptionReportParam.setFacilityId(StringUtils.isBlank(filterCriteria.get("facility")[0]) ? 0
                : Long.parseLong(filterCriteria.get("facility")[0])); //defaults to 0

        averageConsumptionReportParam
                .setProductCategoryId(StringUtils.isBlank(filterCriteria.get("productCategoryId")[0]) ? 0
                        : Long.parseLong(filterCriteria.get("productCategoryId")[0])); //defaults to 0
        averageConsumptionReportParam.setProductId(StringUtils.isBlank(filterCriteria.get("productId")[0]) ? "0"
                : (filterCriteria.get("productId")[0]).toString().replace("]", "}").replace("[", "{")
                        .replaceAll("\"", ""));
        averageConsumptionReportParam.setRgroupId(StringUtils.isBlank(filterCriteria.get("rgroupId")[0]) ? 0
                : Long.parseLong(filterCriteria.get("rgroupId")[0])); //defaults to 0
        averageConsumptionReportParam.setProgramId(StringUtils.isBlank(filterCriteria.get("programId")[0]) ? 0
                : Long.parseLong(filterCriteria.get("programId")[0])); //defaults to 0

        //monthly
        averageConsumptionReportParam
                .setYearFrom(StringUtils.isBlank(filterCriteria.get("fromYear")[0]) ? originalStart.getYear()
                        : Integer.parseInt(filterCriteria.get("fromYear")[0])); //defaults to 0
        averageConsumptionReportParam
                .setYearTo(StringUtils.isBlank(filterCriteria.get("toYear")[0]) ? originalEnd.getYear()
                        : Integer.parseInt(filterCriteria.get("toYear")[0])); //defaults to 0
        averageConsumptionReportParam
                .setMonthFrom(StringUtils.isBlank(filterCriteria.get("fromMonth")[0]) ? originalStart.getMonth()
                        : Integer.parseInt(filterCriteria.get("fromMonth")[0])); //defaults to 0
        averageConsumptionReportParam
                .setMonthTo(StringUtils.isBlank(filterCriteria.get("toMonth")[0]) ? originalEnd.getMonth()
                        : Integer.parseInt(filterCriteria.get("toMonth")[0])); //defaults to 0

        averageConsumptionReportParam.setPdformat(StringUtils.isBlank(filterCriteria.get("pdformat")[0]) ? 0
                : Integer.parseInt(filterCriteria.get("pdformat")[0])); //defaults to 0
        averageConsumptionReportParam
                .setPeriodType(StringUtils.isBlank(filterCriteria.get("periodType")[0]) ? ""
                        : filterCriteria.get("periodType")[0].toString());
        averageConsumptionReportParam
                .setQuarterFrom(StringUtils.isBlank(filterCriteria.get("fromQuarter")[0]) ? 1
                        : Integer.parseInt(filterCriteria.get("fromQuarter")[0]));
        averageConsumptionReportParam.setQuarterTo(StringUtils.isBlank(filterCriteria.get("toQuarter")[0]) ? 1
                : Integer.parseInt(filterCriteria.get("toQuarter")[0]));
        averageConsumptionReportParam
                .setSemiAnnualFrom(StringUtils.isBlank(filterCriteria.get("fromSemiAnnual")[0]) ? 1
                        : Integer.parseInt(filterCriteria.get("fromSemiAnnual")[0]));
        averageConsumptionReportParam
                .setSemiAnnualTo(StringUtils.isBlank(filterCriteria.get("toSemiAnnual")[0]) ? 1
                        : Integer.parseInt(filterCriteria.get("toSemiAnnual")[0]));

        int monthFrom = 0;
        int monthTo = 0;
        String periodType = averageConsumptionReportParam.getPeriodType();

        if (periodType.equals(Constants.PERIOD_TYPE_QUARTERLY)) {
            monthFrom = 3 * (averageConsumptionReportParam.getQuarterFrom() - 1);
            monthTo = 3 * averageConsumptionReportParam.getQuarterTo() - 1;

        } else if (periodType.equals(Constants.PERIOD_TYPE_MONTHLY)) {
            monthFrom = averageConsumptionReportParam.getMonthFrom();
            monthTo = averageConsumptionReportParam.getMonthTo();

        } else if (periodType.equals(Constants.PERIOD_TYPE_SEMI_ANNUAL)) {
            monthFrom = 6 * (averageConsumptionReportParam.getSemiAnnualFrom() - 1);
            monthTo = 6 * averageConsumptionReportParam.getSemiAnnualTo() - 1;
        } else if (periodType.equals(Constants.PERIOD_TYPE_ANNUAL)) {
            monthFrom = 0;
            monthTo = 11;
        }

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, averageConsumptionReportParam.getYearFrom());
        calendar.set(Calendar.MONTH, monthFrom);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        averageConsumptionReportParam.setStartDate(calendar.getTime());

        calendar.set(Calendar.YEAR, averageConsumptionReportParam.getYearTo());
        calendar.set(Calendar.MONTH, monthTo);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        averageConsumptionReportParam.setEndDate(calendar.getTime());

    }
    return averageConsumptionReportParam;

}

From source file:com.zimbra.common.calendar.ZoneInfo2iCalendar.java

private static String dayToICalRRulePart(int hintYear, int hintMonth, Day day) {
    DayType type = day.getType();//from  www  .  j  av a2  s  .c o  m

    int weeknum = day.getWeeknum();
    Weekday wkday = day.getWeekday();
    int date = day.getDate();

    // Turn ON rules into WEEKNUM rules using the wkday of the monthday in hintYear/hintMonth.
    if (DayType.ON.equals(type)) {
        Calendar hintDay = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
        hintDay.set(hintYear, hintMonth - 1, date, 0, 0, 0);
        hintDay.set(Calendar.MILLISECOND, 0);
        int calWkday = hintDay.get(Calendar.DAY_OF_WEEK);
        wkday = Weekday.lookUp(calWkday);
        assert (wkday != null);
        weeknum = (date - 1) / 7 + 1;
        // Did they mean "last week" rather than "week 4"?
        if (hintDay.getActualMaximum(Calendar.DAY_OF_MONTH) - date < 7)
            weeknum = -1;
        type = DayType.WEEKNUM;
    }

    String icalWkday = weekdayToICalWkday(wkday);

    // Turn [ON_OR_]BEFORE/AFTER rules into WEEKNUM rules using the wkday of the monthday in hintYear/hintMonth.
    // Simplify: < to <=, > to >=.
    if (DayType.BEFORE.equals(type)) {
        type = DayType.ON_OR_BEFORE;
        --date;
    } else if (DayType.AFTER.equals(type)) {
        type = DayType.ON_OR_AFTER;
        ++date;
    }
    if (DayType.ON_OR_BEFORE.equals(type) || DayType.ON_OR_AFTER.equals(type)) {
        Calendar hintDay = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
        hintDay.set(hintYear, hintMonth - 1, date, 0, 0, 0);
        hintDay.set(Calendar.MILLISECOND, 0);
        int numDaysInMonth = hintDay.getActualMaximum(Calendar.DAY_OF_MONTH);
        int calWkday = hintDay.get(Calendar.DAY_OF_WEEK);
        int wkdayInt = Weekday.toInt(wkday);
        int newDate;
        if (DayType.ON_OR_BEFORE.equals(type)) {
            // search backward
            if (calWkday > wkdayInt) // e.g calWkday=Wed(4), wkdayInt=Sun(1) => back 3
                newDate = date - (calWkday - wkdayInt);
            else // eg. calWkday=Wed(4), wkdayInt=Fri(6) => back 5 = back 7-2
                newDate = date - (7 + (calWkday - wkdayInt));
        } else {
            // search forward
            if (calWkday > wkdayInt) // e.g calWkday=Wed(4), wkdayInt=Sun(1) => forward 4 = forward 7 - 3
                newDate = date + (7 + (wkdayInt - calWkday));
            else // eg. calWkday=Wed(4), wkdayInt=Fri(6) => forward 2
                newDate = date + (wkdayInt - calWkday);
        }
        if (newDate >= 1 && newDate <= numDaysInMonth) {
            weeknum = (newDate - 1) / 7 + 1;
            // Did they mean "last week" rather than "week 4"?
            if (numDaysInMonth - newDate < 7)
                weeknum = -1;
            type = DayType.WEEKNUM;
        }
    }
    // If we couldn't convert BYMONTHDAY rule to BYDAY rule for any reason, we have no choice but
    // to use the ugly BYMONTHDAY rule that lists 7 dates.
    // week 1: 1-7
    // week 2: 8-14
    // week 3: 15 - 21
    // week 4: 22 - 28
    // week 5: 29 - 31
    if (DayType.ON_OR_BEFORE.equals(type)) {
        if (date % 7 == 0) { // days 7, 14, 21 and 28 only
            weeknum = (date - 1) / 7 + 1;
            type = DayType.WEEKNUM;
        } else {
            // Can't be done in WEEKNUM style.  We need to use a more verbose iCalendar recurrence
            // syntax.   Let's use the example of "Sun<=25".  This means the last Sunday of the month
            // on or before the 25th.  We can express this in iCalendar with 2 conditions ANDed together:
            // 1) BYDAY=SU (all Sundays in the month)
            // 2) BYMONTHDAY=19,20,21,22,23,24,25 (7 days ending on the given date)
            StringBuilder sb = new StringBuilder("BYDAY=");
            sb.append(icalWkday).append(";BYMONTHDAY=");
            int minDate = Math.max(date - 6, 1);
            sb.append(minDate);
            for (int i = minDate + 1; i <= date; ++i) {
                sb.append(",").append(i);
            }
            return sb.toString();
        }
    } else if (DayType.ON_OR_AFTER.equals(type)) {
        if (date % 7 == 1) { // days 1, 8, 15, 22, and 29 only
            weeknum = date / 7 + 1;
            type = DayType.WEEKNUM;
        } else {
            // Similar to ON_OR_BEFORE case above.  Combine BYDAY and BYMONTHDAY rules.
            // Example: "Sat>=13" means the first Sunday on or after the 9th.
            // 1) BYDAY=SA (all Saturdays in the month)
            // 2) BYMONTHDAY=13,14,15,16,17,18,19 (7 days starting on the given date)
            StringBuilder sb = new StringBuilder("BYDAY=");
            sb.append(icalWkday).append(";BYMONTHDAY=");
            sb.append(date);
            int maxDate = Math.min(date + 6, 31);
            for (int i = date + 1; i <= maxDate; ++i) {
                sb.append(",").append(i);
            }
            return sb.toString();
        }
    }

    assert (DayType.WEEKNUM.equals(type));
    if (weeknum > 4)
        weeknum = -1;
    return String.format("BYDAY=%d%s", weeknum, icalWkday);
}

From source file:org.openmrs.module.facilitydata.web.controller.FacilityDataCompletionAnalysisFormController.java

@RequestMapping("/module/facilitydata/completionAnalysis.form")
public void viewForm(ModelMap map, HttpServletRequest request,
        @ModelAttribute("query") FacilityDataQuery query) {

    FacilityDataService fds = Context.getService(FacilityDataService.class);

    if (query.getSchema() != null) {

        Date validFrom = query.getSchema().getValidFrom();
        if (query.getFromDate() != null && validFrom != null && query.getFromDate().before(validFrom)) {
            query.setFromDate(validFrom);
        }/*w  ww.  j a  v  a  2s.co  m*/
        if (query.getFromDate() == null) {
            Date minEntryDate = fds.getMinEnteredStartDateForSchema(query.getSchema());
            if (minEntryDate == null) {
                minEntryDate = new Date();
            }
            query.setFromDate(minEntryDate);
        }

        Date validTo = query.getSchema().getValidTo();
        if (query.getToDate() != null && validTo != null && query.getToDate().after(validTo)) {
            query.setToDate(validTo);
        }
        if (query.getToDate() == null) {
            query.setToDate(new Date());
        }

        Calendar cal = Calendar.getInstance();
        Frequency frequency = query.getSchema().getForm().getFrequency();
        if (frequency == Frequency.MONTHLY) {
            cal.setTime(query.getFromDate());
            if (cal.get(Calendar.DATE) > 1) {
                cal.set(Calendar.DATE, 1);
                query.setFromDate(cal.getTime());
            }
            cal.setTime(query.getToDate());
            cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
            query.setToDate(cal.getTime());
        }

        int numExpected = 0;
        List<Integer> daysOfWeek = FacilityDataConstants.getDailyReportDaysOfWeek();
        Map<FacilityDataFormQuestion, Integer> numValuesByQuestion = new LinkedHashMap<FacilityDataFormQuestion, Integer>();
        Map<FacilityDataFormQuestion, Double> numericTotals = new HashMap<FacilityDataFormQuestion, Double>();
        Map<FacilityDataFormQuestion, Map<FacilityDataCodedOption, Integer>> codedTotals = new HashMap<FacilityDataFormQuestion, Map<FacilityDataCodedOption, Integer>>();

        cal.setTime(query.getFromDate());
        while (cal.getTime().compareTo(query.getToDate()) <= 0) {
            if (frequency != Frequency.DAILY || daysOfWeek.contains(cal.get(Calendar.DAY_OF_WEEK))) {
                numExpected++;
            }
            cal.add(frequency.getCalendarField(), frequency.getCalendarIncrement());
        }

        List<FacilityDataValue> values = fds.evaluateFacilityDataQuery(query);
        Map<FacilityDataFormQuestion, Map<Location, FacilityDataValue>> latestValuesForQuestion = new HashMap<FacilityDataFormQuestion, Map<Location, FacilityDataValue>>();
        for (FacilityDataValue v : values) {

            Integer numValues = numValuesByQuestion.get(v.getQuestion());
            numValuesByQuestion.put(v.getQuestion(), numValues == null ? 1 : numValues + 1);

            FacilityDataQuestionType type = v.getQuestion().getQuestion().getQuestionType();
            if (type instanceof CodedFacilityDataQuestionType) {
                Map<FacilityDataCodedOption, Integer> m = codedTotals.get(v.getQuestion());
                if (m == null) {
                    m = new HashMap<FacilityDataCodedOption, Integer>();
                    codedTotals.put(v.getQuestion(), m);
                }
                Integer num = m.get(v.getValueCoded());
                num = num == null ? 1 : num + 1;
                m.put(v.getValueCoded(), num);
            } else {
                PeriodApplicability pa = v.getQuestion().getQuestion().getPeriodApplicability();
                if (pa == PeriodApplicability.DURING_PERIOD) {
                    Double num = numericTotals.get(v.getQuestion());
                    if (num == null) {
                        num = new Double(0);
                    }
                    num += v.getValueNumeric();
                    numericTotals.put(v.getQuestion(), num);
                } else {
                    Map<Location, FacilityDataValue> valueForQuestion = latestValuesForQuestion
                            .get(v.getQuestion());
                    if (valueForQuestion == null) {
                        valueForQuestion = new HashMap<Location, FacilityDataValue>();
                        latestValuesForQuestion.put(v.getQuestion(), valueForQuestion);
                    }
                    FacilityDataValue valueForLocation = valueForQuestion.get(v.getFacility());
                    if (valueForLocation == null || valueForLocation.getToDate().before(v.getToDate())) {
                        valueForQuestion.put(v.getFacility(), v);
                    }
                }
            }
        }
        if (!latestValuesForQuestion.isEmpty()) {
            for (FacilityDataFormSection section : query.getSchema().getSections()) {
                for (FacilityDataFormQuestion question : section.getQuestions()) {
                    Double d = new Double(0);
                    Map<Location, FacilityDataValue> m = latestValuesForQuestion.get(question);
                    if (m != null) {
                        for (FacilityDataValue v : m.values()) {
                            if (v != null) {
                                d += v.getValueNumeric();
                            }
                        }
                        numericTotals.put(question, d);
                    }
                }
            }
        }

        if (query.getFacility() == null) {
            numExpected = numExpected * getLocations().size();
        } else {
            Set<Location> allFacilities = FacilityDataUtil.getAllLocationsInHierarchy(query.getFacility());
            List<Location> supportedFacilities = FacilityDataConstants.getSupportedFacilities();
            allFacilities.retainAll(supportedFacilities);
            numExpected = numExpected * allFacilities.size();
        }

        map.addAttribute("numExpected", numExpected);
        map.addAttribute("numValuesByQuestion", numValuesByQuestion);
        map.addAttribute("numericTotals", numericTotals);
        map.addAttribute("codedTotals", codedTotals);
    }
}

From source file:org.jfree.data.time.Week.java

/**
 * Returns the week following this one.  This method will return
 * <code>null</code> for some upper limit on the range of weeks (currently
 * week 53, 9999).  For week 52 of any year, the following week is always
 * week 53, but week 53 may not contain any days (you should check for
 * this)./*w  w w .  j av  a2  s.com*/
 *
 * @return The following week (possibly <code>null</code>).
 */
@Override
public RegularTimePeriod next() {

    Week result;
    if (this.week < 52) {
        result = new Week(this.week + 1, this.year);
    } else {
        Calendar calendar = Calendar.getInstance();
        calendar.set(this.year, Calendar.DECEMBER, 31);
        int actualMaxWeek = calendar.getActualMaximum(Calendar.WEEK_OF_YEAR);
        if (this.week < actualMaxWeek) {
            result = new Week(this.week + 1, this.year);
        } else {
            if (this.year < 9999) {
                result = new Week(FIRST_WEEK_IN_YEAR, this.year + 1);
            } else {
                result = null;
            }
        }
    }
    return result;

}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractReportController.java

private void getRegistrationReport(String start, String end, ModelMap modelMap, Locale locale) {
    Report report = null;// w  ww.j  a  v a 2s. c o m
    HashMap<String, Object> parameters = new HashMap<String, Object>();
    Calendar cal = Calendar.getInstance();
    DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
    if (start == null) {
        cal.set(Calendar.DATE, 1);
        start = format.format(cal.getTime());
    }
    if (end == null) {
        cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
        end = format.format(cal.getTime());
    }

    parameters.put("startDate", start);
    parameters.put("endDate", end);
    List<AccountType> accountTypeList = tenantService.getAllAccountTypes();
    accountTypeList.remove(tenantService.getAccountTypeByName("SYSTEM"));
    GenericReport nrr = new NewRegistrationReport(parameters, dataSource, accountTypeList, locale,
            messageSource);
    report = reportService.generateReport(nrr);
    modelMap.addAttribute("report", report);
    modelMap.addAttribute("tenant", getCurrentUser().getTenant());
}

From source file:edu.northwestern.bioinformatics.studycalendar.service.SubjectService.java

/**
 * Finds all the dates which represent the particular day of the week (Monday, Tuesday, etc.)
 * in the specified month./*from  ww w . j ava  2 s. c  o  m*/
 */
// package level for testing
List<Date> findDaysOfWeekInMonth(int year, int month, int dayOfTheWeek) {
    List<Date> matches = new ArrayList<Date>();
    Calendar search = Calendar.getInstance();
    search.set(year, month, 1);
    while (search.get(Calendar.MONTH) == month
            && search.get(Calendar.DAY_OF_MONTH) <= search.getActualMaximum(Calendar.DAY_OF_MONTH)) {
        System.out.println(search.getTime());
        if (search.get(Calendar.DAY_OF_WEEK) == dayOfTheWeek) {
            matches.add(search.getTime());
        }
        search.add(Calendar.DAY_OF_MONTH, 1);
    }
    return matches;
}