Skip to content

Commit

Permalink
Added JavaStreamUtilities with a predicate to test if a value is th…
Browse files Browse the repository at this point in the history
…e first value the predicate ever saw.

Marking older issues as fixed.

Fixes #2,#3,#4,#6
  • Loading branch information
khituras committed Nov 25, 2020
1 parent 4fc3cc2 commit 066f027
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>julielab-java-utilities</artifactId>
<packaging>jar</packaging>
<version>1.3.2</version>
<version>1.4.0-SNAPSHOT</version>
<name>julielab-java-utilities</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/de/julielab/java/utilities/JavaStreamUtilities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.julielab.java.utilities;

import java.util.function.Function;
import java.util.function.Predicate;

public class JavaStreamUtilities {
/**
* A predicate that tests true for all values that equal the first value it saw.
*
* @param valueFunction A function to retrieve the value.
* @param <T> The input type.
* @param <E> The value type for comparison.
* @return The predicate.
*/
public static <T, E> Predicate equalsFirstSeenValue(Function<T, E> valueFunction) {
return new Predicate<T>() {
private E firstValue = null;

@Override
public boolean test(T entry) {
E value = valueFunction.apply(entry);
if (firstValue == null) {
firstValue = value;
return true;
}
return value.equals(firstValue);
}
};
}
}
Binary file modified src/test/resources/test.jar
Binary file not shown.

0 comments on commit 066f027

Please sign in to comment.