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

io.deephaven.tuple.generated.DoubleObjectTuple Maven / Gradle / Ivy

There is a newer version: 0.36.1
Show newest version
package io.deephaven.tuple.generated;

import gnu.trove.map.TIntObjectMap;
import io.deephaven.tuple.CanonicalizableTuple;
import io.deephaven.tuple.serialization.SerializationUtils;
import io.deephaven.tuple.serialization.StreamingExternalizable;
import io.deephaven.util.compare.DoubleComparisons;
import io.deephaven.util.compare.ObjectComparisons;
import org.jetbrains.annotations.NotNull;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Objects;
import java.util.function.UnaryOperator;

/**
 * 

2-Tuple (double) key class composed of double and Object elements. *

Generated by io.deephaven.replicators.TupleCodeGenerator. */ public class DoubleObjectTuple implements Comparable, Externalizable, StreamingExternalizable, CanonicalizableTuple { private static final long serialVersionUID = 1L; private double element1; private Object element2; private transient int cachedHashCode; public DoubleObjectTuple( final double element1, final Object element2 ) { initialize( element1, element2 ); } /** Public no-arg constructor for {@link Externalizable} support only. Application code should not use this! **/ public DoubleObjectTuple() { } private void initialize( final double element1, final Object element2 ) { this.element1 = element1; this.element2 = element2; cachedHashCode = (31 + Double.hashCode(element1)) * 31 + Objects.hashCode(element2); } public final double getFirstElement() { return element1; } public final Object getSecondElement() { return element2; } @Override public final int hashCode() { return cachedHashCode; } @Override public final boolean equals(final Object other) { if (this == other) { return true; } if (other == null || getClass() != other.getClass()) { return false; } final DoubleObjectTuple typedOther = (DoubleObjectTuple) other; // @formatter:off return element1 == typedOther.element1 && ObjectComparisons.eq(element2, typedOther.element2); // @formatter:on } @Override public final int compareTo(@NotNull final DoubleObjectTuple other) { if (this == other) { return 0; } int comparison; // @formatter:off return 0 != (comparison = DoubleComparisons.compare(element1, other.element1)) ? comparison : ObjectComparisons.compare(element2, other.element2); // @formatter:on } @Override public void writeExternal(@NotNull final ObjectOutput out) throws IOException { out.writeDouble(element1); out.writeObject(element2); } @Override public void readExternal(@NotNull final ObjectInput in) throws IOException, ClassNotFoundException { initialize( in.readDouble(), in.readObject() ); } @Override public void writeExternalStreaming(@NotNull final ObjectOutput out, @NotNull final TIntObjectMap cachedWriters) throws IOException { out.writeDouble(element1); StreamingExternalizable.writeObjectElement(out, cachedWriters, 1, element2); } @Override public void readExternalStreaming(@NotNull final ObjectInput in, @NotNull final TIntObjectMap cachedReaders) throws Exception { initialize( in.readDouble(), StreamingExternalizable.readObjectElement(in, cachedReaders, 1) ); } @Override public String toString() { return "DoubleObjectTuple{" + element1 + ", " + element2 + '}'; } @Override public DoubleObjectTuple canonicalize(@NotNull final UnaryOperator canonicalizer) { final Object canonicalizedElement2 = canonicalizer.apply(element2); return canonicalizedElement2 == element2 ? this : new DoubleObjectTuple(element1, canonicalizedElement2); } }