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

com.hedera.hapi.node.base.ThresholdSignature Maven / Gradle / Ivy

There is a newer version: 0.54.0
Show newest version
package com.hedera.hapi.node.base;

import com.hedera.hapi.node.base.*;
import com.hedera.pbj.runtime.*;
import com.hedera.pbj.runtime.io.*;
import com.hedera.pbj.runtime.io.buffer.*;
import com.hedera.pbj.runtime.io.stream.*;
import edu.umd.cs.findbugs.annotations.*;

import com.hedera.pbj.runtime.Codec;
import java.util.function.Consumer;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.NonNull;
import static java.util.Objects.requireNonNull;

/**
 * This message is DEPRECATED and UNUSABLE with network nodes. It is retained
 * here only for historical reasons.
 * 

* Please use the SignaturePair and SignatureMap messages. * * @param sigs (2) for an N-of-M threshold key, this is a list of M signatures, at least N of which must be * non-null */@Deprecated public record ThresholdSignature( @Nullable SignatureList sigs ) { /** Protobuf codec for reading and writing in protobuf format */ public static final Codec PROTOBUF = new com.hedera.hapi.node.base.codec.ThresholdSignatureProtoCodec(); /** JSON codec for reading and writing in JSON format */ public static final JsonCodec JSON = new com.hedera.hapi.node.base.codec.ThresholdSignatureJsonCodec(); /** Default instance with all fields set to default values */ public static final ThresholdSignature DEFAULT = newBuilder().build(); /** * Create a pre-populated ThresholdSignature. * * @param sigs (2) for an N-of-M threshold key, this is a list of M signatures, at least N of which must be * non-null */ public ThresholdSignature(SignatureList sigs) { this.sigs = sigs; } /** * Override the default hashCode method for * all other objects to make hashCode */ @Override public int hashCode() { int result = 1; if (sigs != null && !sigs.equals(DEFAULT.sigs)) { result = 31 * result + sigs.hashCode(); } long hashCode = result; // Shifts: 30, 27, 16, 20, 5, 18, 10, 24, 30 hashCode += hashCode << 30; hashCode ^= hashCode >>> 27; hashCode += hashCode << 16; hashCode ^= hashCode >>> 20; hashCode += hashCode << 5; hashCode ^= hashCode >>> 18; hashCode += hashCode << 10; hashCode ^= hashCode >>> 24; hashCode += hashCode << 30; return (int)hashCode; } /** * Override the default equals method for */ @Override public boolean equals(Object that) { if (that == null || this.getClass() != that.getClass()) { return false; } ThresholdSignature thatObj = (ThresholdSignature)that; if (sigs == null && thatObj.sigs != null) { return false; } if (sigs != null && !sigs.equals(thatObj.sigs)) { return false; } return true; } /** * Convenience method to check if the sigs has a value * * @return true of the sigs has a value */ public boolean hasSigs() { return sigs != null; } /** * Gets the value for sigs if it has a value, or else returns the default * value for the type. * * @param defaultValue the default value to return if sigs is null * @return the value for sigs if it has a value, or else returns the default value */ public SignatureList sigsOrElse(@NonNull final SignatureList defaultValue) { return hasSigs() ? sigs : defaultValue; } /** * Gets the value for sigs if it has a value, or else throws an NPE. * value for the type. * * @return the value for sigs if it has a value * @throws NullPointerException if sigs is null */ public @NonNull SignatureList sigsOrThrow() { return requireNonNull(sigs, "Field sigs is null"); } /** * Executes the supplied {@link Consumer} if, and only if, the sigs has a value * * @param ifPresent the {@link Consumer} to execute */ public void ifSigs(@NonNull final Consumer ifPresent) { if (hasSigs()) { ifPresent.accept(sigs); } } /** * Return a builder for building a copy of this model object. It will be pre-populated with all the data from this * model object. * * @return a pre-populated builder */ public Builder copyBuilder() { return new Builder(sigs); } /** * Return a new builder for building a model object. This is just a shortcut for new Model.Builder(). * * @return a new builder */ public static Builder newBuilder() { return new Builder(); } /** * Builder class for easy creation, ideal for clean code where performance is not critical. In critical performance * paths use the constructor directly. */ public static final class Builder { @Nullable private SignatureList sigs = null; /** * Create an empty builder */ public Builder() {} /** * Create a pre-populated Builder. * * @param sigs (2) for an N-of-M threshold key, this is a list of M signatures, at least N of which must be * non-null */ public Builder(SignatureList sigs) { this.sigs = sigs; } /** * Build a new model record with data set on builder * * @return new model record with data set */ public ThresholdSignature build() { return new ThresholdSignature(sigs); } /** * (2) for an N-of-M threshold key, this is a list of M signatures, at least N of which must be * non-null * * @param sigs value to set * @return builder to continue building with */ public Builder sigs(@Nullable SignatureList sigs) { this.sigs = sigs; return this; } /** * (2) for an N-of-M threshold key, this is a list of M signatures, at least N of which must be * non-null * * @param builder A pre-populated builder * @return builder to continue building with */ public Builder sigs(SignatureList.Builder builder) { this.sigs = builder.build() ; return this; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy