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

wtf.metio.yosql.models.configuration.ImmutableAnnotation Maven / Gradle / Ivy

package wtf.metio.yosql.models.configuration;

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 java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.immutables.value.Generated;

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

* Use the builder to create immutable instances: * {@code ImmutableAnnotation.builder()}. */ @Generated(from = "Annotation", generator = "Immutables") @SuppressWarnings({"all"}) @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") public final class ImmutableAnnotation implements Annotation { private final String type; private final List members; private ImmutableAnnotation( String type, List members) { this.type = type; this.members = members; } /** * @return The fully-qualified type name of this annotation. */ @JsonProperty("type") @Override public String type() { return type; } /** * @return The members of this annotation. */ @JsonProperty("members") @Override public List members() { return members; } /** * Copy the current immutable object by setting a value for the {@link Annotation#type() type} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for type * @return A modified copy of the {@code this} object */ public final ImmutableAnnotation withType(String value) { String newValue = Objects.requireNonNull(value, "type"); if (this.type.equals(newValue)) return this; return new ImmutableAnnotation(newValue, this.members); } /** * Copy the current immutable object with elements that replace the content of {@link Annotation#members() members}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableAnnotation withMembers(AnnotationMember... elements) { List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return new ImmutableAnnotation(this.type, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link Annotation#members() members}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of members elements to set * @return A modified copy of {@code this} object */ public final ImmutableAnnotation withMembers(Iterable elements) { if (this.members == elements) return this; List newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return new ImmutableAnnotation(this.type, newValue); } /** * This instance is equal to all instances of {@code ImmutableAnnotation} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(Object another) { if (this == another) return true; return another instanceof ImmutableAnnotation && equalTo(0, (ImmutableAnnotation) another); } private boolean equalTo(int synthetic, ImmutableAnnotation another) { return type.equals(another.type) && members.equals(another.members); } /** * Computes a hash code from attributes: {@code type}, {@code members}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + type.hashCode(); h += (h << 5) + members.hashCode(); return h; } /** * Prints the immutable value {@code Annotation} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "Annotation{" + "type=" + type + ", members=" + members + "}"; } /** * 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 = "Annotation", generator = "Immutables") @Deprecated @JsonDeserialize @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements Annotation { String type; List members = Collections.emptyList(); @JsonProperty("type") public void setType(String type) { this.type = type; } @JsonProperty("members") public void setMembers(List members) { this.members = members; } @Override public String type() { throw new UnsupportedOperationException(); } @Override public List members() { 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 ImmutableAnnotation fromJson(Json json) { ImmutableAnnotation.Builder builder = ((ImmutableAnnotation.Builder) ImmutableAnnotation.builder()); if (json.type != null) { builder.setType(json.type); } if (json.members != null) { builder.addAllMembers(json.members); } return builder.build(); } /** * Creates an immutable copy of a {@link Annotation} 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 Annotation instance */ public static ImmutableAnnotation copyOf(Annotation instance) { if (instance instanceof ImmutableAnnotation) { return (ImmutableAnnotation) instance; } return ((ImmutableAnnotation.Builder) ImmutableAnnotation.builder()) .setType(instance.type()) .addAllMembers(instance.members()) .build(); } /** * Creates a builder for {@link ImmutableAnnotation ImmutableAnnotation}. *

   * ImmutableAnnotation.builder()
   *    .setType(String) // required {@link Annotation#type() type}
   *    .addMembers|addAllMembers(wtf.metio.yosql.models.configuration.AnnotationMember) // {@link Annotation#members() members} elements
   *    .build();
   * 
* @return A new ImmutableAnnotation builder */ public static TypeBuildStage builder() { return new ImmutableAnnotation.Builder(); } /** * Builds instances of type {@link ImmutableAnnotation ImmutableAnnotation}. * 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 = "Annotation", generator = "Immutables") public static final class Builder implements TypeBuildStage, BuildFinal { private static final long INIT_BIT_TYPE = 0x1L; private long initBits = 0x1L; private String type; private final List members = new ArrayList(); private Builder() { } /** * Initializes the value for the {@link Annotation#type() type} attribute. * @param type The value for type * @return {@code this} builder for use in a chained invocation */ @JsonProperty("type") public final Builder setType(String type) { checkNotIsSet(typeIsSet(), "type"); this.type = Objects.requireNonNull(type, "type"); initBits &= ~INIT_BIT_TYPE; return this; } /** * Adds one element to {@link Annotation#members() members} list. * @param element A members element * @return {@code this} builder for use in a chained invocation */ public final Builder addMembers(AnnotationMember element) { this.members.add(Objects.requireNonNull(element, "members element")); return this; } /** * Adds elements to {@link Annotation#members() members} list. * @param elements An array of members elements * @return {@code this} builder for use in a chained invocation */ public final Builder addMembers(AnnotationMember... elements) { for (AnnotationMember element : elements) { this.members.add(Objects.requireNonNull(element, "members element")); } return this; } /** * Adds elements to {@link Annotation#members() members} list. * @param elements An iterable of members elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllMembers(Iterable elements) { for (AnnotationMember element : elements) { this.members.add(Objects.requireNonNull(element, "members element")); } return this; } /** * Builds a new {@link ImmutableAnnotation ImmutableAnnotation}. * @return An immutable instance of Annotation * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableAnnotation build() { checkRequiredAttributes(); return new ImmutableAnnotation(type, createUnmodifiableList(true, members)); } private boolean typeIsSet() { return (initBits & INIT_BIT_TYPE) == 0; } private static void checkNotIsSet(boolean isSet, String name) { if (isSet) throw new IllegalStateException("Builder of Annotation is strict, attribute is already set: ".concat(name)); } private void checkRequiredAttributes() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if (!typeIsSet()) attributes.add("type"); return "Cannot build Annotation, some of required attributes are not set " + attributes; } } @Generated(from = "Annotation", generator = "Immutables") public interface TypeBuildStage { /** * Initializes the value for the {@link Annotation#type() type} attribute. * @param type The value for type * @return {@code this} builder for use in a chained invocation */ BuildFinal setType(String type); } @Generated(from = "Annotation", generator = "Immutables") public interface BuildFinal { /** * Adds one element to {@link Annotation#members() members} list. * @param element A members element * @return {@code this} builder for use in a chained invocation */ BuildFinal addMembers(AnnotationMember element); /** * Adds elements to {@link Annotation#members() members} list. * @param elements An array of members elements * @return {@code this} builder for use in a chained invocation */ BuildFinal addMembers(AnnotationMember... elements); /** * Adds elements to {@link Annotation#members() members} list. * @param elements An iterable of members elements * @return {@code this} builder for use in a chained invocation */ BuildFinal addAllMembers(Iterable elements); /** * Builds a new {@link ImmutableAnnotation ImmutableAnnotation}. * @return An immutable instance of Annotation * @throws java.lang.IllegalStateException if any required attributes are missing */ ImmutableAnnotation build(); } private static List createSafeList(Iterable iterable, boolean checkNulls, boolean skipNulls) { ArrayList list; if (iterable instanceof Collection) { int size = ((Collection) iterable).size(); if (size == 0) return Collections.emptyList(); list = new ArrayList<>(); } else { list = new ArrayList<>(); } for (T element : iterable) { if (skipNulls && element == null) continue; if (checkNulls) Objects.requireNonNull(element, "element"); list.add(element); } return list; } private static List createUnmodifiableList(boolean clone, List list) { switch(list.size()) { case 0: return Collections.emptyList(); case 1: return Collections.singletonList(list.get(0)); default: if (clone) { return Collections.unmodifiableList(new ArrayList<>(list)); } else { if (list instanceof ArrayList) { ((ArrayList) list).trimToSize(); } return Collections.unmodifiableList(list); } } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy