mchades commented on code in PR #9551:
URL: https://github.com/apache/gravitino/pull/9551#discussion_r2660642099


##########
api/src/main/java/org/apache/gravitino/function/FunctionResources.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.function;
+
+import java.util.Arrays;
+import java.util.Objects;
+import org.apache.gravitino.annotation.Evolving;
+
+/** Represents external resources that are required by a function 
implementation. */
+@Evolving
+public class FunctionResources {
+  private static final String[] EMPTY = new String[0];
+
+  private final String[] jars;
+  private final String[] files;
+  private final String[] archives;
+
+  private FunctionResources(String[] jars, String[] files, String[] archives) {
+    this.jars = jars == null ? EMPTY : Arrays.copyOf(jars, jars.length);
+    this.files = files == null ? EMPTY : Arrays.copyOf(files, files.length);
+    this.archives = archives == null ? EMPTY : Arrays.copyOf(archives, 
archives.length);
+  }
+
+  /**
+   * @return An empty {@link FunctionResources} instance.
+   */
+  public static FunctionResources empty() {
+    return new FunctionResources(EMPTY, EMPTY, EMPTY);
+  }
+
+  /**
+   * Create a {@link FunctionResources} instance.
+   *
+   * @param jars The jar resources.
+   * @param files The file resources.
+   * @param archives The archive resources.
+   * @return A {@link FunctionResources} instance.
+   */
+  public static FunctionResources of(String[] jars, String[] files, String[] 
archives) {
+    if ((jars == null || jars.length == 0)
+        && (files == null || files.length == 0)
+        && (archives == null || archives.length == 0)) {
+      return new FunctionResources(EMPTY, EMPTY, EMPTY);
+    }
+    return new FunctionResources(jars, files, archives);
+  }
+
+  /**
+   * @return The jar resources.
+   */
+  public String[] jars() {
+    return Arrays.copyOf(jars, jars.length);

Review Comment:
   Why do I make copies in these two places?
   - In my design, functions are immutable, and every modification will result 
in a new version
   - The constructor performs a defensive copy to prevent the caller from 
holding a reference to the input array and modifying the internal state. 
   - If getters directly return the internal array, it would break 
immutability; therefore, a copy is returned.
   
   If we consider that setting the member as `final` is sufficient and aligns 
with our project style, I will remove the copy from the getters.



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