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
Copy file name to clipboardExpand all lines: README.md
+35-1Lines changed: 35 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,7 @@ And has support for...
31
31
+ Exclusive end point (`until`)
32
32
+ Configurable period between stream elements (`every`)
33
33
+ Streams can move forward or backward through time
34
+
+ Infinite streams (by not providing an end point)
34
35
35
36
## Usage
36
37
@@ -40,11 +41,19 @@ builder can be created using one of two methods:
40
41
+`.fromNow()` - Assumes 'now'
41
42
+`.from(T from)` - Type-specific starting point, provided by caller
42
43
43
-
To set the point in time where the stream ends (optional!), you can call one of two methods:
44
+
To set the optional point in time where the stream ends (inclusive) you can call one of two methods:
44
45
45
46
+`.to(T to)` - Type-specific end point. Can be null to indicate forever
46
47
+`.to(amount, units)` - Where `amount` is a positive integer (for forward through time) or a negative integer (for backward through time), and `unit` is a valid `ChronoUnit`
47
48
49
+
To make the optional end of the stream exclusive, you can call one of two methods:
50
+
51
+
+`.until(T to)` - Type-specific end point. Can be null to indicate forever
52
+
+`.until(amount, units)` - Where `amount` is a positive integer (for forward through time) or a negative integer (for backward through time), and `unit` is a valid `ChronoUnit`
53
+
54
+
Note that providing an end time (via `to` or `until`) is optional. In that case, the stream will
55
+
have no end and should produce values until you stop it.
56
+
48
57
## Examples
49
58
50
59
Create a stream of `LocalDateTime` objects, between now and hour from now, every two minutes:
@@ -78,6 +87,31 @@ final Stream<YearMonth> stream = YearMonthStream
78
87
.stream();
79
88
```
80
89
90
+
Replace this code that does something with every minute of time over the last hour, going backwards:
91
+
92
+
```java
93
+
finalLocalDateTime end =LocalDateTime.now().minusHours(1);
94
+
LocalDateTime when =LocalDateTime.now();
95
+
96
+
while(when.isAfter(end)) {
97
+
doSomething(when);
98
+
when = when.minusMinutes(1);
99
+
}
100
+
```
101
+
102
+
... with this:
103
+
104
+
```java
105
+
LocalDateTimeStream
106
+
.fromNow()
107
+
.until(LocalDateTime.now().minusHours(1))
108
+
.every(1, ChronoUnit.MINUTES)
109
+
.stream()
110
+
.forEach(this::doSomething);
111
+
```
112
+
113
+
It's not less code, but it certainly makes it easier to understand.
114
+
81
115
There are also plenty of examples in the unit tests.
0 commit comments