/** * <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 * Years with values of either {@code Year#MIN_VALUE} or * {@code Year#MAX_VALUE} 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 = Year.parse(range.min(), formatter); if (!defaultValueOf(InRange.class, "max").equals(range.max())) max = Year.parse(range.max(), formatter); if (min.compareTo(max) > 0) throw new IllegalArgumentException(String.format("bad range, %s > %s", range.min(), range.max())); }
@Override public int compare(Year year1, Year year2) { return year1.compareTo(year2); }
@Override public int compare(Year year1, Year year2) { return year1.compareTo(year2); }
@Override public YearPreconditions isGreaterThan(Year value) throws IllegalArgumentException { if (parameter.compareTo(value) > 0) return self; return throwException(IllegalArgumentException.class, String.format("%s must be less than %s.\n" + "Actual: %s", name, value, parameter)); }
@Override public YearPreconditions isLessThanOrEqualTo(Year value) throws IllegalArgumentException { if (parameter.compareTo(value) <= 0) return self; return throwException(IllegalArgumentException.class, String.format("%s must be less than or equal to %s.\n" + "Actual: %s", name, value, parameter)); }
@Override public YearPreconditions isLessThan(Year value, String name) throws IllegalArgumentException { if (parameter.compareTo(value) < 0) return self; return throwException(IllegalArgumentException.class, String.format("%s must be less than %s.\n" + "Expected: %s\n" + "Actual : %s", this.name, name, value, parameter)); }
@Override public YearPreconditions isGreaterThan(Year value, String name) throws IllegalArgumentException { if (parameter.compareTo(value) > 0) return self; return throwException(IllegalArgumentException.class, String.format("%s must be greater than %s.\n" + "Expected: %s\n" + "Actual : %s", this.name, name, value, parameter)); }
@Override public YearPreconditions isLessThan(Year value) throws IllegalArgumentException { if (parameter.compareTo(value) < 0) return self; return throwException(IllegalArgumentException.class, String.format("%s must be less than %s.\n" + "Actual: %s", name, value, parameter)); }
@Override public YearPreconditions isLessThanOrEqualTo(Year value, String name) throws IllegalArgumentException { if (parameter.compareTo(value) <= 0) return self; return throwException(IllegalArgumentException.class, String.format("%s must be less than or equal to %s.\n" + "Expected: %s\n" + "Actual : %s", this.name, name, value, parameter)); }
@Override public YearPreconditions isGreaterThanOrEqualTo(Year value, String name) throws IllegalArgumentException { if (parameter.compareTo(value) >= 0) return self; return throwException(IllegalArgumentException.class, String.format("%s must be greater than or equal to %s.\n" + "Expected: %s\n" + "Actual : %s", this.name, name, value, parameter)); }
@Override public YearPreconditions isGreaterThanOrEqualTo(Year value) throws IllegalArgumentException { if (parameter.compareTo(value) >= 0) return self; return throwException(IllegalArgumentException.class, String.format("%s must be greater than or equal to %s.\n" + "Actual: %s", name, value, parameter)); }
/** * <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 * Years with values of either {@code Year#MIN_VALUE} or * {@code Year#MAX_VALUE} 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 = Year.parse(range.min(), formatter); if (!defaultValueOf(InRange.class, "max").equals(range.max())) max = Year.parse(range.max(), formatter); if (min.compareTo(max) > 0) throw new IllegalArgumentException(String.format("bad range, %s > %s", range.min(), range.max())); }