本文整理了Java中java.time.YearMonth.compareTo()
方法的一些代码示例,展示了YearMonth.compareTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YearMonth.compareTo()
方法的具体详情如下:
包路径:java.time.YearMonth
类名称: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()));
}
内容来源于网络,如有侵权,请联系作者删除!