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

com.neotys.neoload.model.repository.ImmutableHeader Maven / Gradle / Ivy

package com.neotys.neoload.model.repository;

import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
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 Header}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableHeader.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "Header"}) @Deprecated @Immutable @CheckReturnValue public final class ImmutableHeader implements Header { private final String headerName; private final String headerValue; private ImmutableHeader(String headerName, String headerValue) { this.headerName = headerName; this.headerValue = headerValue; } /** * @return The value of the {@code headerName} attribute */ @Override public String getHeaderName() { return headerName; } /** * @return The value of the {@code headerValue} attribute */ @Override public String getHeaderValue() { return headerValue; } /** * Copy the current immutable object by setting a value for the {@link Header#getHeaderName() headerName} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for headerName * @return A modified copy of the {@code this} object */ public final ImmutableHeader withHeaderName(String value) { if (this.headerName.equals(value)) return this; String newValue = Objects.requireNonNull(value, "headerName"); return new ImmutableHeader(newValue, this.headerValue); } /** * Copy the current immutable object by setting a value for the {@link Header#getHeaderValue() headerValue} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for headerValue * @return A modified copy of the {@code this} object */ public final ImmutableHeader withHeaderValue(String value) { if (this.headerValue.equals(value)) return this; String newValue = Objects.requireNonNull(value, "headerValue"); return new ImmutableHeader(this.headerName, newValue); } /** * This instance is equal to all instances of {@code ImmutableHeader} 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 ImmutableHeader && equalTo((ImmutableHeader) another); } private boolean equalTo(ImmutableHeader another) { return headerName.equals(another.headerName) && headerValue.equals(another.headerValue); } /** * Computes a hash code from attributes: {@code headerName}, {@code headerValue}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + headerName.hashCode(); h += (h << 5) + headerValue.hashCode(); return h; } /** * Prints the immutable value {@code Header} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Header") .omitNullValues() .add("headerName", headerName) .add("headerValue", headerValue) .toString(); } /** * Creates an immutable copy of a {@link Header} 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 Header instance */ public static ImmutableHeader copyOf(Header instance) { if (instance instanceof ImmutableHeader) { return (ImmutableHeader) instance; } return ImmutableHeader.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableHeader ImmutableHeader}. * @return A new ImmutableHeader builder */ public static ImmutableHeader.Builder builder() { return new ImmutableHeader.Builder(); } /** * Builds instances of type {@link ImmutableHeader ImmutableHeader}. * 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_HEADER_NAME = 0x1L; private static final long INIT_BIT_HEADER_VALUE = 0x2L; private long initBits = 0x3L; private @Nullable String headerName; private @Nullable String headerValue; private Builder() { } /** * Fill a builder with attribute values from the provided {@code Header} 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 */ @CanIgnoreReturnValue public final Builder from(Header instance) { Objects.requireNonNull(instance, "instance"); headerName(instance.getHeaderName()); headerValue(instance.getHeaderValue()); return this; } /** * Initializes the value for the {@link Header#getHeaderName() headerName} attribute. * @param headerName The value for headerName * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder headerName(String headerName) { this.headerName = Objects.requireNonNull(headerName, "headerName"); initBits &= ~INIT_BIT_HEADER_NAME; return this; } /** * Initializes the value for the {@link Header#getHeaderValue() headerValue} attribute. * @param headerValue The value for headerValue * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder headerValue(String headerValue) { this.headerValue = Objects.requireNonNull(headerValue, "headerValue"); initBits &= ~INIT_BIT_HEADER_VALUE; return this; } /** * Builds a new {@link ImmutableHeader ImmutableHeader}. * @return An immutable instance of Header * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableHeader build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableHeader(headerName, headerValue); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_HEADER_NAME) != 0) attributes.add("headerName"); if ((initBits & INIT_BIT_HEADER_VALUE) != 0) attributes.add("headerValue"); return "Cannot build Header, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy