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

com.kidsoncoffee.cheesecakes.ImmutableRegistrableConverter Maven / Gradle / Ivy

package com.kidsoncoffee.cheesecakes;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link Parameter.RegistrableConverter}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableRegistrableConverter.registrableConverter()}. * Use the static factory method to create immutable instances: * {@code ImmutableRegistrableConverter.of()}. */ @Generated(from = "Parameter.RegistrableConverter", generator = "Immutables") @SuppressWarnings({"all"}) @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") public final class ImmutableRegistrableConverter extends Parameter.RegistrableConverter { private final Class targetType; private final Function converter; private ImmutableRegistrableConverter( Class targetType, Function converter) { this.targetType = Objects.requireNonNull(targetType, "targetType"); this.converter = Objects.requireNonNull(converter, "converter"); } private ImmutableRegistrableConverter( ImmutableRegistrableConverter original, Class targetType, Function converter) { this.targetType = targetType; this.converter = converter; } /** * @return The value of the {@code targetType} attribute */ @Override public Class getTargetType() { return targetType; } /** * @return The value of the {@code converter} attribute */ @Override public Function getConverter() { return converter; } /** * Copy the current immutable object by setting a value for the {@link Parameter.RegistrableConverter#getTargetType() targetType} 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 targetType * @return A modified copy of the {@code this} object */ public final ImmutableRegistrableConverter withTargetType(Class value) { if (this.targetType == value) return this; Class newValue = Objects.requireNonNull(value, "targetType"); return new ImmutableRegistrableConverter<>(this, newValue, this.converter); } /** * Copy the current immutable object by setting a value for the {@link Parameter.RegistrableConverter#getConverter() converter} 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 converter * @return A modified copy of the {@code this} object */ public final ImmutableRegistrableConverter withConverter(Function value) { if (this.converter == value) return this; Function newValue = Objects.requireNonNull(value, "converter"); return new ImmutableRegistrableConverter<>(this, this.targetType, newValue); } /** * This instance is equal to all instances of {@code ImmutableRegistrableConverter} 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 ImmutableRegistrableConverter && equalTo((ImmutableRegistrableConverter) another); } private boolean equalTo(ImmutableRegistrableConverter another) { return targetType.equals(another.targetType) && converter.equals(another.converter); } /** * Computes a hash code from attributes: {@code targetType}, {@code converter}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + targetType.hashCode(); h += (h << 5) + converter.hashCode(); return h; } /** * Prints the immutable value {@code RegistrableConverter} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "RegistrableConverter{" + "targetType=" + targetType + ", converter=" + converter + "}"; } /** * Construct a new immutable {@code RegistrableConverter} instance. * @param generic parameter R * @param targetType The value for the {@code targetType} attribute * @param converter The value for the {@code converter} attribute * @return An immutable RegistrableConverter instance */ public static ImmutableRegistrableConverter of(Class targetType, Function converter) { return new ImmutableRegistrableConverter<>(targetType, converter); } /** * Creates an immutable copy of a {@link Parameter.RegistrableConverter} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param generic parameter R * @param instance The instance to copy * @return A copied immutable RegistrableConverter instance */ public static ImmutableRegistrableConverter copyOf(Parameter.RegistrableConverter instance) { if (instance instanceof ImmutableRegistrableConverter) { return (ImmutableRegistrableConverter) instance; } return ImmutableRegistrableConverter.registrableConverter() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableRegistrableConverter ImmutableRegistrableConverter}. *

   * ImmutableRegistrableConverter.&lt;R&gt;registrableConverter()
   *    .targetType(Class&lt;R&gt;) // required {@link Parameter.RegistrableConverter#getTargetType() targetType}
   *    .converter(function.Function&lt;com.kidsoncoffee.cheesecakes.Parameter.Convertible, R&gt;) // required {@link Parameter.RegistrableConverter#getConverter() converter}
   *    .build();
   * 
* @param generic parameter R * @return A new ImmutableRegistrableConverter builder */ public static ImmutableRegistrableConverter.Builder registrableConverter() { return new ImmutableRegistrableConverter.Builder<>(); } /** * Builds instances of type {@link ImmutableRegistrableConverter ImmutableRegistrableConverter}. * 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 = "Parameter.RegistrableConverter", generator = "Immutables") public static final class Builder { private static final long INIT_BIT_TARGET_TYPE = 0x1L; private static final long INIT_BIT_CONVERTER = 0x2L; private long initBits = 0x3L; private Class targetType; private Function converter; private Builder() { } /** * Fill a builder with attribute values from the provided {@code RegistrableConverter} 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(Parameter.RegistrableConverter instance) { Objects.requireNonNull(instance, "instance"); targetType(instance.getTargetType()); converter(instance.getConverter()); return this; } /** * Initializes the value for the {@link Parameter.RegistrableConverter#getTargetType() targetType} attribute. * @param targetType The value for targetType * @return {@code this} builder for use in a chained invocation */ public final Builder targetType(Class targetType) { this.targetType = Objects.requireNonNull(targetType, "targetType"); initBits &= ~INIT_BIT_TARGET_TYPE; return this; } /** * Initializes the value for the {@link Parameter.RegistrableConverter#getConverter() converter} attribute. * @param converter The value for converter * @return {@code this} builder for use in a chained invocation */ public final Builder converter(Function converter) { this.converter = Objects.requireNonNull(converter, "converter"); initBits &= ~INIT_BIT_CONVERTER; return this; } /** * Builds a new {@link ImmutableRegistrableConverter ImmutableRegistrableConverter}. * @return An immutable instance of RegistrableConverter * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableRegistrableConverter build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableRegistrableConverter<>(null, targetType, converter); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_TARGET_TYPE) != 0) attributes.add("targetType"); if ((initBits & INIT_BIT_CONVERTER) != 0) attributes.add("converter"); return "Cannot build RegistrableConverter, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy