java.time.Period.multipliedBy()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中java.time.Period.multipliedBy()方法的一些代码示例,展示了Period.multipliedBy()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Period.multipliedBy()方法的具体详情如下:
包路径:java.time.Period
类名称:Period
方法名:multipliedBy

Period.multipliedBy介绍

[英]Returns a new instance with each element in this period multiplied by the specified scalar.

This simply multiplies each field, years, months, days and normalized time, by the scalar. No normalization is performed.
[中]

代码示例

代码示例来源:origin: org.codehaus.groovy/groovy-datetime

/**
 * Supports the multiply operator; equivalent to calling the {@link java.time.Period#multipliedBy(int)} method.
 *
 * @param self   a Period
 * @param scalar a scalar to multiply each unit by
 * @return a Period
 * @since 2.5.0
 */
public static Period multiply(final Period self, int scalar) {
  return self.multipliedBy(scalar);
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Returns a new instance with each amount in this period negated.
 *
 * @return a {@code Period} based on this period with the amounts negated, not null
 * @throws ArithmeticException if numeric overflow occurs
 */
public Period negated() {
  return multipliedBy(-1);
}

代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core

private TemporalAmount multiply(TemporalAmount first, int second) {
  if (first instanceof Period) {
    return ((Period) first).multipliedBy(second);
  } else if (first instanceof Duration) {
    return ((Duration)first).multipliedBy(second);
  } else {
    throw new DMNRuntimeException(String.format("Cannot multiply '%s' by '%s'", first, second));
  }
}

代码示例来源:origin: goldmansachs/jdmn

private TemporalAmount multiply(TemporalAmount first, int second) {
  if (first instanceof Period) {
    return ((Period) first).multipliedBy(second);
  } else if (first instanceof Duration) {
    return ((Duration)first).multipliedBy(second);
  } else {
    throw new DMNRuntimeException(String.format("Cannot multiply '%s' by '%s'", first, second));
  }
}

代码示例来源:origin: metatron-app/metatron-discovery

/**
 * Parses an amount of time in the format {@code PyYmMwWdDThHmMsS}.
 * @param text the amount of time to parse
 * @return the parsed amount of time
 */
public static PeriodDuration parse(final CharSequence text) {
 final Matcher matcher = Pattern.compile("([+-]?)P([^T]*)T?(.*)").matcher(text);
 if (matcher.matches()) {
  final int negate = "-".equals(matcher.group(1)) ? -1 : 1;
  final Period period = matcher.group(2).isEmpty() ? Period.ZERO : Period.parse("P" + matcher.group(2));
  final Duration duration = matcher.group(3).isEmpty() ? Duration.ZERO : Duration.parse("PT" + matcher.group(3));
  return new PeriodDuration(period.multipliedBy(negate), duration.multipliedBy(negate));
 }
 throw new DateTimeParseException("Text cannot be parsed to a PeriodDuration", text, 0);
}

代码示例来源:origin: org.threeten/threeten-extra

/**
 * Returns an instance with the amount multiplied by the specified scalar.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param scalar  the scalar to multiply by, not null
 * @return the amount multiplied by the specified scalar, not null
 * @throws ArithmeticException if numeric overflow occurs
 */
public PeriodDuration multipliedBy(int scalar) {
  if (scalar == 1) {
    return this;
  }
  return of(period.multipliedBy(scalar), duration.multipliedBy(scalar));
}

代码示例来源:origin: OpenGamma/Strata

public BasicFixedLeg(
  LocalDate curveSpotDate,
  LocalDate maturityDate,
  Period swapInterval,
  DayCount swapDCC,
  DayCount curveDcc,
  BusinessDayAdjustment busAdj,
  ReferenceData refData) {
 List<LocalDate> list = new ArrayList<>();
 LocalDate tDate = maturityDate;
 int step = 1;
 while (tDate.isAfter(curveSpotDate)) {
  list.add(tDate);
  tDate = maturityDate.minus(swapInterval.multipliedBy(step++));
 }
 // remove spotDate from list, if it ends up there
 list.remove(curveSpotDate);
 nPayment = list.size();
 swapPaymentTime = new double[nPayment];
 yearFraction = new double[nPayment];
 LocalDate prev = curveSpotDate;
 int j = nPayment - 1;
 for (int i = 0; i < nPayment; i++, j--) {
  LocalDate current = list.get(j);
  LocalDate adjCurr = busAdj.adjust(current, refData);
  yearFraction[i] = swapDCC.relativeYearFraction(prev, adjCurr);
  swapPaymentTime[i] = curveDcc.relativeYearFraction(curveSpotDate, adjCurr); // Payment times always good business days
  prev = adjCurr;
 }
}

代码示例来源:origin: OpenGamma/Strata

.frequency(Frequency.of(frequency.getPeriod().multipliedBy(groupSize)))
.rollConvention(rollConvention)
.build();

代码示例来源:origin: zavtech/morpheus-core

@Override
public List<Range<LocalDate>> split(int splitThreshold) {
  final int[] segmentSteps = getSegmentSteps((int)estimateSize());
  if (segmentSteps[0] < splitThreshold) {
    return Collections.singletonList(this);
  } else {
    final Period stepSize = step;
    final List<Range<LocalDate>> segments = new ArrayList<>();
    for (int i=0; i<segmentSteps.length; ++i) {
      final Period segmentSize = stepSize.multipliedBy(segmentSteps[i]);
      if (i == 0) {
        final LocalDate end = isAscending() ? start().plus(segmentSize) : start().minus(segmentSize);
        final Range<LocalDate> range = Range.of(start(), end, step, excludes);
        segments.add(range);
      } else {
        final Range<LocalDate> previous = segments.get(i-1);
        final LocalDate end = isAscending() ? previous.end().plus(segmentSize) : previous.end().minus(segmentSize);
        final Range<LocalDate> next = Range.of(previous.end(), end, step, excludes);
        segments.add(next);
      }
    }
    return segments;
  }
}

代码示例来源:origin: OpenGamma/Strata

Period newFrequency = frequency.getPeriod().multipliedBy(groupSize);
throw new ScheduleException(
  "Unable to merge schedule, firstRegularStartDate {} and lastRegularEndDate {} cannot be used to " +
 .frequency(Frequency.of(frequency.getPeriod().multipliedBy(groupSize)))
 .rollConvention(rollConvention)
 .build();

相关文章