/** * <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())); }
/** * 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; }
/** * 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; }
@Override public int compare(YearMonth yearMonth1, YearMonth yearMonth2) { return yearMonth1.compareTo(yearMonth2); }
@Override public int compare(YearMonth yearMonth1, YearMonth yearMonth2) { return yearMonth1.compareTo(yearMonth2); }
/** * <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())); }