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

io.ingenieux.lambada.testing.ImmutableLambadaClientContext Maven / Gradle / Ivy

The newest version!
package io.ingenieux.lambada.testing;

import com.amazonaws.services.lambda.runtime.Client;
import com.amazonaws.services.lambda.runtime.ClientContext;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Generated;

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

* Use the builder to create immutable instances: * {@code ImmutableLambadaClientContext.builder()}. */ @SuppressWarnings("all") @Generated({"Immutables.generator", "LambadaClientContext"}) public final class ImmutableLambadaClientContext implements LambadaClientContext { private final Client client; private final Map custom; private final Map environment; private ImmutableLambadaClientContext( Client client, Map custom, Map environment) { this.client = client; this.custom = custom; this.environment = environment; } /** * @return The value of the {@code client} attribute */ @Override public Client getClient() { return client; } /** * @return The value of the {@code custom} attribute */ @Override public Map getCustom() { return custom; } /** * @return The value of the {@code environment} attribute */ @Override public Map getEnvironment() { return environment; } /** * Copy the current immutable object by setting a value for the {@link LambadaClientContext#getClient() client} 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 client * @return A modified copy of the {@code this} object */ public final ImmutableLambadaClientContext withClient(Client value) { if (this.client == value) return this; return new ImmutableLambadaClientContext(Objects.requireNonNull(value, "client"), this.custom, this.environment); } /** * Copy the current immutable object by replacing the {@link LambadaClientContext#getCustom() custom} 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 entries The entries to be added to the custom map * @return A modified copy of {@code this} object */ public final ImmutableLambadaClientContext withCustom(Map entries) { if (this.custom == entries) return this; Map value = createUnmodifiableMap(true, entries); return new ImmutableLambadaClientContext(this.client, value, this.environment); } /** * Copy the current immutable object by replacing the {@link LambadaClientContext#getEnvironment() environment} 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 entries The entries to be added to the environment map * @return A modified copy of {@code this} object */ public final ImmutableLambadaClientContext withEnvironment(Map entries) { if (this.environment == entries) return this; Map value = createUnmodifiableMap(true, entries); return new ImmutableLambadaClientContext(this.client, this.custom, value); } /** * This instance is equal to all instances of {@code ImmutableLambadaClientContext} 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 ImmutableLambadaClientContext && equalTo((ImmutableLambadaClientContext) another); } private boolean equalTo(ImmutableLambadaClientContext another) { return client.equals(another.client) && custom.equals(another.custom) && environment.equals(another.environment); } /** * Computes a hash code from attributes: {@code client}, {@code custom}, {@code environment}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + client.hashCode(); h = h * 17 + custom.hashCode(); h = h * 17 + environment.hashCode(); return h; } /** * Prints the immutable value {@code LambadaClientContext} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "LambadaClientContext{" + "client=" + client + ", custom=" + custom + ", environment=" + environment + "}"; } /** * Creates an immutable copy of a {@link LambadaClientContext} 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 LambadaClientContext instance */ public static ImmutableLambadaClientContext copyOf(LambadaClientContext instance) { if (instance instanceof ImmutableLambadaClientContext) { return (ImmutableLambadaClientContext) instance; } return ImmutableLambadaClientContext.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableLambadaClientContext ImmutableLambadaClientContext}. * @return A new ImmutableLambadaClientContext builder */ public static ImmutableLambadaClientContext.Builder builder() { return new ImmutableLambadaClientContext.Builder(); } /** * Builds instances of type {@link ImmutableLambadaClientContext ImmutableLambadaClientContext}. * 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. */ public static final class Builder { private static final long INIT_BIT_CLIENT = 0x1L; private long initBits = 0x1; private Client client; private Map customBuilder = new LinkedHashMap(); private Map environmentBuilder = new LinkedHashMap(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code com.amazonaws.services.lambda.runtime.ClientContext} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(ClientContext instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code io.ingenieux.lambada.testing.LambadaClientContext} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(LambadaClientContext instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { if (object instanceof ClientContext) { ClientContext instance = (ClientContext) object; client(instance.getClient()); putAllEnvironment(instance.getEnvironment()); putAllCustom(instance.getCustom()); } } /** * Initializes the value for the {@link LambadaClientContext#getClient() client} attribute. * @param client The value for client * @return {@code this} builder for use in a chained invocation */ public final Builder client(Client client) { this.client = Objects.requireNonNull(client, "client"); initBits &= ~INIT_BIT_CLIENT; return this; } /** * Put one entry to the {@link LambadaClientContext#getCustom() custom} map. * @param key The key in the custom map * @param value The associated value in the custom map * @return {@code this} builder for use in a chained invocation */ public final Builder putCustom(String key, String value) { customBuilder.put( Objects.requireNonNull(key, "custom key"), Objects.requireNonNull(value, "custom value")); return this; } /** * Put one entry to the {@link LambadaClientContext#getCustom() custom} 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 putCustom(Map.Entry entry) { customBuilder.put( Objects.requireNonNull(entry.getKey(), "custom key"), Objects.requireNonNull(entry.getValue(), "custom value")); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link LambadaClientContext#getCustom() custom} map. Nulls are not permitted * @param entries The entries that will be added to the custom map * @return {@code this} builder for use in a chained invocation */ public final Builder custom(Map entries) { customBuilder.clear(); return putAllCustom(entries); } /** * Put all mappings from the specified map as entries to {@link LambadaClientContext#getCustom() custom} map. Nulls are not permitted * @param entries The entries that will be added to the custom map * @return {@code this} builder for use in a chained invocation */ public final Builder putAllCustom(Map entries) { for (Map.Entry entry : entries.entrySet()) { customBuilder.put( Objects.requireNonNull(entry.getKey(), "custom key"), Objects.requireNonNull(entry.getValue(), "custom value")); } return this; } /** * Put one entry to the {@link LambadaClientContext#getEnvironment() environment} map. * @param key The key in the environment map * @param value The associated value in the environment map * @return {@code this} builder for use in a chained invocation */ public final Builder putEnvironment(String key, String value) { environmentBuilder.put( Objects.requireNonNull(key, "environment key"), Objects.requireNonNull(value, "environment value")); return this; } /** * Put one entry to the {@link LambadaClientContext#getEnvironment() environment} 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 putEnvironment(Map.Entry entry) { environmentBuilder.put( Objects.requireNonNull(entry.getKey(), "environment key"), Objects.requireNonNull(entry.getValue(), "environment value")); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link LambadaClientContext#getEnvironment() environment} map. Nulls are not permitted * @param entries The entries that will be added to the environment map * @return {@code this} builder for use in a chained invocation */ public final Builder environment(Map entries) { environmentBuilder.clear(); return putAllEnvironment(entries); } /** * Put all mappings from the specified map as entries to {@link LambadaClientContext#getEnvironment() environment} map. Nulls are not permitted * @param entries The entries that will be added to the environment map * @return {@code this} builder for use in a chained invocation */ public final Builder putAllEnvironment(Map entries) { for (Map.Entry entry : entries.entrySet()) { environmentBuilder.put( Objects.requireNonNull(entry.getKey(), "environment key"), Objects.requireNonNull(entry.getValue(), "environment value")); } return this; } /** * Builds a new {@link ImmutableLambadaClientContext ImmutableLambadaClientContext}. * @return An immutable instance of LambadaClientContext * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableLambadaClientContext build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableLambadaClientContext( client, createUnmodifiableMap(false, customBuilder), createUnmodifiableMap(false, environmentBuilder)); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList(); if ((initBits & INIT_BIT_CLIENT) != 0) attributes.add("client"); return "Cannot build LambadaClientContext, some of required attributes are not set " + attributes; } } private static Map createUnmodifiableMap(boolean checkNulls, Map map) { Map linkedMap = new LinkedHashMap(map.size()); linkedMap.putAll(map); if (checkNulls) { for (Map.Entry e : linkedMap.entrySet()) { Objects.requireNonNull(e.getKey(), "key"); Objects.requireNonNull(e.getValue(), "value"); } } switch (linkedMap.size()) { case 0: return Collections.emptyMap(); case 1: Map.Entry e = linkedMap.entrySet().iterator().next(); return Collections.singletonMap(e.getKey(), e.getValue()); default: return Collections.unmodifiableMap(linkedMap); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy