kirupha2000 commented on code in PR #32074:
URL: https://github.com/apache/beam/pull/32074#discussion_r1714587676
##########
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:
I think it does not have any advantages in this context since the
`comparing` method here takes in a `SerializableFunction<? super T, ? extends
V>`, meaning, because of the `? extends V` it would accept any type that is a
sub type of `Comparable` as per my understanding.
But I had the `? super V`, following the "**P**roducers **E**xtends
**C**onsumers **S**uper" general rule of thumb just in case to be safe.
##########
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:
Same here, wasn't able to think of a scenario where this would be useful but
added it anyways, following **PECS**, just in case.
--
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]