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

org.immutables.fixture.ImmutableOrderAttributeValue Maven / Gradle / Ivy

package org.immutables.fixture;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Ordering;
import com.google.common.primitives.Ints;
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 OrderAttributeValue}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableOrderAttributeValue.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "OrderAttributeValue"}) @Immutable public final class ImmutableOrderAttributeValue extends OrderAttributeValue { private final ImmutableSortedSet natural; private final ImmutableSortedSet reverse; private final ImmutableSortedMap reverseMap; private final ImmutableSortedMap navigableMap; private ImmutableOrderAttributeValue( ImmutableSortedSet natural, ImmutableSortedSet reverse, ImmutableSortedMap reverseMap, ImmutableSortedMap navigableMap) { this.natural = natural; this.reverse = reverse; this.reverseMap = reverseMap; this.navigableMap = navigableMap; } /** * @return The value of the {@code natural} attribute */ @Override public ImmutableSortedSet natural() { return natural; } /** * @return The value of the {@code reverse} attribute */ @Override public ImmutableSortedSet reverse() { return reverse; } /** * @return The value of the {@code reverseMap} attribute */ @Override public ImmutableSortedMap reverseMap() { return reverseMap; } /** * @return The value of the {@code navigableMap} attribute */ @Override public ImmutableSortedMap navigableMap() { return navigableMap; } /** * Copy the current immutable object with elements that replace the content of {@link OrderAttributeValue#natural() natural}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableOrderAttributeValue withNatural(int... elements) { ImmutableSortedSet newValue = ImmutableSortedSet.copyOf( Ordering.natural(), Ints.asList(elements)); return new ImmutableOrderAttributeValue(newValue, this.reverse, this.reverseMap, this.navigableMap); } /** * Copy the current immutable object with elements that replace the content of {@link OrderAttributeValue#natural() natural}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of natural elements to set * @return A modified copy of {@code this} object */ public final ImmutableOrderAttributeValue withNatural(Iterable elements) { if (this.natural == elements) return this; ImmutableSortedSet newValue = ImmutableSortedSet.copyOf( Ordering.natural(), elements); return new ImmutableOrderAttributeValue(newValue, this.reverse, this.reverseMap, this.navigableMap); } /** * Copy the current immutable object with elements that replace the content of {@link OrderAttributeValue#reverse() reverse}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableOrderAttributeValue withReverse(String... elements) { ImmutableSortedSet newValue = ImmutableSortedSet.copyOf( Ordering.natural().reverse(), Arrays.asList(elements)); return new ImmutableOrderAttributeValue(this.natural, newValue, this.reverseMap, this.navigableMap); } /** * Copy the current immutable object with elements that replace the content of {@link OrderAttributeValue#reverse() reverse}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of reverse elements to set * @return A modified copy of {@code this} object */ public final ImmutableOrderAttributeValue withReverse(Iterable elements) { if (this.reverse == elements) return this; ImmutableSortedSet newValue = ImmutableSortedSet.copyOf( Ordering.natural().reverse(), elements); return new ImmutableOrderAttributeValue(this.natural, newValue, this.reverseMap, this.navigableMap); } /** * Copy the current immutable object by replacing the {@link OrderAttributeValue#reverseMap() reverseMap} 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 reverseMap The entries to be added to the reverseMap map * @return A modified copy of {@code this} object */ public final ImmutableOrderAttributeValue withReverseMap(Map reverseMap) { if (this.reverseMap == reverseMap) return this; ImmutableSortedMap newValue = ImmutableSortedMap.copyOf(reverseMap, Ordering.natural().reverse() ); return new ImmutableOrderAttributeValue(this.natural, this.reverse, newValue, this.navigableMap); } /** * Copy the current immutable object by replacing the {@link OrderAttributeValue#navigableMap() navigableMap} 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 navigableMap The entries to be added to the navigableMap map * @return A modified copy of {@code this} object */ public final ImmutableOrderAttributeValue withNavigableMap(Map navigableMap) { if (this.navigableMap == navigableMap) return this; ImmutableSortedMap newValue = ImmutableSortedMap.copyOf(navigableMap, Ordering.natural() ); return new ImmutableOrderAttributeValue(this.natural, this.reverse, this.reverseMap, newValue); } /** * This instance is equal to all instances of {@code ImmutableOrderAttributeValue} 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 ImmutableOrderAttributeValue && equalTo((ImmutableOrderAttributeValue) another); } private boolean equalTo(ImmutableOrderAttributeValue another) { return natural.equals(another.natural) && reverse.equals(another.reverse) && reverseMap.equals(another.reverseMap) && navigableMap.equals(another.navigableMap); } /** * Computes a hash code from attributes: {@code natural}, {@code reverse}, {@code reverseMap}, {@code navigableMap}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + natural.hashCode(); h = h * 17 + reverse.hashCode(); h = h * 17 + reverseMap.hashCode(); h = h * 17 + navigableMap.hashCode(); return h; } /** * Prints the immutable value {@code OrderAttributeValue} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("OrderAttributeValue") .omitNullValues() .add("natural", natural) .add("reverse", reverse) .add("reverseMap", reverseMap) .add("navigableMap", navigableMap) .toString(); } /** * Creates an immutable copy of a {@link OrderAttributeValue} 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 OrderAttributeValue instance */ public static ImmutableOrderAttributeValue copyOf(OrderAttributeValue instance) { if (instance instanceof ImmutableOrderAttributeValue) { return (ImmutableOrderAttributeValue) instance; } return ImmutableOrderAttributeValue.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableOrderAttributeValue ImmutableOrderAttributeValue}. * @return A new ImmutableOrderAttributeValue builder */ public static ImmutableOrderAttributeValue.Builder builder() { return new ImmutableOrderAttributeValue.Builder(); } /** * Builds instances of type {@link ImmutableOrderAttributeValue ImmutableOrderAttributeValue}. * 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 ImmutableSortedSet.Builder natural = ImmutableSortedSet.naturalOrder(); private ImmutableSortedSet.Builder reverse = ImmutableSortedSet.reverseOrder(); private ImmutableSortedMap.Builder reverseMap = ImmutableSortedMap.reverseOrder(); private ImmutableSortedMap.Builder navigableMap = ImmutableSortedMap.naturalOrder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code OrderAttributeValue} 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(OrderAttributeValue instance) { Preconditions.checkNotNull(instance, "instance"); addAllNatural(instance.natural()); addAllReverse(instance.reverse()); putAllReverseMap(instance.reverseMap()); putAllNavigableMap(instance.navigableMap()); return this; } /** * Adds one element to {@link OrderAttributeValue#natural() natural} sortedSet. * @param element A natural element * @return {@code this} builder for use in a chained invocation */ public final Builder addNatural(int element) { this.natural.add(element); return this; } /** * Adds elements to {@link OrderAttributeValue#natural() natural} sortedSet. * @param elements An array of natural elements * @return {@code this} builder for use in a chained invocation */ public final Builder addNatural(int... elements) { this.natural.addAll(Ints.asList(elements)); return this; } /** * Sets or replaces all elements for {@link OrderAttributeValue#natural() natural} sortedSet. * @param elements An iterable of natural elements * @return {@code this} builder for use in a chained invocation */ public final Builder natural(Iterable elements) { this.natural = ImmutableSortedSet.naturalOrder(); return addAllNatural(elements); } /** * Adds elements to {@link OrderAttributeValue#natural() natural} sortedSet. * @param elements An iterable of natural elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllNatural(Iterable elements) { this.natural.addAll(elements); return this; } /** * Adds one element to {@link OrderAttributeValue#reverse() reverse} sortedSet. * @param element A reverse element * @return {@code this} builder for use in a chained invocation */ public final Builder addReverse(String element) { this.reverse.add(element); return this; } /** * Adds elements to {@link OrderAttributeValue#reverse() reverse} sortedSet. * @param elements An array of reverse elements * @return {@code this} builder for use in a chained invocation */ public final Builder addReverse(String... elements) { this.reverse.addAll(Arrays.asList(elements)); return this; } /** * Sets or replaces all elements for {@link OrderAttributeValue#reverse() reverse} sortedSet. * @param elements An iterable of reverse elements * @return {@code this} builder for use in a chained invocation */ public final Builder reverse(Iterable elements) { this.reverse = ImmutableSortedSet.reverseOrder(); return addAllReverse(elements); } /** * Adds elements to {@link OrderAttributeValue#reverse() reverse} sortedSet. * @param elements An iterable of reverse elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllReverse(Iterable elements) { this.reverse.addAll(elements); return this; } /** * Put one entry to the {@link OrderAttributeValue#reverseMap() reverseMap} map. * @param key The key in the reverseMap map * @param value The associated value in the reverseMap map * @return {@code this} builder for use in a chained invocation */ public final Builder putReverseMap(String key, String value) { this.reverseMap.put(key, value); return this; } /** * Put one entry to the {@link OrderAttributeValue#reverseMap() reverseMap} 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 putReverseMap(Map.Entry entry) { this.reverseMap.put(entry); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link OrderAttributeValue#reverseMap() reverseMap} map. Nulls are not permitted * @param reverseMap The entries that will be added to the reverseMap map * @return {@code this} builder for use in a chained invocation */ public final Builder reverseMap(Map reverseMap) { this.reverseMap = ImmutableSortedMap.reverseOrder(); return putAllReverseMap(reverseMap); } /** * Put all mappings from the specified map as entries to {@link OrderAttributeValue#reverseMap() reverseMap} map. Nulls are not permitted * @param reverseMap The entries that will be added to the reverseMap map * @return {@code this} builder for use in a chained invocation */ public final Builder putAllReverseMap(Map reverseMap) { this.reverseMap.putAll(reverseMap); return this; } /** * Put one entry to the {@link OrderAttributeValue#navigableMap() navigableMap} map. * @param key The key in the navigableMap map * @param value The associated value in the navigableMap map * @return {@code this} builder for use in a chained invocation */ public final Builder putNavigableMap(int key, String value) { this.navigableMap.put(key, value); return this; } /** * Put one entry to the {@link OrderAttributeValue#navigableMap() navigableMap} 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 putNavigableMap(Map.Entry entry) { this.navigableMap.put(entry); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link OrderAttributeValue#navigableMap() navigableMap} map. Nulls are not permitted * @param navigableMap The entries that will be added to the navigableMap map * @return {@code this} builder for use in a chained invocation */ public final Builder navigableMap(Map navigableMap) { this.navigableMap = ImmutableSortedMap.naturalOrder(); return putAllNavigableMap(navigableMap); } /** * Put all mappings from the specified map as entries to {@link OrderAttributeValue#navigableMap() navigableMap} map. Nulls are not permitted * @param navigableMap The entries that will be added to the navigableMap map * @return {@code this} builder for use in a chained invocation */ public final Builder putAllNavigableMap(Map navigableMap) { this.navigableMap.putAll(navigableMap); return this; } /** * Builds a new {@link ImmutableOrderAttributeValue ImmutableOrderAttributeValue}. * @return An immutable instance of OrderAttributeValue * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableOrderAttributeValue build() { return new ImmutableOrderAttributeValue(natural.build(), reverse.build(), reverseMap.build(), navigableMap.build()); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy