Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #505 from ical4j/develop
Support for non-Gregorian recurrences
- Loading branch information
Showing
19 changed files
with
616 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package net.fortuna.ical4j.model; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Defines a month of the year, which may be a leap-month in some calendaring systems. | ||
*/ | ||
public class Month implements Serializable { | ||
|
||
private final int monthOfYear; | ||
|
||
private final boolean leapMonth; | ||
|
||
public Month(int monthOfYear) { | ||
this(monthOfYear, false); | ||
} | ||
|
||
public Month(int monthOfYear, boolean leapMonth) { | ||
this.monthOfYear = monthOfYear; | ||
this.leapMonth = leapMonth; | ||
} | ||
|
||
public int getMonthOfYear() { | ||
return monthOfYear; | ||
} | ||
|
||
public boolean isLeapMonth() { | ||
return leapMonth; | ||
} | ||
|
||
public static Month parse(String monthString) { | ||
if (monthString.endsWith("L")) { | ||
return new Month(Integer.parseInt(monthString.substring(0, monthString.length()-1)), true); | ||
} | ||
return new Month(Integer.parseInt(monthString)); | ||
} | ||
|
||
public static Month valueOf(int monthOfYear) { | ||
return new Month(monthOfYear); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (leapMonth) { | ||
return monthOfYear + "L"; | ||
} else { | ||
return String.valueOf(monthOfYear); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Month month = (Month) o; | ||
return monthOfYear == month.monthOfYear && leapMonth == month.leapMonth; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(monthOfYear, leapMonth); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package net.fortuna.ical4j.model; | ||
|
||
import java.time.temporal.ChronoField; | ||
import java.time.temporal.ValueRange; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
public class MonthList extends ArrayList<Month> { | ||
|
||
private final ValueRange valueRange; | ||
|
||
public MonthList() { | ||
this(ChronoField.MONTH_OF_YEAR.range()); | ||
} | ||
|
||
public MonthList(ValueRange range) { | ||
this.valueRange = range; | ||
} | ||
|
||
public MonthList(String aString) { | ||
this(aString, ChronoField.MONTH_OF_YEAR.range()); | ||
} | ||
|
||
public MonthList(String aString, ValueRange valueRange) { | ||
this(valueRange); | ||
addAll(Arrays.stream(aString.split(",")).map(Month::parse).collect(Collectors.toList())); | ||
} | ||
|
||
@Override | ||
public final boolean add(final Month month) { | ||
if (!valueRange.isValidValue(month.getMonthOfYear())) { | ||
throw new IllegalArgumentException( | ||
"Value not in range [" + valueRange + "]: " + month); | ||
} | ||
return super.add(month); | ||
} | ||
|
||
@Override | ||
public boolean addAll(Collection<? extends Month> c) { | ||
Optional<? extends Month> invalidMonth = c.stream().filter(m -> !valueRange.isValidValue(m.getMonthOfYear())) | ||
.findFirst(); | ||
if (invalidMonth.isPresent()) { | ||
throw new IllegalArgumentException( | ||
"Value not in range [" + valueRange + "]: " + invalidMonth); | ||
} | ||
return super.addAll(c); | ||
} | ||
|
||
@Override | ||
public final String toString() { | ||
return stream().map(Object::toString).collect(Collectors.joining(",")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.