Skip to content

Commit

Permalink
Misc clean-ups
Browse files Browse the repository at this point in the history
+ Remove Take/Drop implementations, it's not worth it for an alias.
+ Constructors on gatherers have default visibility.
  • Loading branch information
tginsberg committed Jun 17, 2024
1 parent 470999e commit 485370d
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 296 deletions.
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,6 @@ TBD, once I start publishing snapshots to Maven Central.
(Example, TODO clean this up)


**Dropping elements from the start of a Stream:**

```java
Stream
.of("A", "B", "C", "D", "E", "F", "G")
.gather(Gatherers4j.drop(3))
.toList();

// ["D", "E", "F", "G"]
```

**Limiting the size of the Stream:**

```java
Stream
.of("A", "B", "C", "D", "E", "F", "G")
.gather(Gatherers4j.take(3))
.toList();

// ["A", "B", "C"]
```

**Removing consecutive duplicate elements:**

```java
Expand Down
51 changes: 0 additions & 51 deletions src/main/java/com/ginsberg/gatherers4j/DroppingGatherer.java

This file was deleted.

32 changes: 4 additions & 28 deletions src/main/java/com/ginsberg/gatherers4j/Gatherers4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class Gatherers4j {
}

/**
*
* @param function A mapping function used to compare objects in the stream for equality.
*/
public static <INPUT> Gatherer<INPUT, ?, INPUT> dedupeConsecutiveBy(final Function<INPUT, Object> function) {
Expand All @@ -48,25 +47,14 @@ public class Gatherers4j {

/**
* Filter a stream to only distinct elements as described by the given function.
*
* @param function The mapping function
*/
public static <INPUT, OUTPUT> Gatherer<INPUT, ?, INPUT> distinctBy(final Function<INPUT, OUTPUT> function) {
Objects.requireNonNull(function, "Mapping function cannot be null"); // TODO: Where should this go?
return new DistinctGatherer<>(function);
}

/**
* Drop the first {@code count} elements from the input stream. If the stream has fewer than {@code count}
* elements, an empty Stream is produced. If the input stream has more than {@code count} elements,
* anything after {@code count} elements will comprise the output stream.
*
* @param count A non-negative number of elements to drop from the stream.
* @return DroppingGatherer
*/
public static <INPUT> DroppingGatherer<INPUT> drop(final long count) {
return new DroppingGatherer<>(count);
}

public static <INPUT> Gatherer<INPUT, Void, INPUT> interleave(final Stream<INPUT> other) {
return new InterleavingGatherer<>(other);
}
Expand All @@ -80,32 +68,20 @@ public static <INPUT> LastGatherer<INPUT> last(final int count) {
return new LastGatherer<>(count);
}

public static <INPUT,OUTPUT> Gatherer<INPUT, ?, IndexedValue<OUTPUT>> mapWithIndex(final Function<INPUT,OUTPUT> mappingFunction) {
public static <INPUT, OUTPUT> Gatherer<INPUT, ?, IndexedValue<OUTPUT>> mapWithIndex(final Function<INPUT, OUTPUT> mappingFunction) {
Objects.requireNonNull(mappingFunction, "Mapping function cannot be null");
return new IndexingGatherer<>(mappingFunction);
}

/**
* Limit the input stream to the first {@code count} elements. If the input stream has more than {@code count}
* elements, anything more than {@code count} are discarded. If input the stream has fewer than {@code count}
* elements, an empty output Stream is produced.
*
* @param count A non-negative number of elements to limit the stream to.
* @return TakingGatherer
*/
public static <INPUT> TakingGatherer<INPUT> take(final long count) {
return new TakingGatherer<>(count);
}

public static <INPUT> Gatherer<INPUT, ?, IndexedValue<INPUT>> withIndex() {
return new IndexingGatherer<>(Function.identity());
}

public static <FIRST,SECOND> Gatherer<FIRST, Void, Pair<FIRST,SECOND>> zip(final Stream<SECOND> other) {
public static <FIRST, SECOND> Gatherer<FIRST, Void, Pair<FIRST, SECOND>> zip(final Stream<SECOND> other) {
return new ZipGatherer<>(other);
}

public static <INPUT> Gatherer<INPUT,?, List<INPUT>> zipWithNext() {
public static <INPUT> Gatherer<INPUT, ?, List<INPUT>> zipWithNext() {
return new ZipWithNextGatherer<>();
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/ginsberg/gatherers4j/LastGatherer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class LastGatherer<INPUT> implements Gatherer<INPUT, LastGatherer.State<I

private final int lastCount;

public LastGatherer(int lastCount) {
LastGatherer(int lastCount) {
if (lastCount < 0) {
throw new IllegalArgumentException("Last count must not be negative");
}
Expand Down
51 changes: 0 additions & 51 deletions src/main/java/com/ginsberg/gatherers4j/TakingGatherer.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/java/com/ginsberg/gatherers4j/ZipGatherer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ public Integrator<Void, FIRST, Pair<FIRST, SECOND>> integrator() {
.tryAdvance(
it -> downstream.push(new Pair<>(element, it))
) && !downstream.isRejecting();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
import java.util.stream.Gatherer;

public class ZipWithNextGatherer<INPUT> implements Gatherer<INPUT, ZipWithNextGatherer.State<INPUT>, List<INPUT>> {

ZipWithNextGatherer() {
super();
}

@Override
public Supplier<State<INPUT>> initializer() {
return State::new;
Expand Down
71 changes: 0 additions & 71 deletions src/test/java/com/ginsberg/gatherers4j/DroppingGathererTest.java

This file was deleted.

71 changes: 0 additions & 71 deletions src/test/java/com/ginsberg/gatherers4j/TakingGathererTest.java

This file was deleted.

0 comments on commit 485370d

Please sign in to comment.