aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me/lucko/spark/common/util
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2022-11-13 12:30:59 +0000
committerLuck <git@lucko.me>2022-11-13 12:30:59 +0000
commit5af2e6fb4cbd21f836c7ad56100b3c4535a831de (patch)
tree1fcda21b99dd8ae8f1339d862c14b7c2ac220012 /spark-common/src/main/java/me/lucko/spark/common/util
parent1d8e0f3a0a115a70146c1462a68990508a71af6e (diff)
downloadspark-5af2e6fb4cbd21f836c7ad56100b3c4535a831de.tar.gz
spark-5af2e6fb4cbd21f836c7ad56100b3c4535a831de.tar.bz2
spark-5af2e6fb4cbd21f836c7ad56100b3c4535a831de.zip
Remove recursion in protobuf data
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/common/util')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/util/IndexedListBuilder.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/util/IndexedListBuilder.java b/spark-common/src/main/java/me/lucko/spark/common/util/IndexedListBuilder.java
new file mode 100644
index 0000000..b2315f9
--- /dev/null
+++ b/spark-common/src/main/java/me/lucko/spark/common/util/IndexedListBuilder.java
@@ -0,0 +1,43 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.common.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * List builder that returns the index of the inserted element.
+ *
+ * @param <T> generic type
+ */
+public class IndexedListBuilder<T> {
+ private int i = 0;
+ private final List<T> nodes = new ArrayList<>();
+
+ public int add(T node) {
+ this.nodes.add(node);
+ return this.i++;
+ }
+
+ public List<T> build() {
+ return this.nodes;
+ }
+}