Пример #1
0
 /**
  * Gets a copy of this Partial with the specified period added.
  *
  * <p>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 the method {@link #withFieldAdded(DurationFieldType, 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 Partial 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 Partial(this, newValues);
 }
Пример #2
0
 /**
  * Gets the indexed field part of the period.
  *
  * @param period the period to query
  * @param index the index to use
  * @return the value of the field, zero if unsupported
  */
 int getIndexedField(ReadablePeriod period, int index) {
   int realIndex = iIndices[index];
   return (realIndex == -1 ? 0 : period.getValue(realIndex));
 }