本文整理汇总了Java中org.joda.time.ReadablePeriod.getFieldType方法的典型用法代码示例。如果您正苦于以下问题:Java ReadablePeriod.getFieldType方法的具体用法?Java ReadablePeriod.getFieldType怎么用?Java ReadablePeriod.getFieldType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.ReadablePeriod
的用法示例。
在下文中一共展示了ReadablePeriod.getFieldType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addPeriodInto
import org.joda.time.ReadablePeriod; //导入方法依赖的package包/类
/**
* 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;
}
示例2: setPeriodInternal
import org.joda.time.ReadablePeriod; //导入方法依赖的package包/类
/**
* 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);
}
示例3: mergePeriodInto
import org.joda.time.ReadablePeriod; //导入方法依赖的package包/类
/**
* 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;
}
示例4: equals
import org.joda.time.ReadablePeriod; //导入方法依赖的package包/类
/**
* 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;
}