Skip to content

Commit

Permalink
Use standard value range values
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Jul 4, 2020
1 parent 04fa017 commit dbc3d9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
16 changes: 9 additions & 7 deletions src/main/java/net/fortuna/ical4j/model/NumberList.java
Expand Up @@ -34,6 +34,7 @@
import net.fortuna.ical4j.util.Numbers;

import java.io.Serializable;
import java.time.temporal.ValueRange;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -50,9 +51,7 @@ public class NumberList extends ArrayList<Integer> implements Serializable {

private static final long serialVersionUID = -1667481795613729889L;

private final int minValue;

private final int maxValue;
private final ValueRange range;

private final boolean allowsNegativeValues;

Expand All @@ -70,8 +69,11 @@ public NumberList() {
* @param allowsNegativeValues indicates whether negative values are allowed
*/
public NumberList(int minValue, int maxValue, boolean allowsNegativeValues) {
this.minValue = minValue;
this.maxValue = maxValue;
this(ValueRange.of(minValue, maxValue), allowsNegativeValues);
}

public NumberList(ValueRange range, boolean allowsNegativeValues) {
this.range = range;
this.allowsNegativeValues = allowsNegativeValues;
}

Expand Down Expand Up @@ -106,9 +108,9 @@ public final boolean add(final Integer aNumber) {
}
abs = Math.abs(abs);
}
if (abs < minValue || abs > maxValue) {
if (!range.isValidIntValue(abs)) {
throw new IllegalArgumentException(
"Value not in range [" + minValue + ".." + maxValue + "]: " + aNumber);
"Value not in range [" + range.getMinimum() + ".." + range.getMaximum() + "]: " + aNumber);
}
return super.add(aNumber);
}
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/net/fortuna/ical4j/model/Recur.java
Expand Up @@ -40,6 +40,7 @@
import java.io.IOException;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalUnit;
Expand Down Expand Up @@ -164,21 +165,21 @@ public enum Frequency {

private Integer interval;

private final List<Integer> secondList = new NumberList(0, 59, false);
private final List<Integer> secondList = new NumberList(ChronoField.SECOND_OF_MINUTE.range(), false);

private final List<Integer> minuteList = new NumberList(0, 59, false);
private final List<Integer> minuteList = new NumberList(ChronoField.MINUTE_OF_HOUR.range(), false);

private final List<Integer> hourList = new NumberList(0, 23, false);
private final List<Integer> hourList = new NumberList(ChronoField.HOUR_OF_DAY.range(), false);

private final List<WeekDay> dayList = new WeekDayList();

private final List<Integer> monthDayList = new NumberList(1, 31, true);
private final List<Integer> monthDayList = new NumberList(ChronoField.DAY_OF_MONTH.range(), true);

private final List<Integer> yearDayList = new NumberList(1, 366, true);
private final List<Integer> yearDayList = new NumberList(ChronoField.DAY_OF_YEAR.range(), true);

private final List<Integer> weekNoList = new NumberList(1, 53, true);
private final List<Integer> weekNoList = new NumberList(ChronoField.ALIGNED_WEEK_OF_YEAR.range(), true);

private final List<Integer> monthList = new NumberList(1, 12, false);
private final List<Integer> monthList = new NumberList(ChronoField.MONTH_OF_YEAR.range(), false);

private final List<Integer> setPosList = new NumberList(1, 366, true);

Expand Down

0 comments on commit dbc3d9e

Please sign in to comment.