edu.isi.nlp.evaluation.ImmutableFMeasureCounts Maven / Gradle / Ivy
package edu.isi.nlp.evaluation;
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.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.primitives.Doubles;
import java.util.List;
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 FMeasureCounts}.
*
* Use the builder to create immutable instances:
* {@code new FMeasureCounts.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "FMeasureCounts"})
@Immutable
final class ImmutableFMeasureCounts extends FMeasureCounts {
private final double falsePositives;
private final double falseNegatives;
private final double numPredicted;
private final double numItemsInKey;
private ImmutableFMeasureCounts(double falsePositives, double falseNegatives, double numPredicted, double numItemsInKey) {
this.falsePositives = falsePositives;
this.falseNegatives = falseNegatives;
this.numPredicted = numPredicted;
this.numItemsInKey = numItemsInKey;
}
/**
* @return The value of the {@code falsePositives} attribute
*/
@JsonProperty("falsePositives")
@Override
public double falsePositives() {
return falsePositives;
}
/**
* @return The value of the {@code falseNegatives} attribute
*/
@JsonProperty("falseNegatives")
@Override
public double falseNegatives() {
return falseNegatives;
}
/**
* @return The value of the {@code numPredicted} attribute
*/
@JsonProperty("numPredicted")
@Override
public double numPredicted() {
return numPredicted;
}
/**
* @return The value of the {@code numItemsInKey} attribute
*/
@JsonProperty("numItemsInKey")
@Override
public double numItemsInKey() {
return numItemsInKey;
}
/**
* Copy the current immutable object by setting a value for the {@link FMeasureCounts#falsePositives() falsePositives} attribute.
* A value strict bits equality used to prevent copying of the same value by returning {@code this}.
* @param value A new value for falsePositives
* @return A modified copy of the {@code this} object
*/
public final ImmutableFMeasureCounts withFalsePositives(double value) {
if (Double.doubleToLongBits(this.falsePositives) == Double.doubleToLongBits(value)) return this;
return validate(new ImmutableFMeasureCounts(value, this.falseNegatives, this.numPredicted, this.numItemsInKey));
}
/**
* Copy the current immutable object by setting a value for the {@link FMeasureCounts#falseNegatives() falseNegatives} attribute.
* A value strict bits equality used to prevent copying of the same value by returning {@code this}.
* @param value A new value for falseNegatives
* @return A modified copy of the {@code this} object
*/
public final ImmutableFMeasureCounts withFalseNegatives(double value) {
if (Double.doubleToLongBits(this.falseNegatives) == Double.doubleToLongBits(value)) return this;
return validate(new ImmutableFMeasureCounts(this.falsePositives, value, this.numPredicted, this.numItemsInKey));
}
/**
* Copy the current immutable object by setting a value for the {@link FMeasureCounts#numPredicted() numPredicted} attribute.
* A value strict bits equality used to prevent copying of the same value by returning {@code this}.
* @param value A new value for numPredicted
* @return A modified copy of the {@code this} object
*/
public final ImmutableFMeasureCounts withNumPredicted(double value) {
if (Double.doubleToLongBits(this.numPredicted) == Double.doubleToLongBits(value)) return this;
return validate(new ImmutableFMeasureCounts(this.falsePositives, this.falseNegatives, value, this.numItemsInKey));
}
/**
* Copy the current immutable object by setting a value for the {@link FMeasureCounts#numItemsInKey() numItemsInKey} attribute.
* A value strict bits equality used to prevent copying of the same value by returning {@code this}.
* @param value A new value for numItemsInKey
* @return A modified copy of the {@code this} object
*/
public final ImmutableFMeasureCounts withNumItemsInKey(double value) {
if (Double.doubleToLongBits(this.numItemsInKey) == Double.doubleToLongBits(value)) return this;
return validate(new ImmutableFMeasureCounts(this.falsePositives, this.falseNegatives, this.numPredicted, value));
}
/**
* This instance is equal to all instances of {@code ImmutableFMeasureCounts} 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 ImmutableFMeasureCounts
&& equalTo((ImmutableFMeasureCounts) another);
}
private boolean equalTo(ImmutableFMeasureCounts another) {
return Double.doubleToLongBits(falsePositives) == Double.doubleToLongBits(another.falsePositives)
&& Double.doubleToLongBits(falseNegatives) == Double.doubleToLongBits(another.falseNegatives)
&& Double.doubleToLongBits(numPredicted) == Double.doubleToLongBits(another.numPredicted)
&& Double.doubleToLongBits(numItemsInKey) == Double.doubleToLongBits(another.numItemsInKey);
}
/**
* Computes a hash code from attributes: {@code falsePositives}, {@code falseNegatives}, {@code numPredicted}, {@code numItemsInKey}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + Doubles.hashCode(falsePositives);
h = h * 17 + Doubles.hashCode(falseNegatives);
h = h * 17 + Doubles.hashCode(numPredicted);
h = h * 17 + Doubles.hashCode(numItemsInKey);
return h;
}
/**
* 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 extends FMeasureCounts {
double falsePositives;
boolean falsePositivesIsSet;
double falseNegatives;
boolean falseNegativesIsSet;
double numPredicted;
boolean numPredictedIsSet;
double numItemsInKey;
boolean numItemsInKeyIsSet;
@JsonProperty("falsePositives")
public void setFalsePositives(double falsePositives) {
this.falsePositives = falsePositives;
this.falsePositivesIsSet = true;
}
@JsonProperty("falseNegatives")
public void setFalseNegatives(double falseNegatives) {
this.falseNegatives = falseNegatives;
this.falseNegativesIsSet = true;
}
@JsonProperty("numPredicted")
public void setNumPredicted(double numPredicted) {
this.numPredicted = numPredicted;
this.numPredictedIsSet = true;
}
@JsonProperty("numItemsInKey")
public void setNumItemsInKey(double numItemsInKey) {
this.numItemsInKey = numItemsInKey;
this.numItemsInKeyIsSet = true;
}
@Override
public double falsePositives() { throw new UnsupportedOperationException(); }
@Override
public double falseNegatives() { throw new UnsupportedOperationException(); }
@Override
public double numPredicted() { throw new UnsupportedOperationException(); }
@Override
public double numItemsInKey() { 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
static ImmutableFMeasureCounts fromJson(Json json) {
FMeasureCounts.Builder builder = new FMeasureCounts.Builder();
if (json.falsePositivesIsSet) {
builder.falsePositives(json.falsePositives);
}
if (json.falseNegativesIsSet) {
builder.falseNegatives(json.falseNegatives);
}
if (json.numPredictedIsSet) {
builder.numPredicted(json.numPredicted);
}
if (json.numItemsInKeyIsSet) {
builder.numItemsInKey(json.numItemsInKey);
}
return (ImmutableFMeasureCounts) builder.build();
}
private static ImmutableFMeasureCounts validate(ImmutableFMeasureCounts instance) {
instance.check();
return instance;
}
/**
* Creates an immutable copy of a {@link FMeasureCounts} 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 FMeasureCounts instance
*/
public static FMeasureCounts copyOf(FMeasureCounts instance) {
if (instance instanceof ImmutableFMeasureCounts) {
return (ImmutableFMeasureCounts) instance;
}
return new FMeasureCounts.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link FMeasureCounts FMeasureCounts}.
* 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
static class Builder {
private static final long INIT_BIT_FALSE_POSITIVES = 0x1L;
private static final long INIT_BIT_FALSE_NEGATIVES = 0x2L;
private static final long INIT_BIT_NUM_PREDICTED = 0x4L;
private static final long INIT_BIT_NUM_ITEMS_IN_KEY = 0x8L;
private long initBits = 0xfL;
private double falsePositives;
private double falseNegatives;
private double numPredicted;
private double numItemsInKey;
/**
* Creates a builder for {@link FMeasureCounts FMeasureCounts} instances.
*/
Builder() {
if (!(this instanceof FMeasureCounts.Builder)) {
throw new UnsupportedOperationException("Use: new FMeasureCounts.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code FMeasureCounts} 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 FMeasureCounts.Builder from(FMeasureCounts instance) {
Preconditions.checkNotNull(instance, "instance");
falsePositives(instance.falsePositives());
falseNegatives(instance.falseNegatives());
numPredicted(instance.numPredicted());
numItemsInKey(instance.numItemsInKey());
return (FMeasureCounts.Builder) this;
}
/**
* Initializes the value for the {@link FMeasureCounts#falsePositives() falsePositives} attribute.
* @param falsePositives The value for falsePositives
* @return {@code this} builder for use in a chained invocation
*/
public final FMeasureCounts.Builder falsePositives(double falsePositives) {
this.falsePositives = falsePositives;
initBits &= ~INIT_BIT_FALSE_POSITIVES;
return (FMeasureCounts.Builder) this;
}
/**
* Initializes the value for the {@link FMeasureCounts#falseNegatives() falseNegatives} attribute.
* @param falseNegatives The value for falseNegatives
* @return {@code this} builder for use in a chained invocation
*/
public final FMeasureCounts.Builder falseNegatives(double falseNegatives) {
this.falseNegatives = falseNegatives;
initBits &= ~INIT_BIT_FALSE_NEGATIVES;
return (FMeasureCounts.Builder) this;
}
/**
* Initializes the value for the {@link FMeasureCounts#numPredicted() numPredicted} attribute.
* @param numPredicted The value for numPredicted
* @return {@code this} builder for use in a chained invocation
*/
public final FMeasureCounts.Builder numPredicted(double numPredicted) {
this.numPredicted = numPredicted;
initBits &= ~INIT_BIT_NUM_PREDICTED;
return (FMeasureCounts.Builder) this;
}
/**
* Initializes the value for the {@link FMeasureCounts#numItemsInKey() numItemsInKey} attribute.
* @param numItemsInKey The value for numItemsInKey
* @return {@code this} builder for use in a chained invocation
*/
public final FMeasureCounts.Builder numItemsInKey(double numItemsInKey) {
this.numItemsInKey = numItemsInKey;
initBits &= ~INIT_BIT_NUM_ITEMS_IN_KEY;
return (FMeasureCounts.Builder) this;
}
/**
* Builds a new {@link FMeasureCounts FMeasureCounts}.
* @return An immutable instance of FMeasureCounts
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public FMeasureCounts build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return ImmutableFMeasureCounts.validate(new ImmutableFMeasureCounts(falsePositives, falseNegatives, numPredicted, numItemsInKey));
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_FALSE_POSITIVES) != 0) attributes.add("falsePositives");
if ((initBits & INIT_BIT_FALSE_NEGATIVES) != 0) attributes.add("falseNegatives");
if ((initBits & INIT_BIT_NUM_PREDICTED) != 0) attributes.add("numPredicted");
if ((initBits & INIT_BIT_NUM_ITEMS_IN_KEY) != 0) attributes.add("numItemsInKey");
return "Cannot build FMeasureCounts, some of required attributes are not set " + attributes;
}
}
}