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

com.neotys.neoload.model.scenario.ImmutableDuration Maven / Gradle / Ivy

package com.neotys.neoload.model.scenario;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
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.errorprone.annotations.CanIgnoreReturnValue;
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 Duration}.
 * 

* Use the builder to create immutable instances: * {@code new Duration.Builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "Duration"}) @Deprecated @Immutable @CheckReturnValue public final class ImmutableDuration implements Duration { private final Integer value; private final Duration.Type type; private ImmutableDuration(Integer value, Duration.Type type) { this.value = value; this.type = type; } /** * @return The value of the {@code value} attribute */ @JsonProperty("value") @Override public Integer getValue() { return value; } /** * @return The value of the {@code type} attribute */ @JsonProperty("type") @Override public Duration.Type getType() { return type; } /** * Copy the current immutable object by setting a value for the {@link Duration#getValue() value} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for value (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableDuration withValue(Integer value) { if (Objects.equals(this.value, value)) return this; return new ImmutableDuration(value, this.type); } /** * Copy the current immutable object by setting a value for the {@link Duration#getType() type} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for type (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableDuration withType(Duration.Type value) { if (this.type == value) return this; return new ImmutableDuration(this.value, value); } /** * This instance is equal to all instances of {@code ImmutableDuration} 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 ImmutableDuration && equalTo((ImmutableDuration) another); } private boolean equalTo(ImmutableDuration another) { return Objects.equals(value, another.value) && Objects.equals(type, another.type); } /** * Computes a hash code from attributes: {@code value}, {@code type}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + Objects.hashCode(value); h += (h << 5) + Objects.hashCode(type); return h; } /** * Prints the immutable value {@code Duration} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Duration") .omitNullValues() .add("value", value) .add("type", type) .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 @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements Duration { @Nullable Integer value; @Nullable Duration.Type type; @JsonProperty("value") public void setValue(Integer value) { this.value = value; } @JsonProperty("type") public void setType(Duration.Type type) { this.type = type; } @Override public Integer getValue() { throw new UnsupportedOperationException(); } @Override public Duration.Type getType() { 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(mode = JsonCreator.Mode.DELEGATING) static ImmutableDuration fromJson(Json json) { Duration.Builder builder = new Duration.Builder(); if (json.value != null) { builder.value(json.value); } if (json.type != null) { builder.type(json.type); } return (ImmutableDuration) builder.build(); } /** * Creates an immutable copy of a {@link Duration} 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 Duration instance */ public static ImmutableDuration copyOf(Duration instance) { if (instance instanceof ImmutableDuration) { return (ImmutableDuration) instance; } return new Duration.Builder() .from(instance) .build(); } /** * Builds instances of type {@link ImmutableDuration ImmutableDuration}. * 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 class Builder { private @Nullable Integer value; private @Nullable Duration.Type type; /** * Creates a builder for {@link ImmutableDuration ImmutableDuration} instances. */ public Builder() { if (!(this instanceof Duration.Builder)) { throw new UnsupportedOperationException("Use: new Duration.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code Duration} 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 Duration.Builder from(Duration instance) { Objects.requireNonNull(instance, "instance"); Integer valueValue = instance.getValue(); if (valueValue != null) { value(valueValue); } Duration.Type typeValue = instance.getType(); if (typeValue != null) { type(typeValue); } return (Duration.Builder) this; } /** * Initializes the value for the {@link Duration#getValue() value} attribute. * @param value The value for value (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("value") public final Duration.Builder value(Integer value) { this.value = value; return (Duration.Builder) this; } /** * Initializes the value for the {@link Duration#getType() type} attribute. * @param type The value for type (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("type") public final Duration.Builder type(Duration.Type type) { this.type = type; return (Duration.Builder) this; } /** * Builds a new {@link ImmutableDuration ImmutableDuration}. * @return An immutable instance of Duration * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableDuration build() { return new ImmutableDuration(value, type); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy