-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add helpers for working with Streams
For test cases it is sometimes useful to check aggregated values rather than individual counters. The most common example is looking at the overall number of increments for a counter with a given name. The recommendation was to use streams, but that can get a bit cumbersome: ```java long sum = StreamSupport.stream(registry.spliterator(), false) .filter(m -> m instanceof Counter) // Convert to counters .map(m -> (Counter) m) .filter(c -> "foo".equals(c.id().name())) // Restrict by name .mapToLong(Counter::count) // Get value .reduce(0L, Long::sum) // Compute sum ``` This change adds some helpers to make this sort of use-case a bit easier: ```java long sum = registry.counters() .filter(Functions.nameEquals("foo")) // Restrict by name .mapToLong(Counter::count) // Get value .reduce(0L, Long::sum) // Compute sum ``` There are also some examples in the unit tests and comments for the stream methods on Registry.
- Loading branch information
1 parent
cf349c4
commit 9b3dd8a
Showing
4 changed files
with
158 additions
and
0 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
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