Skip to content

Commit

Permalink
Support building new recur definitions based on existing
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Apr 10, 2022
1 parent 16e2cb1 commit 9bdf5e3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/net/fortuna/ical4j/model/Recur.java
Expand Up @@ -1134,6 +1134,26 @@ private void readObject(final java.io.ObjectInputStream stream) throws IOExcepti
log = LoggerFactory.getLogger(Recur.class);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Recur recur = (Recur) o;
return frequency == recur.frequency && skip == recur.skip && Objects.equals(until, recur.until) &&
rscale == recur.rscale && Objects.equals(count, recur.count) && Objects.equals(interval, recur.interval) &&
Objects.equals(secondList, recur.secondList) && Objects.equals(minuteList, recur.minuteList) &&
Objects.equals(hourList, recur.hourList) && Objects.equals(dayList, recur.dayList) &&
Objects.equals(monthDayList, recur.monthDayList) && Objects.equals(yearDayList, recur.yearDayList) &&
Objects.equals(weekNoList, recur.weekNoList) && Objects.equals(monthList, recur.monthList) &&
Objects.equals(setPosList, recur.setPosList) && weekStartDay == recur.weekStartDay;
}

@Override
public int hashCode() {
return Objects.hash(frequency, skip, until, rscale, count, interval, secondList, minuteList, hourList, dayList,
monthDayList, yearDayList, weekNoList, monthList, setPosList, weekStartDay);
}

/**
* Support for building Recur instances.
*/
Expand Down Expand Up @@ -1171,6 +1191,28 @@ public static class Builder {

private WeekDay.Day weekStartDay;

public Builder() {
}

public Builder(Recur recur) {
this.frequency = recur.frequency;
this.rscale = recur.rscale;
this.skip = recur.skip;
this.until = recur.until;
this.count = recur.count;
this.interval = recur.interval;
this.secondList = recur.secondList;
this.minuteList = recur.minuteList;
this.hourList = recur.hourList;
this.dayList = recur.dayList;
this.monthDayList = recur.monthDayList;
this.yearDayList = recur.yearDayList;
this.weekNoList = recur.weekNoList;
this.monthList = recur.monthList;
this.setPosList = recur.setPosList;
this.weekStartDay = recur.weekStartDay;
}

public Builder frequency(Frequency frequency) {
this.frequency = frequency;
return this;
Expand Down
3 changes: 3 additions & 0 deletions src/test/groovy/net/fortuna/ical4j/model/RecurSpec.groovy
Expand Up @@ -446,6 +446,9 @@ class RecurSpec extends Specification {

then: 'result is as expected'
recurDaily as String == "FREQ=DAILY;WKST=MO;UNTIL=20050307;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR"

and: 'a new builder based on the recur generates the same definition'
new Recur.Builder(recurDaily).build() == recurDaily
}

def 'test Recur.getNextDate() with different recurrence rules'() {
Expand Down

0 comments on commit 9bdf5e3

Please sign in to comment.