Node class

Пакет: com.hypixel.hytale.server.core.modules.interaction.interaction.config.data

Файл: com/hypixel/hytale/server/core/modules/interaction/interaction/config/data/TreeCollector.java

Поля (4)

МодификаторыТипИмя
public static final TreeCollector.Node[] EMPTY_ARRAY
private TreeCollector.Node<T>[] children
private T data
private final TreeCollector.Node<T> parent

Методы (3)

МодификаторыВозвратСигнатура
public TreeCollector.Node<T>[] getChildrenpublic TreeCollector.Node<T>[] getChildren()
public T getDatapublic T getData()
public TreeCollector.Node<T> getParentpublic TreeCollector.Node<T> getParent()

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.modules.interaction.interaction.config.data;

class="kw">import com.hypixel.hytale.function.function.TriFunction;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionContext;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.Interaction;
class="kw">import java.util.Arrays;
class="kw">import javax.annotation.Nonnull;

class="kw">public class TreeCollector<T> class="kw">implements Collector {
   class="kw">private class="kw">final TriFunction<CollectorTag, InteractionContext, Interaction, T> function;
   class="kw">private TreeCollector.Node<T> root;
   class="kw">private TreeCollector.Node<T> current;

   class="kw">public TreeCollector(TriFunction<CollectorTag, InteractionContext, Interaction, T> var1) {
      this.function = var1;
   }

   class="kw">public TreeCollector.Node<T> getRoot() {
      class="kw">return this.root;
   }

   @Override
   class="kw">public void start() {
      this.root = new TreeCollector.Node<>(null);
      this.current = this.root;
   }

   @Override
   class="kw">public void into(@Nonnull InteractionContext var1, Interaction var2) {
      if (this.current.children != null) {
         this.current.children = Arrays.copyOf(this.current.children, this.current.children.length + 1);
      } else {
         this.current.children = new TreeCollector.Node[1];
      }

      this.current = this.current.children[this.current.children.length - 1] = new TreeCollector.Node<>(this.current);
   }

   @Override
   class="kw">public boolean collect(@Nonnull CollectorTag var1, @Nonnull InteractionContext var2, @Nonnull Interaction var3) {
      this.current.data = this.function.apply(var1, var2, var3);
      class="kw">return false;
   }

   @Override
   class="kw">public void outof() {
      this.current = this.current.parent;
   }

   @Override
   class="kw">public void finished() {
   }

   class="kw">public class="kw">static class Node<T> {
      class="kw">public class="kw">static class="kw">final TreeCollector.Node[] EMPTY_ARRAY = new TreeCollector.Node[0];
      class="kw">private class="kw">final TreeCollector.Node<T> parent;
      class="kw">private TreeCollector.Node<T>[] children = EMPTY_ARRAY;
      class="kw">private T data;

      Node(TreeCollector.Node<T> var1) {
         this.parent = var1;
      }

      class="kw">public TreeCollector.Node<T> getParent() {
         class="kw">return this.parent;
      }

      class="kw">public TreeCollector.Node<T>[] getChildren() {
         class="kw">return this.children;
      }

      class="kw">public T getData() {
         class="kw">return this.data;
      }
   }
}