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


Java PeriodUnit.doPlus方法代码示例

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


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

示例1: plus

import java.time.calendrical.PeriodUnit; //导入方法依赖的package包/类
@Override
public Instant plus(long amountToAdd, PeriodUnit unit) {

  if (unit instanceof ChronoUnit) {
    switch ((ChronoUnit) unit) {
      case NANOS:
        return plusNanos(amountToAdd);
      case MICROS:
        return plus(amountToAdd / 1000000, (amountToAdd % 1000000) * 1000);
      case MILLIS:
        return plusMillis(amountToAdd);
      case SECONDS:
        return plusSeconds(amountToAdd);
      case MINUTES:
        return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_MINUTE));
      case HOURS:
        return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_HOUR));
      case HALF_DAYS:
        return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY / 2));
      case DAYS:
        return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY));
    }
    throw new DateTimeException("Unsupported unit: " + unit.getName());
  }
  return unit.doPlus(this, amountToAdd);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:27,代码来源:Instant.java

示例2: plus

import java.time.calendrical.PeriodUnit; //导入方法依赖的package包/类
@Override
public Year plus(long amountToAdd, PeriodUnit unit) {

  if (unit instanceof ChronoUnit) {
    switch ((ChronoUnit) unit) {
      case YEARS:
        return plusYears(amountToAdd);
      case DECADES:
        return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
      case CENTURIES:
        return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
      case MILLENNIA:
        return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
      case ERAS:
        return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
    }
    throw new DateTimeException("Unsupported unit: " + unit.getName());
  }
  return unit.doPlus(this, amountToAdd);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:21,代码来源:Year.java

示例3: plus

import java.time.calendrical.PeriodUnit; //导入方法依赖的package包/类
@Override
public YearMonth plus(long amountToAdd, PeriodUnit unit) {

  if (unit instanceof ChronoUnit) {
    switch ((ChronoUnit) unit) {
      case MONTHS:
        return plusMonths(amountToAdd);
      case QUARTER_YEARS:
        return plusYears(amountToAdd / 256).plusMonths((amountToAdd % 256) * 3); // no overflow (256 is
                                                                                 // multiple of 4)
      case HALF_YEARS:
        return plusYears(amountToAdd / 256).plusMonths((amountToAdd % 256) * 6); // no overflow (256 is
                                                                                 // multiple of 2)
      case YEARS:
        return plusYears(amountToAdd);
      case DECADES:
        return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
      case CENTURIES:
        return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
      case MILLENNIA:
        return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
      case ERAS:
        return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
    }
    throw new DateTimeException("Unsupported unit: " + unit.getName());
  }
  return unit.doPlus(this, amountToAdd);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:29,代码来源:YearMonth.java

示例4: plus

import java.time.calendrical.PeriodUnit; //导入方法依赖的package包/类
/**
 * Returns a copy of this time with the specified period added.
 * <p>
 * This method returns a new time based on this time with the specified period added. This can be used to
 * add any period that is defined by a unit, for example to add hours, minutes or seconds. The unit is
 * responsible for the details of the calculation, including the resolution of any edge cases in the
 * calculation.
 * <p>
 * This instance is immutable and unaffected by this method call.
 * 
 * @param amountToAdd the amount of the unit to add to the result, may be negative
 * @param unit the unit of the period to add, not null
 * @return a {@code LocalTime} based on this time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public LocalTime plus(long amountToAdd, PeriodUnit unit) {

  if (unit instanceof ChronoUnit) {
    ChronoUnit f = (ChronoUnit) unit;
    switch (f) {
      case NANOS:
        return plusNanos(amountToAdd);
      case MICROS:
        return plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
      case MILLIS:
        return plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000);
      case SECONDS:
        return plusSeconds(amountToAdd);
      case MINUTES:
        return plusMinutes(amountToAdd);
      case HOURS:
        return plusHours(amountToAdd);
      case HALF_DAYS:
        return plusHours((amountToAdd % 2) * 12);
      case DAYS:
        return this;
    }
    throw new DateTimeException("Unsupported unit: " + unit.getName());
  }
  return unit.doPlus(this, amountToAdd);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:43,代码来源:LocalTime.java

示例5: plus

import java.time.calendrical.PeriodUnit; //导入方法依赖的package包/类
/**
 * Returns a copy of this date with the specified period added.
 * <p>
 * This method returns a new date based on this date with the specified period added. This can be used to
 * add any period that is defined by a unit, for example to add years, months or days. The unit is
 * responsible for the details of the calculation, including the resolution of any edge cases in the
 * calculation.
 * <p>
 * This instance is immutable and unaffected by this method call.
 * 
 * @param amountToAdd the amount of the unit to add to the result, may be negative
 * @param unit the unit of the period to add, not null
 * @return a {@code LocalDate} based on this date with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public LocalDate plus(long amountToAdd, PeriodUnit unit) {

  if (unit instanceof ChronoUnit) {
    ChronoUnit f = (ChronoUnit) unit;
    switch (f) {
      case DAYS:
        return plusDays(amountToAdd);
      case WEEKS:
        return plusWeeks(amountToAdd);
      case MONTHS:
        return plusMonths(amountToAdd);
      case QUARTER_YEARS:
        return plusYears(amountToAdd / 256).plusMonths((amountToAdd % 256) * 3); // no overflow (256 is
                                                                                 // multiple of 4)
      case HALF_YEARS:
        return plusYears(amountToAdd / 256).plusMonths((amountToAdd % 256) * 6); // no overflow (256 is
                                                                                 // multiple of 2)
      case YEARS:
        return plusYears(amountToAdd);
      case DECADES:
        return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
      case CENTURIES:
        return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
      case MILLENNIA:
        return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
      case ERAS:
        return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
    }
    throw new DateTimeException("Unsupported unit: " + unit.getName());
  }
  return unit.doPlus(this, amountToAdd);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:49,代码来源:LocalDate.java

示例6: plus

import java.time.calendrical.PeriodUnit; //导入方法依赖的package包/类
/**
 * Returns a copy of this date-time with the specified period added.
 * <p>
 * This method returns a new date-time based on this date-time with the specified period added. This can be
 * used to add any period that is defined by a unit, for example to add years, months or days. The unit is
 * responsible for the details of the calculation, including the resolution of any edge cases in the
 * calculation.
 * <p>
 * This instance is immutable and unaffected by this method call.
 * 
 * @param amountToAdd the amount of the unit to add to the result, may be negative
 * @param unit the unit of the period to add, not null
 * @return a {@code LocalDateTime} based on this date-time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public LocalDateTime plus(long amountToAdd, PeriodUnit unit) {

  if (unit instanceof ChronoUnit) {
    ChronoUnit f = (ChronoUnit) unit;
    switch (f) {
      case NANOS:
        return plusNanos(amountToAdd);
      case MICROS:
        return plusDays(amountToAdd / MICROS_PER_DAY).plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
      case MILLIS:
        return plusDays(amountToAdd / MILLIS_PER_DAY).plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000);
      case SECONDS:
        return plusSeconds(amountToAdd);
      case MINUTES:
        return plusMinutes(amountToAdd);
      case HOURS:
        return plusHours(amountToAdd);
      case HALF_DAYS:
        return plusDays(amountToAdd / 256).plusHours((amountToAdd % 256) * 12); // no overflow (256 is
                                                                                // multiple of 2)
    }
    return with(this.date.plus(amountToAdd, unit), this.time);
  }
  return unit.doPlus(this, amountToAdd);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:42,代码来源:LocalDateTime.java

示例7: plus

import java.time.calendrical.PeriodUnit; //导入方法依赖的package包/类
/**
 * Returns a copy of this time with the specified period added.
 * <p>
 * This method returns a new time based on this time with the specified period added. This can be used to
 * add any period that is defined by a unit, for example to add hours, minutes or seconds. The unit is
 * responsible for the details of the calculation, including the resolution of any edge cases in the
 * calculation. The offset is not part of the calculation and will be unchanged in the result.
 * <p>
 * This instance is immutable and unaffected by this method call.
 * 
 * @param amountToAdd the amount of the unit to add to the result, may be negative
 * @param unit the unit of the period to add, not null
 * @return an {@code OffsetTime} based on this time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public OffsetTime plus(long amountToAdd, PeriodUnit unit) {

  if (unit instanceof ChronoUnit) {
    return with(this.time.plus(amountToAdd, unit), this.offset);
  }
  return unit.doPlus(this, amountToAdd);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:24,代码来源:OffsetTime.java

示例8: plus

import java.time.calendrical.PeriodUnit; //导入方法依赖的package包/类
/**
 * Returns a copy of this date-time with the specified period added.
 * <p>
 * This method returns a new date-time based on this date-time with the specified period added. This can be
 * used to add any period that is defined by a unit, for example to add years, months or days. The unit is
 * responsible for the details of the calculation, including the resolution of any edge cases in the
 * calculation. The offset is not part of the calculation and will be unchanged in the result.
 * <p>
 * This instance is immutable and unaffected by this method call.
 * 
 * @param amountToAdd the amount of the unit to add to the result, may be negative
 * @param unit the unit of the period to add, not null
 * @return an {@code OffsetDateTime} based on this date-time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public OffsetDateTime plus(long amountToAdd, PeriodUnit unit) {

  if (unit instanceof ChronoUnit) {
    return with(this.dateTime.plus(amountToAdd, unit), this.offset);
  }
  return unit.doPlus(this, amountToAdd);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:24,代码来源:OffsetDateTime.java

示例9: plus

import java.time.calendrical.PeriodUnit; //导入方法依赖的package包/类
/**
 * Returns a copy of this date-time with the specified period added.
 * <p>
 * This method returns a new date-time based on this date-time with the specified period added. This can be
 * used to add any period that is defined by a unit, for example to add years, months or days. The unit is
 * responsible for the details of the calculation, including the resolution of any edge cases in the
 * calculation.
 * <p>
 * The calculation for date and time units differ.
 * <p>
 * Date units operate on the local time-line. The period is first added to the local date-time, then
 * converted back to a zoned date-time using the zone ID. The conversion uses
 * {@link #ofLocal(LocalDateTime, ZoneId, ZoneOffset)} with the offset before the addition.
 * <p>
 * Time units operate on the instant time-line. The period is first added to the local date-time, then
 * converted back to a zoned date-time using the zone ID. The conversion uses
 * {@link #ofInstant(LocalDateTime, ZoneOffset, ZoneId)} with the offset before the addition.
 * <p>
 * This instance is immutable and unaffected by this method call.
 * 
 * @param amountToAdd the amount of the unit to add to the result, may be negative
 * @param unit the unit of the period to add, not null
 * @return a {@code ZonedDateTime} based on this date-time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public ZonedDateTime plus(long amountToAdd, PeriodUnit unit) {

  if (unit instanceof ChronoUnit) {
    ChronoUnit u = (ChronoUnit) unit;
    if (u.isDateUnit()) {
      return resolveLocal(this.dateTime.plus(amountToAdd, unit));
    } else {
      return resolveInstant(this.dateTime.plus(amountToAdd, unit));
    }
  }
  return unit.doPlus(this, amountToAdd);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:39,代码来源:ZonedDateTime.java

示例10: plus

import java.time.calendrical.PeriodUnit; //导入方法依赖的package包/类
/**
 * Returns a copy of this date with the specified period added.
 * <p>
 * This method returns a new date based on this date with the specified period added. This can be used to
 * add any period that is defined by a unit, for example to add years, months or days. The unit is
 * responsible for the details of the calculation, including the resolution of any edge cases in the
 * calculation. The offset is not part of the calculation and will be unchanged in the result.
 * <p>
 * This instance is immutable and unaffected by this method call.
 * 
 * @param amountToAdd the amount of the unit to add to the result, may be negative
 * @param unit the unit of the period to add, not null
 * @return an {@code OffsetDate} based on this date with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public OffsetDate plus(long amountToAdd, PeriodUnit unit) {

  if (unit instanceof ChronoUnit) {
    return with(this.date.plus(amountToAdd, unit), this.offset);
  }
  return unit.doPlus(this, amountToAdd);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:24,代码来源:OffsetDate.java


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