Example usage for java.util GregorianCalendar getActualMinimum

List of usage examples for java.util GregorianCalendar getActualMinimum

Introduction

In this page you can find the example usage for java.util GregorianCalendar getActualMinimum.

Prototype

@Override
public int getActualMinimum(int field) 

Source Link

Document

Returns the minimum value that this calendar field could have, taking into consideration the given time value and the current values of the Calendar#getFirstDayOfWeek() getFirstDayOfWeek , Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek , #getGregorianChange() getGregorianChange and Calendar#getTimeZone() getTimeZone methods.

Usage

From source file:Main.java

public static void main(String[] args) {

    GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();

    // get actual minimum for day_of_month
    int min = cal.getActualMinimum(GregorianCalendar.DAY_OF_MONTH);
    System.out.println("Actual Minimum:" + min);

    // get actual minimum for YEAR
    min = cal.getActualMinimum(GregorianCalendar.YEAR);
    System.out.println("Actual Minimum:" + min);

}

From source file:org.accada.epcis.repository.query.Schedule.java

/**
 * Sets the specified field of the given callendar to the next scheduled
 * value. Returns whether the new value has been set and is valid.
 * /* ww  w .j a  v a 2 s . co m*/
 * @param cal
 *            Calendar to adjust.
 * @param field
 *            Field to adjust.
 * @return Returns whether the new value has been set and is valid.
 * @throws ImplementationException
 *             Almost any error.
 */
private boolean setToNextScheduledValue(final GregorianCalendar cal, final int field)
        throws ImplementationExceptionResponse {
    int next;
    TreeSet<Integer> vals = getValues(field);
    if (vals.isEmpty()) {
        next = cal.get(field) + 1;
    } else {
        try {
            // get next scheduled value which is bigger than current
            int incrValue = cal.get(field) + 1;
            next = vals.tailSet(new Integer(incrValue)).first().intValue();
        } catch (NoSuchElementException nse) {
            // there is no bigger scheduled value
            return false;
        }
    }
    if (next > cal.getActualMaximum(field) || next < cal.getActualMinimum(field)) {
        return false;
    }
    // all is well, set it to next
    cal.set(field, next);
    return true;
}

From source file:org.accada.epcis.repository.query.Schedule.java

/**
 * Sets the field of a GregorianCalender to its minimum, which is defined as
 * the minimal possible value according to the calendar type possibly
 * superseded by the defined values in the schedule we have. Returns whether
 * the new value has been set and is valid.
 * /* w  w w .j  av  a 2 s  .c  om*/
 * @param cal
 *            Calendar to adjust.
 * @param field
 *            Field to adjust.
 * @return Returns whether the new value has been set and is valid.
 * @throws ImplementationException
 *             Almost any error.
 */
private boolean setFieldToMinimum(final GregorianCalendar cal, final int field)
        throws ImplementationExceptionResponse {
    int min;
    TreeSet<Integer> values = getValues(field);
    if (values.isEmpty()) {
        min = cal.getActualMinimum(field);
    } else {
        min = Math.max(values.first().intValue(), cal.getActualMinimum(field));
        if (min > cal.getActualMaximum(field)) {
            min = cal.getActualMaximum(field);
            if (!values.contains(Integer.valueOf(min)) || min < cal.getActualMinimum(field)
                    || min > cal.getActualMaximum(field)) {
                return false;
            }
        }
    }
    cal.set(field, min);
    return true;
}

From source file:org.nuclos.common2.DateUtils.java

private static void calc(GregorianCalendar result, CalcFunction cf, CalcPair cp) {
    switch (cf) {
    case ADD:/*from w  ww .  jav  a  2  s . c  o m*/
        result.add(cp.x, cp.y);
        break;
    case SUBTRACT:
        result.add(cp.x, cp.y * (-1));
        break;
    case SET:
        switch (cp.x) {
        case Calendar.YEAR:
            result.set(Calendar.DAY_OF_YEAR,
                    cp.y == Integer.MIN_VALUE ? result.getActualMinimum(Calendar.DAY_OF_YEAR)
                            : result.getActualMaximum(Calendar.DAY_OF_YEAR));
            break;
        case Calendar.MONTH:
            result.set(Calendar.DAY_OF_MONTH,
                    cp.y == Integer.MIN_VALUE ? result.getActualMinimum(Calendar.DAY_OF_MONTH)
                            : result.getActualMaximum(Calendar.DAY_OF_MONTH));
            break;
        case Calendar.WEEK_OF_YEAR:
            result.set(Calendar.DAY_OF_WEEK, cp.y == Integer.MIN_VALUE ? Calendar.MONDAY : Calendar.SUNDAY);
            break;
        }
        break;
    }
}