Example usage for org.joda.time.field FieldUtils safeMultiply

List of usage examples for org.joda.time.field FieldUtils safeMultiply

Introduction

In this page you can find the example usage for org.joda.time.field FieldUtils safeMultiply.

Prototype

public static long safeMultiply(long val1, long val2) 

Source Link

Document

Multiply two values throwing an exception if overflow occurs.

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>//www .  j  a va2 s. c  o  m
 * 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);
}