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

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

There is a newer version: 0.54.0
Show newest version
package 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;

/**
 * Contains the IP address and the port representing a service endpoint of
 * a Node in a network. Used to reach the Hedera API and submit transactions
 * to the network.
 * 

* When the `domain_name` field is set, the `ipAddressV4` field * MUST NOT be set.
* When the `ipAddressV4` field is set, the `domain_name` field * MUST NOT be set. * * @param ipAddressV4 (1) The 4-byte IPv4 address of the endpoint encoded in left to right order * (e.g. 127.0.0.1 has bytes [127, 0, 0, 1]) * @param port (2) The port of the service endpoint * @param domainName (3) A node domain name.
* This MUST be the fully qualified domain(DNS) name of the node.
* This value MUST NOT be more than 253 characters. * domain_name and ipAddressV4 are mutually exclusive. * When the `domain_name` field is set, the `ipAddressV4` field MUST NOT be set.
* When the `ipAddressV4` field is set, the `domain_name` field MUST NOT be set. */ public record ServiceEndpoint( @NonNull Bytes ipAddressV4, int port, @NonNull String domainName ) { /** Protobuf codec for reading and writing in protobuf format */ public static final Codec PROTOBUF = new com.hedera.hapi.node.base.codec.ServiceEndpointProtoCodec(); /** JSON codec for reading and writing in JSON format */ public static final JsonCodec JSON = new com.hedera.hapi.node.base.codec.ServiceEndpointJsonCodec(); /** Default instance with all fields set to default values */ public static final ServiceEndpoint DEFAULT = newBuilder().build(); /** * Create a pre-populated ServiceEndpoint. * * @param ipAddressV4 (1) The 4-byte IPv4 address of the endpoint encoded in left to right order * (e.g. 127.0.0.1 has bytes [127, 0, 0, 1]), * @param port (2) The port of the service endpoint, * @param domainName (3) A node domain name.
* This MUST be the fully qualified domain(DNS) name of the node.
* This value MUST NOT be more than 253 characters. * domain_name and ipAddressV4 are mutually exclusive. * When the `domain_name` field is set, the `ipAddressV4` field MUST NOT be set.
* When the `ipAddressV4` field is set, the `domain_name` field MUST NOT be set. */ public ServiceEndpoint(Bytes ipAddressV4, int port, String domainName) { this.ipAddressV4 = ipAddressV4 != null ? ipAddressV4 : Bytes.EMPTY; this.port = port; this.domainName = domainName != null ? domainName : ""; } /** * Override the default hashCode method for * all other objects to make hashCode */ @Override public int hashCode() { int result = 1; if (ipAddressV4 != null && !ipAddressV4.equals(DEFAULT.ipAddressV4)) { result = 31 * result + ipAddressV4.hashCode(); } if (port != DEFAULT.port) { result = 31 * result + Integer.hashCode(port); } if (domainName != null && !domainName.equals(DEFAULT.domainName)) { result = 31 * result + domainName.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; } ServiceEndpoint thatObj = (ServiceEndpoint)that; if (ipAddressV4 == null && thatObj.ipAddressV4 != null) { return false; } if (ipAddressV4 != null && !ipAddressV4.equals(thatObj.ipAddressV4)) { return false; } if (port != thatObj.port) { return false; } if (domainName == null && thatObj.domainName != null) { return false; } if (domainName != null && !domainName.equals(thatObj.domainName)) { 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(ipAddressV4, port, domainName); } /** * 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 ipAddressV4 = Bytes.EMPTY; private int port = 0; @NonNull private String domainName = ""; /** * Create an empty builder */ public Builder() {} /** * Create a pre-populated Builder. * * @param ipAddressV4 (1) The 4-byte IPv4 address of the endpoint encoded in left to right order * (e.g. 127.0.0.1 has bytes [127, 0, 0, 1]), * @param port (2) The port of the service endpoint, * @param domainName (3) A node domain name.
* This MUST be the fully qualified domain(DNS) name of the node.
* This value MUST NOT be more than 253 characters. * domain_name and ipAddressV4 are mutually exclusive. * When the `domain_name` field is set, the `ipAddressV4` field MUST NOT be set.
* When the `ipAddressV4` field is set, the `domain_name` field MUST NOT be set. */ public Builder(Bytes ipAddressV4, int port, String domainName) { this.ipAddressV4 = ipAddressV4 != null ? ipAddressV4 : Bytes.EMPTY; this.port = port; this.domainName = domainName != null ? domainName : ""; } /** * Build a new model record with data set on builder * * @return new model record with data set */ public ServiceEndpoint build() { return new ServiceEndpoint(ipAddressV4, port, domainName); } /** * (1) The 4-byte IPv4 address of the endpoint encoded in left to right order * (e.g. 127.0.0.1 has bytes [127, 0, 0, 1]) * * @param ipAddressV4 value to set * @return builder to continue building with */ public Builder ipAddressV4(@NonNull Bytes ipAddressV4) { this.ipAddressV4 = ipAddressV4 != null ? ipAddressV4 : Bytes.EMPTY; return this; } /** * (2) The port of the service endpoint * * @param port value to set * @return builder to continue building with */ public Builder port(int port) { this.port = port; return this; } /** * (3) A node domain name.
* This MUST be the fully qualified domain(DNS) name of the node.
* This value MUST NOT be more than 253 characters. * domain_name and ipAddressV4 are mutually exclusive. * When the `domain_name` field is set, the `ipAddressV4` field MUST NOT be set.
* When the `ipAddressV4` field is set, the `domain_name` field MUST NOT be set. * * @param domainName value to set * @return builder to continue building with */ public Builder domainName(@NonNull String domainName) { this.domainName = domainName != null ? domainName : ""; return this; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy