Example usage for org.joda.time ReadablePeriod getFieldType

List of usage examples for org.joda.time ReadablePeriod getFieldType

Introduction

In this page you can find the example usage for org.joda.time ReadablePeriod getFieldType.

Prototype

DurationFieldType getFieldType(int index);

Source Link

Document

Gets the field type at the specified index.

Usage

From source file:net.sourceforge.fenixedu.util.HourMinuteSecond.java

License:Open Source License

/**
 * Gets a copy of this date with the specified period added.
 * <p>/* w  ww. j av  a2  s . c  om*/
 * If the addition is zero, then <code>this</code> is returned. Fields in the period that aren't present in the partial are
 * ignored.
 * <p>
 * This method is typically used to add multiple copies of complex period instances. Adding one field is best achieved using
 * methods like {@link #withFieldAdded(DurationFieldType, int)} or {@link #plusHours(int)}.
 * 
 * @param period
 *            the period to add to this one, null means zero
 * @param scalar
 *            the amount of times to add, such as -1 to subtract once
 * @return a copy of this instance with the period added
 * @throws ArithmeticException
 *             if the new datetime exceeds the capacity
 */
public HourMinuteSecond withPeriodAdded(ReadablePeriod period, int scalar) {
    if (period == null || scalar == 0) {
        return this;
    }
    int[] newValues = getValues();
    for (int i = 0; i < period.size(); i++) {
        DurationFieldType fieldType = period.getFieldType(i);
        int index = indexOf(fieldType);
        if (index >= 0) {
            newValues = getField(index).add(this, index, newValues,
                    FieldUtils.safeMultiply(period.getValue(i), scalar));
        }
    }
    return new HourMinuteSecond(this, newValues);
}