java - Extend an existing stream collector instance -
i need collector that's identical collectors.toset(), custom finisher. i'd love able like:
mycollector = collectors.toset(); mycollector.setfinisher(mycustomfinisher); and done, doesn't seem possible. alternative can see recreate collectors.toset() using collector.of(), not dry.
is there way take existing collector , amend described above?
edit
a few of answers have recommended this:
collector<t, ?, set<t>> toset = collectors.toset(); return collector.of( toset.supplier(), toset.accumulator(), toset.combiner(), yourfinisher, toset.characteristics()); however custom finisher isn't returning set; it's using accumulated set return else. fact it's doing putting me generics hell i'm still rummaging through..
that’s collectingandthen(collector,finisher) does.
the custom finisher not replace old one, if there one, gets combined (like oldfinisher.andthen(newfinisher)), current implementation of toset() has no finisher (an identity finisher) anyway.
so have do, collectingandthen(toset(),mycustomfinisher)…
Comments
Post a Comment