com.hedera.hapi.block.ItemAcknowledgement Maven / Gradle / Ivy
package com.hedera.hapi.block;
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;
/**
* Acknowledgement for a single `BlockItem`.
* Most nodes are expected to implement this acknowledgement only for
* debugging and development purposes.
*
* If a node implements single item acknowledgement, the block node SHALL
* send one `ItemAcknowledgement` for each `BlockItem` received
* and verified.
*
* @param itemHash (1) A SHA2-384 hash of the `BlockItem` received.
*
* This field is REQUIRED.
* A source system MUST verify that this value matches its own internal
* calculated hash value, and MUST end the stream if the values do not
* match.
*/
public record ItemAcknowledgement(
@NonNull Bytes itemHash
) {
/** Protobuf codec for reading and writing in protobuf format */
public static final Codec PROTOBUF = new com.hedera.hapi.block.codec.ItemAcknowledgementProtoCodec();
/** JSON codec for reading and writing in JSON format */
public static final JsonCodec JSON = new com.hedera.hapi.block.codec.ItemAcknowledgementJsonCodec();
/** Default instance with all fields set to default values */
public static final ItemAcknowledgement DEFAULT = newBuilder().build();
/**
* Create a pre-populated ItemAcknowledgement.
*
* @param itemHash (1) A SHA2-384 hash of the `BlockItem` received.
*
* This field is REQUIRED.
* A source system MUST verify that this value matches its own internal
* calculated hash value, and MUST end the stream if the values do not
* match.
*/
public ItemAcknowledgement(Bytes itemHash) {
this.itemHash = itemHash != null ? itemHash : Bytes.EMPTY;
}
/**
* Override the default hashCode method for
* all other objects to make hashCode
*/
@Override
public int hashCode() {
int result = 1;
if (itemHash != null && !itemHash.equals(DEFAULT.itemHash)) {
result = 31 * result + itemHash.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;
}
ItemAcknowledgement thatObj = (ItemAcknowledgement)that;
if (itemHash == null && thatObj.itemHash != null) {
return false;
}
if (itemHash != null && !itemHash.equals(thatObj.itemHash)) {
return false;
}
return true;
}
/**
* 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(itemHash);
}
/**
* 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 {
@NonNull private Bytes itemHash = Bytes.EMPTY;
/**
* Create an empty builder
*/
public Builder() {}
/**
* Create a pre-populated Builder.
*
* @param itemHash (1) A SHA2-384 hash of the `BlockItem` received.
*
* This field is REQUIRED.
* A source system MUST verify that this value matches its own internal
* calculated hash value, and MUST end the stream if the values do not
* match.
*/
public Builder(Bytes itemHash) {
this.itemHash = itemHash != null ? itemHash : Bytes.EMPTY;
}
/**
* Build a new model record with data set on builder
*
* @return new model record with data set
*/
public ItemAcknowledgement build() {
return new ItemAcknowledgement(itemHash);
}
/**
* (1) A SHA2-384 hash of the `BlockItem` received.
*
* This field is REQUIRED.
* A source system MUST verify that this value matches its own internal
* calculated hash value, and MUST end the stream if the values do not
* match.
*
* @param itemHash value to set
* @return builder to continue building with
*/
public Builder itemHash(@NonNull Bytes itemHash) {
this.itemHash = itemHash != null ? itemHash : Bytes.EMPTY;
return this;
}
}
}