Java Code Examples for org.joda.time.ReadablePeriod#getFieldType()

The following examples show how to use org.joda.time.ReadablePeriod#getFieldType() . 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: Time_22_BasePeriod_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Adds the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] addPeriodInto(int[] values, ReadablePeriod period) {
     for (int i = 0, isize = period.size(); i < isize; i++) {
         DurationFieldType type = period.getFieldType(i);
         int value = period.getValue(i);
         if (value != 0) {
             int index = indexOf(type);
             if (index == -1) {
                 throw new IllegalArgumentException(
                     "Period does not support field '" + type.getName() + "'");
             } else {
                 values[index] = FieldUtils.safeAdd(getValue(index), value);
             }
         }
     }
     return values;
}
 
Example 2
Source File: Time_22_BasePeriod_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Adds the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] addPeriodInto(int[] values, ReadablePeriod period) {
     for (int i = 0, isize = period.size(); i < isize; i++) {
         DurationFieldType type = period.getFieldType(i);
         int value = period.getValue(i);
         if (value != 0) {
             int index = indexOf(type);
             if (index == -1) {
                 throw new IllegalArgumentException(
                     "Period does not support field '" + type.getName() + "'");
             } else {
                 values[index] = FieldUtils.safeAdd(getValue(index), value);
             }
         }
     }
     return values;
}
 
Example 3
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] addPeriodInto(int[] values, ReadablePeriod period) {
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        if (value != 0) {
            int index = indexOf(type);
            if (index == -1) {
                throw new IllegalArgumentException(
                    "Period does not support field '" + type.getName() + "'");
            } else {
                values[index] = FieldUtils.safeAdd(getValue(index), value);
            }
        }
    }
    return values;
}
 
Example 4
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] addPeriodInto(int[] values, ReadablePeriod period) {
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        if (value != 0) {
            int index = indexOf(type);
            if (index == -1) {
                throw new IllegalArgumentException(
                    "Period does not support field '" + type.getName() + "'");
            } else {
                values[index] = FieldUtils.safeAdd(getValue(index), value);
            }
        }
    }
    return values;
}
 
Example 5
Source File: Time_22_BasePeriod_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Private method called from constructor.
 */
private void setPeriodInternal(ReadablePeriod period) {
    int[] newValues = new int[size()];
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        checkAndUpdate(type, newValues, value);
    }
    iValues = newValues;
}
 
Example 6
Source File: Time_22_BasePeriod_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Merges the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] mergePeriodInto(int[] values, ReadablePeriod period) {
     for (int i = 0, isize = period.size(); i < isize; i++) {
         DurationFieldType type = period.getFieldType(i);
         int value = period.getValue(i);
         checkAndUpdate(type, values, value);
     }
     return values;
}
 
Example 7
Source File: Time_22_BasePeriod_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Private method called from constructor.
 */
private void setPeriodInternal(ReadablePeriod period) {
    int[] newValues = new int[size()];
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        checkAndUpdate(type, newValues, value);
    }
    iValues = newValues;
}
 
Example 8
Source File: Time_22_BasePeriod_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Merges the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] mergePeriodInto(int[] values, ReadablePeriod period) {
     for (int i = 0, isize = period.size(); i < isize; i++) {
         DurationFieldType type = period.getFieldType(i);
         int value = period.getValue(i);
         checkAndUpdate(type, values, value);
     }
     return values;
}
 
Example 9
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Private method called from constructor.
 */
private void setPeriodInternal(ReadablePeriod period) {
    int[] newValues = new int[size()];
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        checkAndUpdate(type, newValues, value);
    }
    setValues(newValues);
}
 
Example 10
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Merges the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] mergePeriodInto(int[] values, ReadablePeriod period) {
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        checkAndUpdate(type, values, value);
    }
    return values;
}
 
Example 11
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Private method called from constructor.
 */
private void setPeriodInternal(ReadablePeriod period) {
    int[] newValues = new int[size()];
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        checkAndUpdate(type, newValues, value);
    }
    setValues(newValues);
}
 
Example 12
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Merges the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] mergePeriodInto(int[] values, ReadablePeriod period) {
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        checkAndUpdate(type, values, value);
    }
    return values;
}
 
Example 13
Source File: AbstractPeriod.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compares this object with the specified object for equality based
 * on the value of each field. All ReadablePeriod instances are accepted.
 * <p>
 * Note that a period of 1 day is not equal to a period of 24 hours,
 * nor is 1 hour equal to 60 minutes. Only periods with the same amount
 * in each field are equal.
 * <p>
 * This is because periods represent an abstracted definition of a time
 * period (eg. a day may not actually be 24 hours, it might be 23 or 25
 * at daylight savings boundary).
 * <p>
 * To compare the actual duration of two periods, convert both to
 * {@link org.joda.time.Duration Duration}s, an operation that emphasises
 * that the result may differ according to the date you choose.
 *
 * @param period  a readable period to check against
 * @return true if all the field values are equal, false if
 *  not or the period is null or of an incorrect type
 */
public boolean equals(Object period) {
    if (this == period) {
        return true;
    }
    if (period instanceof ReadablePeriod == false) {
        return false;
    }
    ReadablePeriod other = (ReadablePeriod) period;
    if (size() != other.size()) {
        return false;
    }
    for (int i = 0, isize = size(); i < isize; i++) {
        if (getValue(i) != other.getValue(i) || getFieldType(i) != other.getFieldType(i)) {
            return false;
        }
    }
    return true;
}
 
Example 14
Source File: AbstractPeriod.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compares this object with the specified object for equality based
 * on the value of each field. All ReadablePeriod instances are accepted.
 * <p>
 * Note that a period of 1 day is not equal to a period of 24 hours,
 * nor is 1 hour equal to 60 minutes. Only periods with the same amount
 * in each field are equal.
 * <p>
 * This is because periods represent an abstracted definition of a time
 * period (eg. a day may not actually be 24 hours, it might be 23 or 25
 * at daylight savings boundary).
 * <p>
 * To compare the actual duration of two periods, convert both to
 * {@link org.joda.time.Duration Duration}s, an operation that emphasises
 * that the result may differ according to the date you choose.
 *
 * @param period  a readable period to check against
 * @return true if all the field values are equal, false if
 *  not or the period is null or of an incorrect type
 */
public boolean equals(Object period) {
    if (this == period) {
        return true;
    }
    if (period instanceof ReadablePeriod == false) {
        return false;
    }
    ReadablePeriod other = (ReadablePeriod) period;
    if (size() != other.size()) {
        return false;
    }
    for (int i = 0, isize = size(); i < isize; i++) {
        if (getValue(i) != other.getValue(i) || getFieldType(i) != other.getFieldType(i)) {
            return false;
        }
    }
    return true;
}
 
Example 15
Source File: HourMinuteSecond.java    From fenixedu-academic with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Gets a copy of this date 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
 * 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);
}