本文整理汇总了Java中org.joda.time.field.FieldUtils类的典型用法代码示例。如果您正苦于以下问题:Java FieldUtils类的具体用法?Java FieldUtils怎么用?Java FieldUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldUtils类属于org.joda.time.field包,在下文中一共展示了FieldUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: standardPeriodIn
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
* Creates a new instance representing the number of complete standard length units
* in the specified period.
* <p>
* This factory method converts all fields from the period to hours using standardised
* durations for each field. Only those fields which have a precise duration in
* the ISO UTC chronology can be converted.
* <ul>
* <li>One week consists of 7 days.
* <li>One day consists of 24 hours.
* <li>One hour consists of 60 minutes.
* <li>One minute consists of 60 seconds.
* <li>One second consists of 1000 milliseconds.
* </ul>
* Months and Years are imprecise and periods containing these values cannot be converted.
*
* @param period the period to get the number of hours from, must not be null
* @param millisPerUnit the number of milliseconds in one standard unit of this period
* @throws IllegalArgumentException if the period contains imprecise duration values
*/
protected static int standardPeriodIn(ReadablePeriod period, long millisPerUnit) {
if (period == null) {
return 0;
}
Chronology iso = ISOChronology.getInstanceUTC();
long duration = 0L;
for (int i = 0; i < period.size(); i++) {
int value = period.getValue(i);
if (value != 0) {
DurationField field = period.getFieldType(i).getField(iso);
if (field.isPrecise() == false) {
throw new IllegalArgumentException(
"Cannot convert period to duration as " + field.getName() +
" is not precise in the period " + period);
}
duration = FieldUtils.safeAdd(duration, FieldUtils.safeMultiply(field.getUnitMillis(), value));
}
}
return FieldUtils.safeToInt(duration / millisPerUnit);
}
示例2: equals
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
* Compares this ReadablePartial with another returning true if the chronology,
* field types and values are equal.
*
* @param partial an object to check against
* @return true if fields and values are equal
*/
public boolean equals(Object partial) {
if (this == partial) {
return true;
}
if (partial instanceof ReadablePartial == false) {
return false;
}
ReadablePartial other = (ReadablePartial) partial;
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 FieldUtils.equals(getChronology(), other.getChronology());
}
示例3: withPeriodAdded
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
* 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);
}
示例4: getDateTimeMillis
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
public long getDateTimeMillis(
int year, int monthOfYear, int dayOfMonth,
int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
throws IllegalArgumentException {
Chronology base;
if ((base = getBase()) != null) {
return base.getDateTimeMillis(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}
FieldUtils.verifyValueBounds(DateTimeFieldType.hourOfDay(), hourOfDay, 0, 23);
FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59);
FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59);
FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999);
return getDateMidnightMillis(year, monthOfYear, dayOfMonth)
+ hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
+ minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
+ secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
+ millisOfSecond;
}
示例5: set
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
* Set the Month component of the specified time instant.<p>
* If the new month has less total days than the specified
* day of the month, this value is coerced to the nearest
* sane value. e.g.<p>
* 07-31 to month 6 = 06-30<p>
* 03-31 to month 2 = 02-28 or 02-29 depending<p>
*
* @param instant the time instant in millis to update.
* @param month the month (1,12) to update the time to.
* @return the updated time instant.
* @throws IllegalArgumentException if month is invalid
*/
public long set(long instant, int month) {
FieldUtils.verifyValueBounds(this, month, MIN, iMax);
//
int thisYear = iChronology.getYear(instant);
//
int thisDom = iChronology.getDayOfMonth(instant, thisYear);
int maxDom = iChronology.getDaysInYearMonth(thisYear, month);
if (thisDom > maxDom) {
// Quietly force DOM to nearest sane value.
thisDom = maxDom;
}
// Return newly calculated millis value
return iChronology.getYearMonthDayMillis(thisYear, month, thisDom) +
iChronology.getMillisOfDay(instant);
}
示例6: BaseInterval
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
* Constructs an interval from a start instant and a duration.
*
* @param start start of this interval, null means now
* @param duration the duration of this interval, null means zero length
* @throws IllegalArgumentException if the end is before the start
* @throws ArithmeticException if the end instant exceeds the capacity of a long
*/
protected BaseInterval(ReadableInstant start, ReadableDuration duration) {
super();
iChronology = DateTimeUtils.getInstantChronology(start);
iStartMillis = DateTimeUtils.getInstantMillis(start);
long durationMillis = DateTimeUtils.getDurationMillis(duration);
iEndMillis = FieldUtils.safeAdd(iStartMillis, durationMillis);
checkInterval(iStartMillis, iEndMillis);
}
示例7: BasePeriod
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
* Creates a period from the given duration and end point.
*
* @param duration the duration of the interval, null means zero-length
* @param endInstant the interval end, null means now
* @param type which set of fields this period supports, null means standard
*/
protected BasePeriod(ReadableDuration duration, ReadableInstant endInstant, PeriodType type) {
super();
type = checkPeriodType(type);
long durationMillis = DateTimeUtils.getDurationMillis(duration);
long endMillis = DateTimeUtils.getInstantMillis(endInstant);
long startMillis = FieldUtils.safeSubtract(endMillis, durationMillis);
Chronology chrono = DateTimeUtils.getInstantChronology(endInstant);
iType = type;
iValues = chrono.get(this, startMillis, endMillis);
}
示例8: addFieldInto
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
* Adds the value of a field in this period.
*
* @param values the array of values to update
* @param field the field to set
* @param value the value to set
* @throws IllegalArgumentException if field is is null or not supported.
*/
protected void addFieldInto(int[] values, DurationFieldType field, int value) {
int index = indexOf(field);
if (index == -1) {
if (value != 0 || field == null) {
throw new IllegalArgumentException(
"Period does not support field '" + field + "'");
}
} else {
values[index] = FieldUtils.safeAdd(values[index], value);
}
}
示例9: addIndexedField
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
* Adds to the indexed field part of the period.
*
* @param period the period to query
* @param index the index to use
* @param values the array to populate
* @param valueToAdd the value to add
* @return true if the array is updated
* @throws UnsupportedOperationException if not supported
*/
boolean addIndexedField(ReadablePeriod period, int index, int[] values, int valueToAdd) {
if (valueToAdd == 0) {
return false;
}
int realIndex = iIndices[index];
if (realIndex == -1) {
throw new UnsupportedOperationException("Field is not supported");
}
values[realIndex] = FieldUtils.safeAdd(values[realIndex], valueToAdd);
return true;
}
示例10: multipliedBy
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
* Returns a new instance with each element in this period multiplied
* by the specified scalar.
*
* @param scalar the scalar to multiply by, not null
* @return a {@code Period} based on this period with the amounts multiplied by the scalar, never null
* @throws ArithmeticException if the capacity of any field is exceeded
* @since 2.1
*/
public Period multipliedBy(int scalar) {
if (this == ZERO || scalar == 1) {
return this;
}
int[] values = getValues(); // cloned
for (int i = 0; i < values.length; i++) {
values[i] = FieldUtils.safeMultiply(values[i], scalar);
}
return new Period(values, getPeriodType());
}
示例11: equals
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
* A limit chronology is only equal to a limit chronology with the
* same base chronology and limits.
*
* @param obj the object to compare to
* @return true if equal
* @since 1.4
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof LimitChronology == false) {
return false;
}
LimitChronology chrono = (LimitChronology) obj;
return
getBase().equals(chrono.getBase()) &&
FieldUtils.equals(getLowerLimit(), chrono.getLowerLimit()) &&
FieldUtils.equals(getUpperLimit(), chrono.getUpperLimit());
}
示例12: add
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
public long add(long instant, int years) {
if (years == 0) {
return instant;
}
int thisYear = get(instant);
int newYear = FieldUtils.safeAdd(thisYear, years);
return set(instant, newYear);
}
示例13: addWrapField
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
public long addWrapField(long instant, int years) {
if (years == 0) {
return instant;
}
// Return newly calculated millis value
int thisYear = iChronology.getYear(instant);
int wrappedYear = FieldUtils.getWrappedValue
(thisYear, years, iChronology.getMinYear(), iChronology.getMaxYear());
return set(instant, wrappedYear);
}
示例14: set
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
public long set(long instant, int year) {
FieldUtils.verifyValueBounds(this, year, 0, getMaximumValue());
if (getWrappedField().get(instant) < 0) {
year = -year;
}
return super.set(instant, year);
}
示例15: set
import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
* Set the Era component of the specified time instant.
*
* @param instant the time instant in millis to update.
* @param era the era to update the time to.
* @return the updated time instant.
* @throws IllegalArgumentException if era is invalid.
*/
public long set(long instant, int era) {
FieldUtils.verifyValueBounds(this, era, DateTimeConstants.BCE, DateTimeConstants.CE);
int oldEra = get(instant);
if (oldEra != era) {
int year = iChronology.getYear(instant);
return iChronology.setYear(instant, -year);
} else {
return instant;
}
}