All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.lenni0451.mcstructs_bedrock.text.components.RootBedrockComponent Maven / Gradle / Ivy

Go to download

A minecraft bedrock data structure library with the goal of being compliant with the vanilla client

The newest version!
package net.lenni0451.mcstructs_bedrock.text.components;

import net.lenni0451.mcstructs_bedrock.text.ABedrockComponent;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;

public class RootBedrockComponent extends ABedrockComponent {

    private final List components;

    public RootBedrockComponent() {
        this.components = new ArrayList<>();
    }

    public RootBedrockComponent(final ABedrockComponent... components) {
        this.components = new ArrayList<>();
        this.components.addAll(Arrays.asList(components));
    }

    public RootBedrockComponent(final List components) {
        this.components = components;
    }

    /**
     * @return The components of this root component
     */
    public List getComponents() {
        return this.components;
    }

    /**
     * Add a component to this root component.
     *
     * @param component The component to add
     * @return This root component
     */
    public RootBedrockComponent addComponent(final ABedrockComponent component) {
        this.components.add(component);
        return this;
    }

    /**
     * Iterate over all components and their siblings.
     *
     * @param consumer The consumer that will be called for every component
     * @return This component
     */
    public RootBedrockComponent forEach(final Consumer consumer) {
        consumer.accept(this);
        for (ABedrockComponent component : this.components) {
            if (component instanceof RootBedrockComponent) ((RootBedrockComponent) component).forEach(consumer);
            else consumer.accept(component);
        }
        return this;
    }

    @Override
    public String asString() {
        StringBuilder out = new StringBuilder();
        for (ABedrockComponent component : this.components) out.append(component.asString());
        return out.toString();
    }

    @Override
    public ABedrockComponent copy() {
        RootBedrockComponent out = new RootBedrockComponent();
        for (ABedrockComponent component : this.components) out.addComponent(component.copy());
        return out;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RootBedrockComponent that = (RootBedrockComponent) o;
        return Objects.equals(this.components, that.components);
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.components);
    }

    @Override
    public String toString() {
        return "RootBedrockComponent{" +
                "components=" + this.components +
                '}';
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy