fqaiser94 commented on code in PR #6513:
URL: https://github.com/apache/iceberg/pull/6513#discussion_r1120531058


##########
api/src/main/java/org/apache/iceberg/BaseValidatablePendingUpdate.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.iceberg;
+
+import java.util.List;
+import java.util.function.Predicate;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+
+abstract class BaseValidatablePendingUpdate<ThisT, T>
+    implements ValidatablePendingUpdate<ThisT, T> {
+
+  private static class Validation {
+    private final Predicate<Table> predicate;
+    private final ValidationException exception;
+
+    Validation(Predicate<Table> predicate, ValidationException exception) {
+      this.predicate = predicate;
+      this.exception = exception;
+    }
+  }
+
+  private final List<Validation> validations = Lists.newArrayList();
+
+  @Override
+  public ThisT addValidation(Predicate<Table> predicate, ValidationException 
exception) {
+    this.validations.add(new Validation(predicate, exception));
+    return returnThis();
+  }
+
+  @Override
+  public final void validateCurrent(Table current) {
+    validations.forEach(
+        validation -> {
+          if (!validation.predicate.test(current)) {
+            throw validation.exception;
+          }
+        });
+  }
+
+  protected abstract ThisT returnThis();

Review Comment:
   ~I noticed this. Unfortunately, I can't call it the same thing because it 
causes conflicts when both methods are in scope.~
   ~Best I can do is call it `returnSelf()`.~ 
   ~Let me know if you have a better idea, my java skills aren't the greatest 
:)~
   
   Never mind, I found a way to do this. 



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to