-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Implement `reverse()` + Implement `maxBy(fn)` and `minBy(fn)` + Implement `exactSize(n)`
- Loading branch information
Showing
12 changed files
with
606 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
name: Build and Test | ||
|
||
on: | ||
[ push ] | ||
[ pull_request, push ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
@@ -22,10 +21,22 @@ jobs: | |
distribution: 'temurin' | ||
cache: 'gradle' | ||
|
||
- name: Build and Publish | ||
run: ./gradlew build publish --no-daemon | ||
- name: Build | ||
run: ./gradlew build --no-daemon | ||
|
||
- name: Publish | ||
if: github.ref != 'refs/heads/main' | ||
run: ./gradlew publish --no-daemon | ||
env: | ||
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} | ||
SONATYPE_TOKEN: ${{ secrets.SONATYPE_TOKEN }} | ||
SONATYPE_SIGNING_KEY: ${{ secrets.SONATYPE_SIGNING_KEY }} | ||
SONATYPE_SIGNING_PASSPHRASE: ${{ secrets.SONATYPE_SIGNING_PASSPHRASE }} | ||
|
||
- name: Add coverage to PR | ||
if: github.event_name == 'pull_request' | ||
id: jacoco | ||
uses: madrapps/[email protected] | ||
with: | ||
paths: ${{ github.workspace }}/**/build/reports/jacoco/test/jacocoTestReport.xml | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.4.0-SNAPSHOT | ||
0.5.0 |
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
74 changes: 74 additions & 0 deletions
74
src/main/java/com/ginsberg/gatherers4j/MinMaxGatherer.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2024 Todd Ginsberg | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.ginsberg.gatherers4j; | ||
|
||
import java.util.function.BiConsumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Gatherer; | ||
|
||
public class MinMaxGatherer<INPUT, MAPPED extends Comparable<MAPPED>> | ||
implements Gatherer<INPUT, MinMaxGatherer.State<INPUT, MAPPED>, INPUT> { | ||
|
||
private final Function<INPUT, MAPPED> mappingFunction; | ||
private final boolean max; | ||
|
||
MinMaxGatherer(final boolean max, final Function<INPUT, MAPPED> mappingFunction) { | ||
this.mappingFunction = mappingFunction; | ||
this.max = max; | ||
} | ||
|
||
@Override | ||
public Supplier<State<INPUT, MAPPED>> initializer() { | ||
return State::new; | ||
} | ||
|
||
@Override | ||
public Integrator<State<INPUT, MAPPED>, INPUT, INPUT> integrator() { | ||
return (state, element, downstream) -> { | ||
final MAPPED mapped = element == null ? null : mappingFunction.apply(element); | ||
if (mapped == null) { | ||
return !downstream.isRejecting(); | ||
} | ||
if (state.bestSoFar == null) { | ||
state.bestSoFar = element; | ||
state.mappedField = mapped; | ||
} else { | ||
final int compared = mapped.compareTo(state.mappedField); | ||
if ((compared > 0 && max) || (compared < 0 && !max)) { | ||
state.bestSoFar = element; | ||
state.mappedField = mapped; | ||
} | ||
} | ||
return !downstream.isRejecting(); | ||
}; | ||
} | ||
|
||
@Override | ||
public BiConsumer<State<INPUT, MAPPED>, Downstream<? super INPUT>> finisher() { | ||
return (state, downstream) -> { | ||
if (state.bestSoFar != null) { | ||
downstream.push(state.bestSoFar); | ||
} | ||
}; | ||
} | ||
|
||
public static class State<INPUT, MAPPED extends Comparable<MAPPED>> { | ||
private INPUT bestSoFar; | ||
private MAPPED mappedField; | ||
} | ||
} |
Oops, something went wrong.