Skip to content

Commit

Permalink
Rename byIndex() to filteringByIndex() (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
pivovarit authored Dec 15, 2024
1 parent 0578053 commit 9790926
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Provided `Gatherers`:
- takes elements until a change is detected based on a key extractor function
- `MoreGatherers.windowSliding(int, int)`
- creates a sliding window of a fixed size with a fixed step, extends `Gatherers.windowSliding(int)` by adding a step parameter
- `MoreGatherers.byIndex(BiPredicate<Long, T>)`
- `MoreGatherers.filteringByIndex(BiPredicate<Long, T>)`
- filters elements based on their index and value

### Philosophy
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pivovarit/gatherers/MoreGatherers.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private MoreGatherers() {
*
* @return a {@link Gatherer} that applies the given filter based on element index and value
*/
public static <T> Gatherer<T, ?, T> byIndex(BiPredicate<Long, ? super T> predicate) {
public static <T> Gatherer<T, ?, T> filteringByIndex(BiPredicate<Long, ? super T> predicate) {
return new FilterByIndexGatherer<>(predicate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FilterByIndexBenchmark {
@Benchmark
public List<Integer> filterByIndex() {
return source.stream()
.gather(MoreGatherers.byIndex((i, _) -> i % 2 == 0))
.gather(MoreGatherers.filteringByIndex((i, _) -> i % 2 == 0))
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

import java.util.stream.Stream;

import static com.pivovarit.gatherers.MoreGatherers.byIndex;
import static com.pivovarit.gatherers.MoreGatherers.filteringByIndex;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class ByIndexTest {

@Test
void shouldRejectNullPredicate() {
assertThatThrownBy(() -> byIndex(null)).isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> filteringByIndex(null)).isInstanceOf(NullPointerException.class);
}

@Test
void shouldFilterByIndexEmptyStream() {
assertThat(Stream.empty().gather(byIndex((_, _) -> true))).isEmpty();
assertThat(Stream.empty().gather(filteringByIndex((_, _) -> true))).isEmpty();
}

@Test
void shouldFilterByIndex() {
assertThat(Stream.of("a", "bb", "cc", "ddd")
.gather(byIndex((i, _) -> i % 2 == 0)))
.gather(filteringByIndex((i, _) -> i % 2 == 0)))
.containsExactly("a", "cc");
}
}

0 comments on commit 9790926

Please sign in to comment.