adoroszlai commented on code in PR #9430:
URL: https://github.com/apache/ozone/pull/9430#discussion_r2598605574


##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/AclListBuilder.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.hadoop.ozone.om.helpers;
+
+import com.google.common.collect.ImmutableList;
+import jakarta.annotation.Nonnull;
+import jakarta.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import org.apache.hadoop.ozone.OzoneAcl;
+
+/** Helps incrementally build a list of ACLs. */
+public final class AclListBuilder {
+
+  /** The original list being built from, used if no changes are made, to 
reduce copying. */
+  private final ImmutableList<OzoneAcl> originalList;
+  /** The updated list being built, created lazily on the first modification. 
*/
+  private List<OzoneAcl> updatedList;
+  /** Whether any changes were made. */
+  private boolean changed;
+
+  public static AclListBuilder empty() {
+    return new AclListBuilder(ImmutableList.of());
+  }
+
+  public static AclListBuilder of(ImmutableList<OzoneAcl> list) {
+    return new AclListBuilder(list);
+  }
+
+  public static AclListBuilder copyOf(List<OzoneAcl> list) {
+    return new AclListBuilder(list == null ? ImmutableList.of() : 
ImmutableList.copyOf(list));
+  }
+
+  private AclListBuilder(ImmutableList<OzoneAcl> list) {
+    originalList = list;
+  }
+
+  public boolean isChanged() {
+    return changed;
+  }
+
+  public ImmutableList<OzoneAcl> build() {
+    return changed ? ImmutableList.copyOf(updatedList) : originalList;
+  }
+
+  public void add(@Nonnull OzoneAcl acl) {
+    Objects.requireNonNull(acl, "acl == null");
+    ensureInitialized();
+    changed |= OzoneAclUtil.addAcl(updatedList, acl);
+  }
+
+  public void addAll(@Nullable List<OzoneAcl> newAcls) {
+    if (newAcls == null || newAcls.isEmpty()) {
+      return;
+    }
+    ensureInitialized();
+    changed |= OzoneAclUtil.addAllAcl(updatedList, newAcls);
+  }
+
+  /** Set the list being built to {@code acls}.  For further mutations to 
work, it must be modifiable. */
+  public void set(@Nonnull List<OzoneAcl> acls) {
+    Objects.requireNonNull(acls, "acls == null");
+    changed |= !Objects.equals(updatedList, acls);

Review Comment:
   It is intentional, since we are replacing the list completely, a new empty 
list does not need to be created.



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