Abyss-lord commented on code in PR #6861:
URL: https://github.com/apache/gravitino/pull/6861#discussion_r2043975349


##########
core/src/main/java/org/apache/gravitino/listener/api/info/Either.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.info;
+
+import java.util.Optional;
+
+/**
+ * Either represents a value of two possible types (a disjoint union).
+ *
+ * @param <L> Left type
+ * @param <R> Right type
+ */
+public final class Either<L, R> {
+  private final Optional<L> left;
+  private final Optional<R> right;
+
+  /**
+   * Create a new {@code Either} instance with a left value.
+   *
+   * @param value Left value
+   * @return Either with left value
+   * @param <L> Left type
+   * @param <R> Right type
+   */
+  public static <L, R> Either<L, R> left(L value) {
+    return new Either<>(Optional.of(value), Optional.empty());

Review Comment:
   > If value is null, this place will throw Exception. Maybe you should use 
`ofNullable` or add check.
   
   In my perspective, the concept of Either implies that one side has a 
definite value, while the other side is expected to be null.
   
   When the `left` method is called, it suggests that the left - hand value is 
present, and the right - hand value should be null. Passing a null value in 
this context should lead to an error.
   
   Likewise, when the `right` method is used, it means the right - hand value 
is present, and the left - hand value should be null. An input of null in this 
situation could also be regarded as invalid. It's possible that there are 
different interpretations, and I'd be more than happy to hear other viewpoints 
and discuss this further.



-- 
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]

Reply via email to