je-ik commented on code in PR #32074:
URL: https://github.com/apache/beam/pull/32074#discussion_r1714824028
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/SerializableComparator.java:
##########
@@ -19,10 +19,29 @@
import java.io.Serializable;
import java.util.Comparator;
+import java.util.Objects;
+import java.util.function.Function;
/**
* A {@code Comparator} that is also {@code Serializable}.
*
* @param <T> type of values being compared
*/
-public interface SerializableComparator<T> extends Comparator<T>, Serializable
{}
+public interface SerializableComparator<T> extends Comparator<T>, Serializable
{
+ /**
+ * Analogous to {@link Comparator#comparing(Function)}, except that it takes
in a {@link
+ * SerializableFunction} as the key extractor and returns a {@link
SerializableComparator}.
+ *
+ * @param keyExtractor the function used to extract the {@link
java.lang.Comparable} sort key
+ * @return A {@link SerializableComparator} that compares by an extracted key
+ * @param <T> the type of element to be compared
+ * @param <V> the type of the {@code Comparable} sort key
+ * @see Comparator#comparing(Function)
+ */
+ static <T, V extends Comparable<? super V>> SerializableComparator<T>
comparing(
+ SerializableFunction<? super T, ? extends V> keyExtractor) {
Review Comment:
:+1:
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/SerializableComparator.java:
##########
@@ -19,10 +19,29 @@
import java.io.Serializable;
import java.util.Comparator;
+import java.util.Objects;
+import java.util.function.Function;
/**
* A {@code Comparator} that is also {@code Serializable}.
*
* @param <T> type of values being compared
*/
-public interface SerializableComparator<T> extends Comparator<T>, Serializable
{}
+public interface SerializableComparator<T> extends Comparator<T>, Serializable
{
+ /**
+ * Analogous to {@link Comparator#comparing(Function)}, except that it takes
in a {@link
+ * SerializableFunction} as the key extractor and returns a {@link
SerializableComparator}.
+ *
+ * @param keyExtractor the function used to extract the {@link
java.lang.Comparable} sort key
+ * @return A {@link SerializableComparator} that compares by an extracted key
+ * @param <T> the type of element to be compared
+ * @param <V> the type of the {@code Comparable} sort key
+ * @see Comparator#comparing(Function)
+ */
+ static <T, V extends Comparable<? super V>> SerializableComparator<T>
comparing(
Review Comment:
Makes sense. :+1:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]