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

org.immutables.fixture.jackson.ImmutableAttributeIs Maven / Gradle / Ivy

package org.immutables.fixture.jackson;

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.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.primitives.Booleans;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

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

* Use the builder to create immutable instances: * {@code ImmutableAttributeIs.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "AttributeIs"}) @Immutable public final class ImmutableAttributeIs implements AttributeIs { private final boolean isEmpty; private final boolean empty; private ImmutableAttributeIs(boolean isEmpty, boolean empty) { this.isEmpty = isEmpty; this.empty = empty; } /** * @return The value of the {@code isEmpty} attribute */ @JsonProperty("isEmpty") @Override public boolean isEmpty() { return isEmpty; } /** * @return The value of the {@code empty} attribute */ @JsonProperty("empty") @Override public boolean getEmpty() { return empty; } /** * Copy the current immutable object by setting a value for the {@link AttributeIs#isEmpty() isEmpty} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param isEmpty A new value for isEmpty * @return A modified copy of the {@code this} object */ public final ImmutableAttributeIs withIsEmpty(boolean isEmpty) { if (this.isEmpty == isEmpty) return this; return new ImmutableAttributeIs(isEmpty, this.empty); } /** * Copy the current immutable object by setting a value for the {@link AttributeIs#getEmpty() empty} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param empty A new value for empty * @return A modified copy of the {@code this} object */ public final ImmutableAttributeIs withEmpty(boolean empty) { if (this.empty == empty) return this; return new ImmutableAttributeIs(this.isEmpty, empty); } /** * This instance is equal to all instances of {@code ImmutableAttributeIs} 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 ImmutableAttributeIs && equalTo((ImmutableAttributeIs) another); } private boolean equalTo(ImmutableAttributeIs another) { return isEmpty == another.isEmpty && empty == another.empty; } /** * Computes a hash code from attributes: {@code isEmpty}, {@code empty}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + Booleans.hashCode(isEmpty); h = h * 17 + Booleans.hashCode(empty); return h; } /** * Prints the immutable value {@code AttributeIs} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("AttributeIs") .omitNullValues() .add("isEmpty", isEmpty) .add("empty", empty) .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 */ @Deprecated @JsonDeserialize static final class Json implements AttributeIs { @Nullable Boolean isEmpty; @Nullable Boolean empty; @JsonProperty("isEmpty") public void setIsEmpty(boolean isEmpty) { this.isEmpty = isEmpty; } @JsonProperty("empty") public void setEmpty(boolean empty) { this.empty = empty; } @Override public boolean isEmpty() { throw new UnsupportedOperationException(); } @Override public boolean getEmpty() { 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 static ImmutableAttributeIs fromJson(Json json) { ImmutableAttributeIs.Builder builder = ImmutableAttributeIs.builder(); if (json.isEmpty != null) { builder.isEmpty(json.isEmpty); } if (json.empty != null) { builder.empty(json.empty); } return builder.build(); } /** * Creates an immutable copy of a {@link AttributeIs} 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 AttributeIs instance */ public static ImmutableAttributeIs copyOf(AttributeIs instance) { if (instance instanceof ImmutableAttributeIs) { return (ImmutableAttributeIs) instance; } return ImmutableAttributeIs.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableAttributeIs ImmutableAttributeIs}. * @return A new ImmutableAttributeIs builder */ public static ImmutableAttributeIs.Builder builder() { return new ImmutableAttributeIs.Builder(); } /** * Builds instances of type {@link ImmutableAttributeIs ImmutableAttributeIs}. * 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. */ @NotThreadSafe public static final class Builder { private static final long INIT_BIT_IS_EMPTY = 0x1L; private static final long INIT_BIT_EMPTY = 0x2L; private long initBits = 0x3L; private boolean isEmpty; private boolean empty; private Builder() { } /** * Fill a builder with attribute values from the provided {@code AttributeIs} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(AttributeIs instance) { Preconditions.checkNotNull(instance, "instance"); isEmpty(instance.isEmpty()); empty(instance.getEmpty()); return this; } /** * Initializes the value for the {@link AttributeIs#isEmpty() isEmpty} attribute. * @param isEmpty The value for isEmpty * @return {@code this} builder for use in a chained invocation */ public final Builder isEmpty(boolean isEmpty) { this.isEmpty = isEmpty; initBits &= ~INIT_BIT_IS_EMPTY; return this; } /** * Initializes the value for the {@link AttributeIs#getEmpty() empty} attribute. * @param empty The value for empty * @return {@code this} builder for use in a chained invocation */ public final Builder empty(boolean empty) { this.empty = empty; initBits &= ~INIT_BIT_EMPTY; return this; } /** * Builds a new {@link ImmutableAttributeIs ImmutableAttributeIs}. * @return An immutable instance of AttributeIs * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableAttributeIs build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableAttributeIs(isEmpty, empty); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_IS_EMPTY) != 0) attributes.add("isEmpty"); if ((initBits & INIT_BIT_EMPTY) != 0) attributes.add("empty"); return "Cannot build AttributeIs, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy