bengbengbalabalabeng commented on code in PR #1015:
URL: https://github.com/apache/fesod/pull/1015#discussion_r3791732091


##########
fesod-sheet/src/main/java/org/apache/fesod/sheet/read/metadata/ColumnIndexResolver.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.fesod.sheet.read.metadata;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.Validate;
+import org.apache.fesod.common.util.MapUtils;
+
+/**
+ * Strategy interface for column index resolution and filtering during sheet 
parsing.
+ */
+@FunctionalInterface
+public interface ColumnIndexResolver {
+
+    /**
+     * Default pass-through resolver that performs no column filtering.
+     */
+    ColumnIndexResolver PASS_THROUGH = columnIndex -> columnIndex;
+
+    /**
+     * Resolves the raw column index to a target column index.
+     *
+     * @param columnIndex raw 0-based column index
+     * @return mapped target column index, or {@code null} if the column is 
not included
+     */
+    Integer resolve(int columnIndex);
+
+    static ColumnIndexResolver fromInclude(List<Integer> columnIndexes) {
+        return new DefaultIncludedColumnIndexResolver(columnIndexes);
+    }
+
+    class DefaultIncludedColumnIndexResolver implements ColumnIndexResolver {
+
+        private final Map<Integer, Integer> indexMap;
+
+        DefaultIncludedColumnIndexResolver(List<Integer> columnIndexes) {
+            Validate.notEmpty(columnIndexes, "The includeColumnIndexes must 
not be empty");
+
+            List<Integer> tmpColumnIndexes = new ArrayList<>(columnIndexes);
+            this.indexMap = 
MapUtils.newHashMapWithExpectedSize(tmpColumnIndexes.size());
+
+            for (int targetIndex = 0; targetIndex < tmpColumnIndexes.size(); 
targetIndex++) {
+                this.indexMap.put(tmpColumnIndexes.get(targetIndex), 
targetIndex);
+            }
+        }
+
+        @Override
+        public Integer resolve(int columnIndex) {

Review Comment:
   Thanks for the review! Regarding returning `Integer` versus primitive `int`, 
I suggest keeping the `Integer` return type for the following reasons:
   
   - `DefaultIncludedColumnIndexResolver` returns existing `Integer` references 
directly from indexMap.
   - `PASS_THROUGH` hits pre-allocated `IntegerCache` singletons for common 
column indexes (0–127). No runtime GC overhead.
   - The downstream `ReadCellData` object itself requires an `Integer` 
columnIndex, so returning primitive `int` would merely defer autoboxing.
   - Column filtering inherently requires a branch check to skip excluded 
columns. Returning `null` provides clear, type-safe semantics (`null` = 
filtered out) without relying on magic sentinel numbers (like -1).



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