当前位置: 首页>>代码示例>>Java>>正文


Java FieldUtils.safeMultiply方法代码示例

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


在下文中一共展示了FieldUtils.safeMultiply方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: forOffsetHoursMinutes

import org.joda.time.field.FieldUtils; //导入方法依赖的package包/类
/**
 * Gets a time zone instance for the specified offset to UTC in hours and minutes.
 * This method assumes 60 minutes in an hour, and standard length minutes.
 * <p>
 * This factory is a convenient way of constructing zones with a fixed offset.
 * The minutes value is always positive and in the range 0 to 59.
 * If constructed with the values (-2, 30), the resulting zone is '-02:30'.
 * 
 * @param hoursOffset  the offset in hours from UTC
 * @param minutesOffset  the offset in minutes from UTC, must be between 0 and 59 inclusive
 * @return the DateTimeZone object for the offset
 * @throws IllegalArgumentException if the offset or minute is too large or too small
 */
public static DateTimeZone forOffsetHoursMinutes(int hoursOffset, int minutesOffset) throws IllegalArgumentException {
    if (hoursOffset == 0 && minutesOffset == 0) {
        return DateTimeZone.UTC;
    }
    if (minutesOffset < 0 || minutesOffset > 59) {
        throw new IllegalArgumentException("Minutes out of range: " + minutesOffset);
    }
    int offset = 0;
    try {
        int hoursInMinutes = FieldUtils.safeMultiply(hoursOffset, 60);
        if (hoursInMinutes < 0) {
            minutesOffset = FieldUtils.safeAdd(hoursInMinutes, -minutesOffset);
        } else {
            minutesOffset = FieldUtils.safeAdd(hoursInMinutes, minutesOffset);
        }
        offset = FieldUtils.safeMultiply(minutesOffset, DateTimeConstants.MILLIS_PER_MINUTE);
    } catch (ArithmeticException ex) {
        throw new IllegalArgumentException("Offset is too large");
    }
    return forOffsetMillis(offset);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:35,代码来源:DateTimeZone.java

示例2: 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

示例3: 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

示例4: 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

示例5: standardDays

import org.joda.time.field.FieldUtils; //导入方法依赖的package包/类
/**
 * Create a duration with the specified number of days assuming that
 * there are the standard number of milliseconds in a day.
 * <p>
 * This method assumes that there are 24 hours in a day,
 * 60 minutes in an hour, 60 seconds in a minute and 1000 milliseconds in
 * a second. This will be true for most days, however days with Daylight
 * Savings changes will not have 24 hours, so use this method with care.
 * <p>
 * A Duration is a representation of an amount of time. If you want to express
 * the concepts of 'days' you should consider using the {@link Days} class.
 *
 * @param days  the number of standard days in this duration
 * @return the duration, never null
 * @throws ArithmeticException if the days value is too large
 * @since 1.6
 */
public static Duration standardDays(long days) {
    if (days == 0) {
        return ZERO;
    }
    return new Duration(FieldUtils.safeMultiply(days, DateTimeConstants.MILLIS_PER_DAY));
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:24,代码来源:Duration.java

示例6: standardHours

import org.joda.time.field.FieldUtils; //导入方法依赖的package包/类
/**
 * Create a duration with the specified number of hours assuming that
 * there are the standard number of milliseconds in an hour.
 * <p>
 * This method assumes that there are 60 minutes in an hour,
 * 60 seconds in a minute and 1000 milliseconds in a second.
 * All currently supplied chronologies use this definition.
 * <p>
 * A Duration is a representation of an amount of time. If you want to express
 * the concepts of 'hours' you should consider using the {@link Hours} class.
 *
 * @param hours  the number of standard hours in this duration
 * @return the duration, never null
 * @throws ArithmeticException if the hours value is too large
 * @since 1.6
 */
public static Duration standardHours(long hours) {
    if (hours == 0) {
        return ZERO;
    }
    return new Duration(FieldUtils.safeMultiply(hours, DateTimeConstants.MILLIS_PER_HOUR));
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:23,代码来源:Duration.java

示例7: standardMinutes

import org.joda.time.field.FieldUtils; //导入方法依赖的package包/类
/**
 * Create a duration with the specified number of minutes assuming that
 * there are the standard number of milliseconds in a minute.
 * <p>
 * This method assumes that there are 60 seconds in a minute and
 * 1000 milliseconds in a second.
 * All currently supplied chronologies use this definition.
 * <p>
 * A Duration is a representation of an amount of time. If you want to express
 * the concepts of 'minutes' you should consider using the {@link Minutes} class.
 *
 * @param minutes  the number of standard minutes in this duration
 * @return the duration, never null
 * @throws ArithmeticException if the minutes value is too large
 * @since 1.6
 */
public static Duration standardMinutes(long minutes) {
    if (minutes == 0) {
        return ZERO;
    }
    return new Duration(FieldUtils.safeMultiply(minutes, DateTimeConstants.MILLIS_PER_MINUTE));
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:23,代码来源:Duration.java

示例8: standardSeconds

import org.joda.time.field.FieldUtils; //导入方法依赖的package包/类
/**
 * Create a duration with the specified number of seconds assuming that
 * there are the standard number of milliseconds in a second.
 * <p>
 * This method assumes that there are 1000 milliseconds in a second.
 * All currently supplied chronologies use this definition.
 * <p>
 * A Duration is a representation of an amount of time. If you want to express
 * the concepts of 'seconds' you should consider using the {@link Seconds} class.
 *
 * @param seconds  the number of standard seconds in this duration
 * @return the duration, never null
 * @throws ArithmeticException if the seconds value is too large
 * @since 1.6
 */
public static Duration standardSeconds(long seconds) {
    if (seconds == 0) {
        return ZERO;
    }
    return new Duration(FieldUtils.safeMultiply(seconds, DateTimeConstants.MILLIS_PER_SECOND));
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:22,代码来源:Duration.java


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