Producing streams in java.time?
Roger Riggs
Roger.Riggs at Oracle.com
Mon Dec 14 22:05:34 UTC 2015
Hi Tagir,
What are the use cases? Does it need to be more convenient?
It seems relatively easy to do in application code.
Could there be a more general form that would be as useful but add fewer
methods?
Roger
On 12/10/2015 11:31 AM, Tagir F. Valeev wrote:
> Hello!
>
> Currently it seems that java.time package does not use Stream API in
> any way. I think it would be nice to add some methods which produce
> the streams. For example:
>
> - in class Year:
>
> // Returns sequential ordered stream of all months within this Year:
> Stream<YearMonth> months();
> // Returns sequential ordered stream of all days within this Year:
> Stream<LocalDate> days();
> // Returns sequential ordered stream of all years starting from this
> // Year until the supplied year, exclusive
> Stream<Year> yearsUntil(Temporal endExclusive);
>
> - in class YearMonth:
>
> // Returns sequential ordered stream of all days within this YearMonth:
> Stream<LocalDate> days();
> // Returns sequential ordered stream of all months starting from this
> // YearMonth until the supplied YearMonth, exclusive
> Stream<YearMonth> monthsUntil(Temporal endExclusive);
>
> - in class LocalDate:
>
> // Returns sequential ordered stream of all months starting from this
> // LocalDate until the supplied LocalDate, exclusive
> Stream<LocalDate> daysUntil(Temporal endExclusive);
>
> The implementation of these methods could be quite simple. For example:
>
> class Year {
> public Stream<LocalDate> days() {
> return IntStream.rangeClosed(1, length()).mapToObj(this::atDay);
> }
> }
>
> What do you think?
>
> With best regards,
> Tagir Valeev.
>
More information about the core-libs-dev
mailing list