org.projectnessie.versioned.tiered.gc.ImmutableGcOptions Maven / Gradle / Ivy
package org.projectnessie.versioned.tiered.gc;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Longs;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link GcOptions}.
*
* Use the builder to create immutable instances:
* {@code ImmutableGcOptions.builder()}.
*/
@Generated(from = "GcOptions", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableGcOptions implements GcOptions {
private final long bloomFilterCapacity;
private final long maxAgeMicros;
private final long timeSlopMicros;
private ImmutableGcOptions(long bloomFilterCapacity, long maxAgeMicros, long timeSlopMicros) {
this.bloomFilterCapacity = bloomFilterCapacity;
this.maxAgeMicros = maxAgeMicros;
this.timeSlopMicros = timeSlopMicros;
}
/**
* The expected bloomfilter capacity.
* @return The number of expected items.
*/
@Override
public long getBloomFilterCapacity() {
return bloomFilterCapacity;
}
/**
*The age in micros beyond which a referenced L1 can be collected.
*/
@Override
public long getMaxAgeMicros() {
return maxAgeMicros;
}
/**
* Describes the the minimum amount of time "slop" before the algorithm can consider removing an
* unreferenced value (based on the DT of that value or L1).
* @return Time in Micros before the present moment.
*/
@Override
public long getTimeSlopMicros() {
return timeSlopMicros;
}
/**
* Copy the current immutable object by setting a value for the {@link GcOptions#getBloomFilterCapacity() bloomFilterCapacity} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for bloomFilterCapacity
* @return A modified copy of the {@code this} object
*/
public final ImmutableGcOptions withBloomFilterCapacity(long value) {
if (this.bloomFilterCapacity == value) return this;
return new ImmutableGcOptions(value, this.maxAgeMicros, this.timeSlopMicros);
}
/**
* Copy the current immutable object by setting a value for the {@link GcOptions#getMaxAgeMicros() maxAgeMicros} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for maxAgeMicros
* @return A modified copy of the {@code this} object
*/
public final ImmutableGcOptions withMaxAgeMicros(long value) {
if (this.maxAgeMicros == value) return this;
return new ImmutableGcOptions(this.bloomFilterCapacity, value, this.timeSlopMicros);
}
/**
* Copy the current immutable object by setting a value for the {@link GcOptions#getTimeSlopMicros() timeSlopMicros} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for timeSlopMicros
* @return A modified copy of the {@code this} object
*/
public final ImmutableGcOptions withTimeSlopMicros(long value) {
if (this.timeSlopMicros == value) return this;
return new ImmutableGcOptions(this.bloomFilterCapacity, this.maxAgeMicros, value);
}
/**
* This instance is equal to all instances of {@code ImmutableGcOptions} 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 ImmutableGcOptions
&& equalTo((ImmutableGcOptions) another);
}
private boolean equalTo(ImmutableGcOptions another) {
return bloomFilterCapacity == another.bloomFilterCapacity
&& maxAgeMicros == another.maxAgeMicros
&& timeSlopMicros == another.timeSlopMicros;
}
/**
* Computes a hash code from attributes: {@code bloomFilterCapacity}, {@code maxAgeMicros}, {@code timeSlopMicros}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Longs.hashCode(bloomFilterCapacity);
h += (h << 5) + Longs.hashCode(maxAgeMicros);
h += (h << 5) + Longs.hashCode(timeSlopMicros);
return h;
}
/**
* Prints the immutable value {@code GcOptions} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("GcOptions")
.omitNullValues()
.add("bloomFilterCapacity", bloomFilterCapacity)
.add("maxAgeMicros", maxAgeMicros)
.add("timeSlopMicros", timeSlopMicros)
.toString();
}
/**
* Creates an immutable copy of a {@link GcOptions} 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 GcOptions instance
*/
public static ImmutableGcOptions copyOf(GcOptions instance) {
if (instance instanceof ImmutableGcOptions) {
return (ImmutableGcOptions) instance;
}
return ImmutableGcOptions.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableGcOptions ImmutableGcOptions}.
*
* ImmutableGcOptions.builder()
* .bloomFilterCapacity(long) // required {@link GcOptions#getBloomFilterCapacity() bloomFilterCapacity}
* .maxAgeMicros(long) // required {@link GcOptions#getMaxAgeMicros() maxAgeMicros}
* .timeSlopMicros(long) // required {@link GcOptions#getTimeSlopMicros() timeSlopMicros}
* .build();
*
* @return A new ImmutableGcOptions builder
*/
public static ImmutableGcOptions.Builder builder() {
return new ImmutableGcOptions.Builder();
}
/**
* Builds instances of type {@link ImmutableGcOptions ImmutableGcOptions}.
* 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 = "GcOptions", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_BLOOM_FILTER_CAPACITY = 0x1L;
private static final long INIT_BIT_MAX_AGE_MICROS = 0x2L;
private static final long INIT_BIT_TIME_SLOP_MICROS = 0x4L;
private long initBits = 0x7L;
private long bloomFilterCapacity;
private long maxAgeMicros;
private long timeSlopMicros;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code GcOptions} 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(GcOptions instance) {
Objects.requireNonNull(instance, "instance");
bloomFilterCapacity(instance.getBloomFilterCapacity());
maxAgeMicros(instance.getMaxAgeMicros());
timeSlopMicros(instance.getTimeSlopMicros());
return this;
}
/**
* Initializes the value for the {@link GcOptions#getBloomFilterCapacity() bloomFilterCapacity} attribute.
* @param bloomFilterCapacity The value for bloomFilterCapacity
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder bloomFilterCapacity(long bloomFilterCapacity) {
this.bloomFilterCapacity = bloomFilterCapacity;
initBits &= ~INIT_BIT_BLOOM_FILTER_CAPACITY;
return this;
}
/**
* Initializes the value for the {@link GcOptions#getMaxAgeMicros() maxAgeMicros} attribute.
* @param maxAgeMicros The value for maxAgeMicros
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder maxAgeMicros(long maxAgeMicros) {
this.maxAgeMicros = maxAgeMicros;
initBits &= ~INIT_BIT_MAX_AGE_MICROS;
return this;
}
/**
* Initializes the value for the {@link GcOptions#getTimeSlopMicros() timeSlopMicros} attribute.
* @param timeSlopMicros The value for timeSlopMicros
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder timeSlopMicros(long timeSlopMicros) {
this.timeSlopMicros = timeSlopMicros;
initBits &= ~INIT_BIT_TIME_SLOP_MICROS;
return this;
}
/**
* Builds a new {@link ImmutableGcOptions ImmutableGcOptions}.
* @return An immutable instance of GcOptions
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableGcOptions build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableGcOptions(bloomFilterCapacity, maxAgeMicros, timeSlopMicros);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_BLOOM_FILTER_CAPACITY) != 0) attributes.add("bloomFilterCapacity");
if ((initBits & INIT_BIT_MAX_AGE_MICROS) != 0) attributes.add("maxAgeMicros");
if ((initBits & INIT_BIT_TIME_SLOP_MICROS) != 0) attributes.add("timeSlopMicros");
return "Cannot build GcOptions, some of required attributes are not set " + attributes;
}
}
}