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

org.immutables.fixture.nullable.ImmutableNullableCompact Maven / Gradle / Ivy

package org.immutables.fixture.nullable;

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.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import java.util.Map;
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 NullableCompact}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableNullableCompact.builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableNullableCompact.of()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "NullableCompact"}) @Immutable public final class ImmutableNullableCompact extends NullableCompact { private final @Nullable Integer[] array; private final @Nullable ImmutableMap map; private ImmutableNullableCompact( @Nullable Integer[] array, @Nullable Map map) { this.array = array; this.map = map == null ? null : ImmutableMap.copyOf(map); } private ImmutableNullableCompact( ImmutableNullableCompact original, @Nullable Integer[] array, @Nullable ImmutableMap map) { this.array = array; this.map = map; } /** * @return A cloned {@code array} array */ @JsonProperty @Override public @Nullable Integer[] array() { return array; } /** * @return The value of the {@code map} attribute */ @JsonProperty @Override public @Nullable ImmutableMap map() { return map; } /** * Copy the current immutable object with elements that replace the content of {@link NullableCompact#array() array}. * The array is cloned before being saved as attribute values. * @param elements The non-null elements for array * @return A modified copy of {@code this} object */ public final ImmutableNullableCompact withArray(@Nullable Integer... elements) { @Nullable Integer[] newValue = elements == null ? null : elements.clone(); return new ImmutableNullableCompact(this, newValue, this.map); } /** * Copy the current immutable object by replacing the {@link NullableCompact#map() map} map with the specified map. * Nulls are not permitted as keys or values. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param map The entries to be added to the map map * @return A modified copy of {@code this} object */ public final ImmutableNullableCompact withMap(@Nullable Map map) { if (this.map == map) return this; @Nullable ImmutableMap newValue = map == null ? null : ImmutableMap.copyOf(map); return new ImmutableNullableCompact(this, this.array, newValue); } /** * This instance is equal to all instances of {@code ImmutableNullableCompact} 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 ImmutableNullableCompact && equalTo((ImmutableNullableCompact) another); } private boolean equalTo(ImmutableNullableCompact another) { return Arrays.equals(array, another.array) && Objects.equal(map, another.map); } /** * Computes a hash code from attributes: {@code array}, {@code map}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + Arrays.hashCode(array); h = h * 17 + Objects.hashCode(map); return h; } /** * Prints the immutable value {@code NullableCompact} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("NullableCompact") .omitNullValues() .add("array", Arrays.toString(array)) .add("map", map) .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 extends NullableCompact { @Nullable Integer[] array; @Nullable Map map; @JsonProperty public void setArray(@Nullable Integer[] array) { this.array = array; } @JsonProperty public void setMap(@Nullable Map map) { this.map = map; } @Override public Integer[] array() { throw new UnsupportedOperationException(); } @Override public Map map() { 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 ImmutableNullableCompact fromJson(Json json) { ImmutableNullableCompact.Builder builder = ImmutableNullableCompact.builder(); if (json.array != null) { builder.array(json.array); } if (json.map != null) { builder.putAllMap(json.map); } return builder.build(); } /** * Construct a new immutable {@code NullableCompact} instance. * @param array The value for the {@code array} attribute * @param map The value for the {@code map} attribute * @return An immutable NullableCompact instance */ public static ImmutableNullableCompact of(@Nullable Integer[] array, @Nullable Map map) { return new ImmutableNullableCompact(array, map); } /** * Creates an immutable copy of a {@link NullableCompact} 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 NullableCompact instance */ public static ImmutableNullableCompact copyOf(NullableCompact instance) { if (instance instanceof ImmutableNullableCompact) { return (ImmutableNullableCompact) instance; } return ImmutableNullableCompact.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableNullableCompact ImmutableNullableCompact}. * @return A new ImmutableNullableCompact builder */ public static ImmutableNullableCompact.Builder builder() { return new ImmutableNullableCompact.Builder(); } /** * Builds instances of type {@link ImmutableNullableCompact ImmutableNullableCompact}. * 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 @Nullable Integer[] array; private ImmutableMap.Builder map = null; private Builder() { } /** * Fill a builder with attribute values from the provided {@code NullableCompact} 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 */ public final Builder from(NullableCompact instance) { Preconditions.checkNotNull(instance, "instance"); @Nullable Integer[] arrayValue = instance.array(); if (arrayValue != null) { array(arrayValue); } putAllMap(instance.map()); return this; } /** * Initializes the value for the {@link NullableCompact#array() array} attribute. * @param array The elements for array * @return {@code this} builder for use in a chained invocation */ public final Builder array(Integer... array) { this.array = array; return this; } /** * Put one entry to the {@link NullableCompact#map() map} map. * @param key The key in the map map * @param value The associated value in the map map * @return {@code this} builder for use in a chained invocation */ public final Builder putMap(String key, Object value) { if (this.map == null) { this.map = ImmutableMap.builder(); } this.map.put(key, value); return this; } /** * Put one entry to the {@link NullableCompact#map() map} map. Nulls are not permitted * @param entry The key and value entry * @return {@code this} builder for use in a chained invocation */ public final Builder putMap(Map.Entry entry) { if (this.map == null) { this.map = ImmutableMap.builder(); } this.map.put(entry); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link NullableCompact#map() map} map. Nulls are not permitted as keys or values, but parameter itself can be null * @param map The entries that will be added to the map map * @return {@code this} builder for use in a chained invocation */ public final Builder map(@Nullable Map map) { if (map == null) { this.map = null; return this; } this.map = ImmutableMap.builder(); return putAllMap(map); } /** * Put all mappings from the specified map as entries to {@link NullableCompact#map() map} map. Nulls are not permitted * @param map The entries that will be added to the map map * @return {@code this} builder for use in a chained invocation */ public final Builder putAllMap(Map map) { if (this.map == null) { this.map = ImmutableMap.builder(); } this.map.putAll(map); return this; } /** * Builds a new {@link ImmutableNullableCompact ImmutableNullableCompact}. * @return An immutable instance of NullableCompact * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableNullableCompact build() { return new ImmutableNullableCompact(null, array, map == null ? null : map.build()); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy