Java Code Examples for org.joda.time.ReadWritablePeriod#setPeriod()

The following examples show how to use org.joda.time.ReadWritablePeriod#setPeriod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateTimeUtils.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public int parseInto(ReadWritablePeriod period, String text, int position, Locale locale)
{
    int bestValidPos = position;
    ReadWritablePeriod bestValidPeriod = null;

    int bestInvalidPos = position;

    for (PeriodParser parser : parsers) {
        ReadWritablePeriod parsedPeriod = new MutablePeriod();
        int parsePos = parser.parseInto(parsedPeriod, text, position, locale);
        if (parsePos >= position) {
            if (parsePos > bestValidPos) {
                bestValidPos = parsePos;
                bestValidPeriod = parsedPeriod;
                if (parsePos >= text.length()) {
                    break;
                }
            }
        }
        else if (parsePos < 0) {
            parsePos = ~parsePos;
            if (parsePos > bestInvalidPos) {
                bestInvalidPos = parsePos;
            }
        }
    }

    if (bestValidPos > position || (bestValidPos == position)) {
        // Restore the state to the best valid parse.
        if (bestValidPeriod != null) {
            period.setPeriod(bestValidPeriod);
        }
        return bestValidPos;
    }

    return ~bestInvalidPos;
}
 
Example 2
Source File: ReadablePeriodConverter.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Extracts duration values from an object of this converter's type, and
 * sets them into the given ReadWritablePeriod.
 *
 * @param duration duration to get modified
 * @param object  the object to convert, must not be null
 * @param chrono  the chronology to use
 * @throws NullPointerException if the duration or object is null
 * @throws ClassCastException if the object is an invalid type
 * @throws IllegalArgumentException if the object is invalid
 */
public void setInto(ReadWritablePeriod duration, Object object, Chronology chrono) {
    duration.setPeriod((ReadablePeriod) object);
}
 
Example 3
Source File: NullConverter.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets the given ReadWritableDuration to zero milliseconds.
 *
 * @param duration duration to get modified
 * @param object  the object to convert, which is null
 * @param chrono  the chronology to use
 * @throws NullPointerException if the duration is null
 */
public void setInto(ReadWritablePeriod duration, Object object, Chronology chrono) {
    duration.setPeriod((Period) null);
}
 
Example 4
Source File: ReadablePeriodConverter.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Extracts duration values from an object of this converter's type, and
 * sets them into the given ReadWritablePeriod.
 *
 * @param duration duration to get modified
 * @param object  the object to convert, must not be null
 * @param chrono  the chronology to use
 * @throws NullPointerException if the duration or object is null
 * @throws ClassCastException if the object is an invalid type
 * @throws IllegalArgumentException if the object is invalid
 */
public void setInto(ReadWritablePeriod duration, Object object, Chronology chrono) {
    duration.setPeriod((ReadablePeriod) object);
}
 
Example 5
Source File: NullConverter.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets the given ReadWritableDuration to zero milliseconds.
 *
 * @param duration duration to get modified
 * @param object  the object to convert, which is null
 * @param chrono  the chronology to use
 * @throws NullPointerException if the duration is null
 */
public void setInto(ReadWritablePeriod duration, Object object, Chronology chrono) {
    duration.setPeriod((Period) null);
}