com.hedera.hapi.node.base.NodeAddressBook Maven / Gradle / Ivy
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 java.util.*;
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;
/**
* A list of nodes and their metadata that contains all details of the nodes for the network. Used
* to parse the contents of system files 0.0.101
and 0.0.102
.
*
* @param nodeAddress (1) Metadata of all nodes in the network
*/
public record NodeAddressBook(
@NonNull List nodeAddress
) {
/** Protobuf codec for reading and writing in protobuf format */
public static final Codec PROTOBUF = new com.hedera.hapi.node.base.codec.NodeAddressBookProtoCodec();
/** JSON codec for reading and writing in JSON format */
public static final JsonCodec JSON = new com.hedera.hapi.node.base.codec.NodeAddressBookJsonCodec();
/** Default instance with all fields set to default values */
public static final NodeAddressBook DEFAULT = newBuilder().build();
/**
* Create a pre-populated NodeAddressBook.
*
* @param nodeAddress (1) Metadata of all nodes in the network
*/
public NodeAddressBook(List nodeAddress) {
this.nodeAddress = nodeAddress == null ? Collections.emptyList() : nodeAddress;
}
/**
* Override the default hashCode method for
* all other objects to make hashCode
*/
@Override
public int hashCode() {
int result = 1;
java.util.List list$nodeAddress = nodeAddress;
if (list$nodeAddress != null) {
for (Object o : list$nodeAddress) {
if (o != null) {
result = 31 * result + o.hashCode();
} else {
result = 31 * result;
}
}
}
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;
}
NodeAddressBook thatObj = (NodeAddressBook)that;
if (this.nodeAddress == null && thatObj.nodeAddress != null) {
return false;
}
if (this.nodeAddress != null && !nodeAddress.equals(thatObj.nodeAddress)) {
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(nodeAddress);
}
/**
* 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 List nodeAddress = Collections.emptyList();
/**
* Create an empty builder
*/
public Builder() {}
/**
* Create a pre-populated Builder.
*
* @param nodeAddress (1) Metadata of all nodes in the network
*/
public Builder(List nodeAddress) {
this.nodeAddress = nodeAddress == null ? Collections.emptyList() : nodeAddress;
}
/**
* Build a new model record with data set on builder
*
* @return new model record with data set
*/
public NodeAddressBook build() {
return new NodeAddressBook(nodeAddress);
}
/**
* (1) Metadata of all nodes in the network
*
* @param nodeAddress value to set
* @return builder to continue building with
*/
public Builder nodeAddress(@NonNull List nodeAddress) {
this.nodeAddress = nodeAddress != null ? nodeAddress : Collections.emptyList();
return this;
}
/**
* (1) Metadata of all nodes in the network
*
* @param values varargs value to be built into a list
* @return builder to continue building with
*/
public Builder nodeAddress(NodeAddress ... values) {
this.nodeAddress = values == null ? Collections.emptyList() : List.of(values) ;
return this;
}
}
}