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

io.protostuff.generator.html.json.index.ImmutableJsonTreeNode Maven / Gradle / Ivy

There is a newer version: 3.1.40
Show newest version
package io.protostuff.generator.html.json.index;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link JsonTreeNode}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableJsonTreeNode.builder()}. */ @Generated(from = "JsonTreeNode", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableJsonTreeNode implements JsonTreeNode { private final String label; private final NodeData data; private final ImmutableList children; private ImmutableJsonTreeNode( String label, NodeData data, ImmutableList children) { this.label = label; this.data = data; this.children = children; } /** * @return The value of the {@code label} attribute */ @JsonProperty("label") @Override public String label() { return label; } /** * @return The value of the {@code data} attribute */ @JsonProperty("data") @Override public NodeData data() { return data; } /** * @return The value of the {@code children} attribute */ @JsonProperty("children") @Override public ImmutableList children() { return children; } /** * Copy the current immutable object by setting a value for the {@link JsonTreeNode#label() label} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for label * @return A modified copy of the {@code this} object */ public final ImmutableJsonTreeNode withLabel(String value) { String newValue = Objects.requireNonNull(value, "label"); if (this.label.equals(newValue)) return this; return new ImmutableJsonTreeNode(newValue, this.data, this.children); } /** * Copy the current immutable object by setting a value for the {@link JsonTreeNode#data() data} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for data * @return A modified copy of the {@code this} object */ public final ImmutableJsonTreeNode withData(NodeData value) { if (this.data == value) return this; NodeData newValue = Objects.requireNonNull(value, "data"); return new ImmutableJsonTreeNode(this.label, newValue, this.children); } /** * Copy the current immutable object with elements that replace the content of {@link JsonTreeNode#children() children}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableJsonTreeNode withChildren(JsonTreeNode... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableJsonTreeNode(this.label, this.data, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link JsonTreeNode#children() children}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of children elements to set * @return A modified copy of {@code this} object */ public final ImmutableJsonTreeNode withChildren(Iterable elements) { if (this.children == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableJsonTreeNode(this.label, this.data, newValue); } /** * This instance is equal to all instances of {@code ImmutableJsonTreeNode} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableJsonTreeNode && equalTo((ImmutableJsonTreeNode) another); } private boolean equalTo(ImmutableJsonTreeNode another) { return label.equals(another.label) && data.equals(another.data) && children.equals(another.children); } /** * Computes a hash code from attributes: {@code label}, {@code data}, {@code children}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + label.hashCode(); h += (h << 5) + data.hashCode(); h += (h << 5) + children.hashCode(); return h; } /** * Prints the immutable value {@code JsonTreeNode} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("JsonTreeNode") .omitNullValues() .add("label", label) .add("data", data) .add("children", children) .toString(); } /** * Utility type used to correctly read immutable object from JSON representation. * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure */ @Generated(from = "JsonTreeNode", generator = "Immutables") @Deprecated @SuppressWarnings("Immutable") @JsonDeserialize @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements JsonTreeNode { @Nullable String label; @Nullable NodeData data; @Nullable List children = ImmutableList.of(); @JsonProperty("label") public void setLabel(String label) { this.label = label; } @JsonProperty("data") public void setData(NodeData data) { this.data = data; } @JsonProperty("children") public void setChildren(List children) { this.children = children; } @Override public String label() { throw new UnsupportedOperationException(); } @Override public NodeData data() { throw new UnsupportedOperationException(); } @Override public List children() { throw new UnsupportedOperationException(); } } /** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonCreator(mode = JsonCreator.Mode.DELEGATING) static ImmutableJsonTreeNode fromJson(Json json) { ImmutableJsonTreeNode.Builder builder = ImmutableJsonTreeNode.builder(); if (json.label != null) { builder.label(json.label); } if (json.data != null) { builder.data(json.data); } if (json.children != null) { builder.addAllChildren(json.children); } return builder.build(); } /** * Creates an immutable copy of a {@link JsonTreeNode} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable JsonTreeNode instance */ public static ImmutableJsonTreeNode copyOf(JsonTreeNode instance) { if (instance instanceof ImmutableJsonTreeNode) { return (ImmutableJsonTreeNode) instance; } return ImmutableJsonTreeNode.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableJsonTreeNode ImmutableJsonTreeNode}. *

   * ImmutableJsonTreeNode.builder()
   *    .label(String) // required {@link JsonTreeNode#label() label}
   *    .data(io.protostuff.generator.html.json.index.NodeData) // required {@link JsonTreeNode#data() data}
   *    .addChildren|addAllChildren(io.protostuff.generator.html.json.index.JsonTreeNode) // {@link JsonTreeNode#children() children} elements
   *    .build();
   * 
* @return A new ImmutableJsonTreeNode builder */ public static ImmutableJsonTreeNode.Builder builder() { return new ImmutableJsonTreeNode.Builder(); } /** * Builds instances of type {@link ImmutableJsonTreeNode ImmutableJsonTreeNode}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @Generated(from = "JsonTreeNode", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_LABEL = 0x1L; private static final long INIT_BIT_DATA = 0x2L; private long initBits = 0x3L; private @Nullable String label; private @Nullable NodeData data; private ImmutableList.Builder children = ImmutableList.builder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code JsonTreeNode} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(JsonTreeNode instance) { Objects.requireNonNull(instance, "instance"); label(instance.label()); data(instance.data()); addAllChildren(instance.children()); return this; } /** * Initializes the value for the {@link JsonTreeNode#label() label} attribute. * @param label The value for label * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("label") public final Builder label(String label) { this.label = Objects.requireNonNull(label, "label"); initBits &= ~INIT_BIT_LABEL; return this; } /** * Initializes the value for the {@link JsonTreeNode#data() data} attribute. * @param data The value for data * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("data") public final Builder data(NodeData data) { this.data = Objects.requireNonNull(data, "data"); initBits &= ~INIT_BIT_DATA; return this; } /** * Adds one element to {@link JsonTreeNode#children() children} list. * @param element A children element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addChildren(JsonTreeNode element) { this.children.add(element); return this; } /** * Adds elements to {@link JsonTreeNode#children() children} list. * @param elements An array of children elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addChildren(JsonTreeNode... elements) { this.children.add(elements); return this; } /** * Sets or replaces all elements for {@link JsonTreeNode#children() children} list. * @param elements An iterable of children elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("children") public final Builder children(Iterable elements) { this.children = ImmutableList.builder(); return addAllChildren(elements); } /** * Adds elements to {@link JsonTreeNode#children() children} list. * @param elements An iterable of children elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllChildren(Iterable elements) { this.children.addAll(elements); return this; } /** * Builds a new {@link ImmutableJsonTreeNode ImmutableJsonTreeNode}. * @return An immutable instance of JsonTreeNode * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableJsonTreeNode build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableJsonTreeNode(label, data, children.build()); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_LABEL) != 0) attributes.add("label"); if ((initBits & INIT_BIT_DATA) != 0) attributes.add("data"); return "Cannot build JsonTreeNode, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy