You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
privatevar hasNext:Boolean=if (increasing) first <= last else first >= last
17
+
privatevar next:LocalDate=if (hasNext) first else finalElement
18
+
19
+
overridefunhasNext(): Boolean= hasNext
20
+
21
+
overridefunnextLocalDate(): LocalDate {
22
+
if(!hasNext) throwNoSuchElementException()
23
+
val value = next
24
+
next += step
25
+
/**
26
+
* Some [DatePeriod]s with opposite-signed constituent parts can get stuck in an infinite loop rather than progressing toward the far future or far past.
27
+
* A period of P1M-28D for example, when added to any date in February, will return that same date, thus leading to a loop.
28
+
*/
29
+
if(next == value) throwIllegalStateException("Progression has hit an infinite loop. Check to ensure that the the values for total months and days in the provided step DatePeriod are not equal and opposite for certain month(s).")
30
+
if ((increasing && next > finalElement) || (!increasing && next < finalElement)) {
31
+
hasNext =false
32
+
}
33
+
return value
34
+
}
35
+
}
36
+
37
+
publicopenclassLocalDateProgression
38
+
internalconstructor
39
+
(
40
+
start:LocalDate,
41
+
endInclusive:LocalDate,
42
+
publicval step:DatePeriod
43
+
) :Iterable<LocalDate> {
44
+
init {
45
+
if(!step.positive() &&!step.negative()) throwIllegalArgumentException("Provided step DatePeriod is of size zero (or equivalent over an arbitrarily long timeline)")
46
+
}
47
+
publicval first:LocalDate= start
48
+
publicval last:LocalDate= endInclusive
49
+
50
+
overridefuniterator(): LocalDateIterator=LocalDateProgressionIterator(first, last, step)
51
+
52
+
publicopenfunisEmpty(): Boolean=if (step.positive()) first > last else first < last
0 commit comments