gpt4 book ai didi

java.time.YearMonth.compareTo()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 23:36:40 29 4
gpt4 key购买 nike

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

YearMonth.compareTo介绍

[英]Compares this year-month to another year-month.

The comparison is based first on the value of the year, then on the value of the month. It is "consistent with equals", as defined by Comparable.
[中]将今年的月份与另一年的月份进行比较。
比较首先基于年份的价值,然后基于月份的价值。它是“与平等相一致的”,正如Comparable所定义的那样。

代码示例

代码示例来源:origin: pholser/junit-quickcheck

/**
 * <p>Tells this generator to produce values within a specified
 * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max()
 * maximum}, inclusive, with uniform distribution.</p>
 *
 * <p>If an endpoint of the range is not specified, the generator will use
 * dates with values of either {@code YearMonth(Year#MIN_VALUE, 1)} or
 * {@code YearMonth(Year#MAX_VALUE, 12)} as appropriate.</p>
 *
 * <p>{@link InRange#format()} describes
 * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to
 * interpret the range's endpoints}.</p>
 *
 * @param range annotation that gives the range's constraints
 */
public void configure(InRange range) {
  DateTimeFormatter formatter = DateTimeFormatter.ofPattern(range.format());
  if (!defaultValueOf(InRange.class, "min").equals(range.min()))
    min = YearMonth.parse(range.min(), formatter);
  if (!defaultValueOf(InRange.class, "max").equals(range.max()))
    max = YearMonth.parse(range.max(), formatter);
  if (min.compareTo(max) > 0)
    throw new IllegalArgumentException(String.format("bad range, %s > %s", range.min(), range.max()));
}

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

/**
 * Is this year-month after the specified year-month.
 *
 * @param other  the other year-month to compare to, not null
 * @return true if this is after the specified year-month
 */
public boolean isAfter(YearMonth other) {
  return compareTo(other) > 0;
}

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

/**
 * Is this year-month before the specified year-month.
 *
 * @param other  the other year-month to compare to, not null
 * @return true if this point is before the specified year-month
 */
public boolean isBefore(YearMonth other) {
  return compareTo(other) < 0;
}

代码示例来源:origin: io.permazen/permazen-coreapi

@Override
public int compare(YearMonth yearMonth1, YearMonth yearMonth2) {
  return yearMonth1.compareTo(yearMonth2);
}

代码示例来源:origin: org.jsimpledb/jsimpledb-coreapi

@Override
public int compare(YearMonth yearMonth1, YearMonth yearMonth2) {
  return yearMonth1.compareTo(yearMonth2);
}

代码示例来源:origin: com.pholser/junit-quickcheck-generators

/**
 * <p>Tells this generator to produce values within a specified
 * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max()
 * maximum}, inclusive, with uniform distribution.</p>
 *
 * <p>If an endpoint of the range is not specified, the generator will use
 * dates with values of either {@code YearMonth(Year#MIN_VALUE, 1)} or
 * {@code YearMonth(Year#MAX_VALUE, 12)} as appropriate.</p>
 *
 * <p>{@link InRange#format()} describes
 * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to
 * interpret the range's endpoints}.</p>
 *
 * @param range annotation that gives the range's constraints
 */
public void configure(InRange range) {
  DateTimeFormatter formatter = DateTimeFormatter.ofPattern(range.format());
  if (!defaultValueOf(InRange.class, "min").equals(range.min()))
    min = YearMonth.parse(range.min(), formatter);
  if (!defaultValueOf(InRange.class, "max").equals(range.max()))
    max = YearMonth.parse(range.max(), formatter);
  if (min.compareTo(max) > 0)
    throw new IllegalArgumentException(String.format("bad range, %s > %s", range.min(), range.max()));
}

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com