• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java FieldUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.joda.time.field.FieldUtils的典型用法代码示例。如果您正苦于以下问题:Java FieldUtils类的具体用法?Java FieldUtils怎么用?Java FieldUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FieldUtils类属于org.joda.time.field包,在下文中一共展示了FieldUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:41,代码来源:BaseSingleFieldPeriod.java


示例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());
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:26,代码来源:AbstractPartial.java


示例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);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:31,代码来源:Partial.java


示例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;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:22,代码来源:BasicChronology.java


示例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);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:29,代码来源:BasicMonthOfYearDateTimeField.java


示例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);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:17,代码来源:BaseInterval.java


示例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);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:18,代码来源:BasePeriod.java


示例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);
    }
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:20,代码来源:BasePeriod.java


示例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;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:22,代码来源:PeriodType.java


示例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());
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:20,代码来源:Period.java


示例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());
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:22,代码来源:LimitChronology.java


示例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);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:9,代码来源:BasicYearDateTimeField.java


示例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);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:11,代码来源:BasicYearDateTimeField.java


示例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);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:8,代码来源:ISOYearOfEraDateTimeField.java


示例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;
    }
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:20,代码来源:GJEraDateTimeField.java


示例16: withPeriodAdded

import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
 * Returns a copy of this month-day 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 #plusMonths(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, never null
 * @throws ArithmeticException if the new date-time exceeds the capacity
 */
public MonthDay 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 MonthDay(this, newValues);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:32,代码来源:MonthDay.java


示例17: normalizedStandard

import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
 * Normalizes this period using standard rules, assuming a 12 month year,
 * 7 day week, 24 hour day, 60 minute hour and 60 second minute,
 * providing control over how the result is split into fields.
 * <p>
 * This method allows you to normalize a period.
 * However to achieve this it makes the assumption that all years are
 * 12 months, all weeks are 7 days, all days are 24 hours,
 * all hours are 60 minutes and all minutes are 60 seconds. This is not
 * true when daylight savings time is considered, and may also not be true
 * for some chronologies. However, it is included as it is a useful operation
 * for many applications and business rules.
 * <p>
 * If the period contains years or months, then the months will be
 * normalized to be between 0 and 11. The days field and below will be
 * normalized as necessary, however this will not overflow into the months
 * field. Thus a period of 1 year 15 months will normalize to 2 years 3 months.
 * But a period of 1 month 40 days will remain as 1 month 40 days.
 * <p>
 * The PeriodType parameter controls how the result is created. It allows
 * you to omit certain fields from the result if desired. For example,
 * you may not want the result to include weeks, in which case you pass
 * in <code>PeriodType.yearMonthDayTime()</code>.
 * 
 * @param type  the period type of the new period, null means standard type
 * @return a normalized period equivalent to this period
 * @throws ArithmeticException if any field is too large to be represented
 * @throws UnsupportedOperationException if this period contains non-zero
 *  years or months but the specified period type does not support them
 * @since 1.5
 */
public Period normalizedStandard(PeriodType type) {
    long millis = getMillis();  // no overflow can happen, even with Integer.MAX_VALUEs
    millis += (((long) getSeconds()) * ((long) DateTimeConstants.MILLIS_PER_SECOND));
    millis += (((long) getMinutes()) * ((long) DateTimeConstants.MILLIS_PER_MINUTE));
    millis += (((long) getHours()) * ((long) DateTimeConstants.MILLIS_PER_HOUR));
    millis += (((long) getDays()) * ((long) DateTimeConstants.MILLIS_PER_DAY));
    millis += (((long) getWeeks()) * ((long) DateTimeConstants.MILLIS_PER_WEEK));
    Period result = new Period(millis, DateTimeUtils.getPeriodType(type), ISOChronology.getInstanceUTC());
    int years = getYears();
    int months = getMonths();
    if (years != 0 || months != 0) {
        years = FieldUtils.safeAdd(years, months / 12);
        months = months % 12;
        if (years != 0) {
            result = result.withYears(years);
        }
        if (months != 0) {
            result = result.withMonths(months);
        }
    }
    return result;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:54,代码来源:Period.java


示例18: withDurationAdded

import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
 * Returns a new duration with this length plus that specified multiplied by the scalar.
 * This instance is immutable and is not altered.
 * <p>
 * If the addition is zero, this instance is returned.
 * 
 * @param durationToAdd  the duration to add to this one
 * @param scalar  the amount of times to add, such as -1 to subtract once
 * @return the new duration instance
 */
public Duration withDurationAdded(long durationToAdd, int scalar) {
    if (durationToAdd == 0 || scalar == 0) {
        return this;
    }
    long add = FieldUtils.safeMultiply(durationToAdd, scalar);
    long duration = FieldUtils.safeAdd(getMillis(), add);
    return new Duration(duration);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:19,代码来源:Duration.java


示例19: getDurationMillis

import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
 * Gets the duration of the string using the standard type.
 * This matches the toString() method of ReadableDuration.
 * 
 * @param object  the String to convert, must not be null
 * @throws ClassCastException if the object is invalid
 */
public long getDurationMillis(Object object) {
    // parse here because duration could be bigger than the int supported
    // by the period parser
    String original = (String) object;
    String str = original;
    int len = str.length();
    if (len >= 4 &&
        (str.charAt(0) == 'P' || str.charAt(0) == 'p') &&
        (str.charAt(1) == 'T' || str.charAt(1) == 't') &&
        (str.charAt(len - 1) == 'S' || str.charAt(len - 1) == 's')) {
        // ok
    } else {
        throw new IllegalArgumentException("Invalid format: \"" + original + '"');
    }
    str = str.substring(2, len - 1);
    int dot = -1;
    for (int i = 0; i < str.length(); i++) {
        if ((str.charAt(i) >= '0' && str.charAt(i) <= '9') ||
            (i == 0 && str.charAt(0) == '-')) {
            // ok
        } else if (i > 0 && str.charAt(i) == '.' && dot == -1) {
            // ok
            dot = i;
        } else {
            throw new IllegalArgumentException("Invalid format: \"" + original + '"');
        }
    }
    long millis = 0, seconds = 0;
    if (dot > 0) {
        seconds = Long.parseLong(str.substring(0, dot));
        str = str.substring(dot + 1);
        if (str.length() != 3) {
            str = (str + "000").substring(0, 3);
        }
        millis = Integer.parseInt(str);
    } else {
        seconds = Long.parseLong(str);
    }
    if (seconds < 0) {
        return FieldUtils.safeAdd(FieldUtils.safeMultiply(seconds, 1000), -millis);
    } else {
        return FieldUtils.safeAdd(FieldUtils.safeMultiply(seconds, 1000), millis);
    }
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:52,代码来源:StringConverter.java


示例20: withPeriodAdded

import org.joda.time.field.FieldUtils; //导入依赖的package包/类
/**
 * Returns a copy of this date with the specified period added.
 * <p>
 * If the addition is zero, then <code>this</code> is returned.
 * <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 #plusYears(int)}.
 * <p>
 * Unsupported time fields are ignored, thus adding a period of 24 hours
 * will not have any effect.
 *
 * @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 date with the period added
 * @throws ArithmeticException if the result exceeds the internal capacity
 */
public LocalDate withPeriodAdded(ReadablePeriod period, int scalar) {
    if (period == null || scalar == 0) {
        return this;
    }
    long instant = getLocalMillis();
    Chronology chrono = getChronology();
    for (int i = 0; i < period.size(); i++) {
        long value = FieldUtils.safeMultiply(period.getValue(i), scalar);
        DurationFieldType type = period.getFieldType(i);
        if (isSupported(type)) {
            instant = type.getField(chrono).add(instant, value);
        }
    }
    return withLocalMillis(instant);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:34,代码来源:LocalDate.java



注:本文中的org.joda.time.field.FieldUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StringSupport类代码示例发布时间:2022-05-22
下一篇:
Java GlyphRun类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap