com.hedera.hapi.node.token.AllProxyStakers Maven / Gradle / Ivy
package com.hedera.hapi.node.token;
import com.hedera.hapi.node.base.*;
import com.hedera.hapi.node.token.*;
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;
/**
* all of the accounts proxy staking to a given account, and the amounts proxy staked
*
* @param accountID (1) The Account ID that is being proxy staked to
* @param proxyStaker (2) Each of the proxy staking accounts, and the amount they are proxy staking
*/
public record AllProxyStakers(
@Nullable AccountID accountID,
@NonNull List proxyStaker
) {
/** Protobuf codec for reading and writing in protobuf format */
public static final Codec PROTOBUF = new com.hedera.hapi.node.token.codec.AllProxyStakersProtoCodec();
/** JSON codec for reading and writing in JSON format */
public static final JsonCodec JSON = new com.hedera.hapi.node.token.codec.AllProxyStakersJsonCodec();
/** Default instance with all fields set to default values */
public static final AllProxyStakers DEFAULT = newBuilder().build();
/**
* Create a pre-populated AllProxyStakers.
*
* @param accountID (1) The Account ID that is being proxy staked to,
* @param proxyStaker (2) Each of the proxy staking accounts, and the amount they are proxy staking
*/
public AllProxyStakers(AccountID accountID, List proxyStaker) {
this.accountID = accountID;
this.proxyStaker = proxyStaker == null ? Collections.emptyList() : proxyStaker;
}
/**
* Override the default hashCode method for
* all other objects to make hashCode
*/
@Override
public int hashCode() {
int result = 1;
if (accountID != null && !accountID.equals(DEFAULT.accountID)) {
result = 31 * result + accountID.hashCode();
}
java.util.List list$proxyStaker = proxyStaker;
if (list$proxyStaker != null) {
for (Object o : list$proxyStaker) {
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;
}
AllProxyStakers thatObj = (AllProxyStakers)that;
if (accountID == null && thatObj.accountID != null) {
return false;
}
if (accountID != null && !accountID.equals(thatObj.accountID)) {
return false;
}
if (this.proxyStaker == null && thatObj.proxyStaker != null) {
return false;
}
if (this.proxyStaker != null && !proxyStaker.equals(thatObj.proxyStaker)) {
return false;
}
return true;
}
/**
* Convenience method to check if the accountID has a value
*
* @return true of the accountID has a value
*/
public boolean hasAccountID() {
return accountID != null;
}
/**
* Gets the value for accountID if it has a value, or else returns the default
* value for the type.
*
* @param defaultValue the default value to return if accountID is null
* @return the value for accountID if it has a value, or else returns the default value
*/
public AccountID accountIDOrElse(@NonNull final AccountID defaultValue) {
return hasAccountID() ? accountID : defaultValue;
}
/**
* Gets the value for accountID if it has a value, or else throws an NPE.
* value for the type.
*
* @return the value for accountID if it has a value
* @throws NullPointerException if accountID is null
*/
public @NonNull AccountID accountIDOrThrow() {
return requireNonNull(accountID, "Field accountID is null");
}
/**
* Executes the supplied {@link Consumer} if, and only if, the accountID has a value
*
* @param ifPresent the {@link Consumer} to execute
*/
public void ifAccountID(@NonNull final Consumer ifPresent) {
if (hasAccountID()) {
ifPresent.accept(accountID);
}
}
/**
* 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(accountID, proxyStaker);
}
/**
* 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 AccountID accountID = null;
@NonNull private List proxyStaker = Collections.emptyList();
/**
* Create an empty builder
*/
public Builder() {}
/**
* Create a pre-populated Builder.
*
* @param accountID (1) The Account ID that is being proxy staked to,
* @param proxyStaker (2) Each of the proxy staking accounts, and the amount they are proxy staking
*/
public Builder(AccountID accountID, List proxyStaker) {
this.accountID = accountID;
this.proxyStaker = proxyStaker == null ? Collections.emptyList() : proxyStaker;
}
/**
* Build a new model record with data set on builder
*
* @return new model record with data set
*/
public AllProxyStakers build() {
return new AllProxyStakers(accountID, proxyStaker);
}
/**
* (1) The Account ID that is being proxy staked to
*
* @param accountID value to set
* @return builder to continue building with
*/
public Builder accountID(@Nullable AccountID accountID) {
this.accountID = accountID;
return this;
}
/**
* (1) The Account ID that is being proxy staked to
*
* @param builder A pre-populated builder
* @return builder to continue building with
*/
public Builder accountID(AccountID.Builder builder) {
this.accountID = builder.build() ;
return this;
}
/**
* (2) Each of the proxy staking accounts, and the amount they are proxy staking
*
* @param proxyStaker value to set
* @return builder to continue building with
*/
public Builder proxyStaker(@NonNull List proxyStaker) {
this.proxyStaker = proxyStaker != null ? proxyStaker : Collections.emptyList();
return this;
}
/**
* (2) Each of the proxy staking accounts, and the amount they are proxy staking
*
* @param values varargs value to be built into a list
* @return builder to continue building with
*/
public Builder proxyStaker(ProxyStaker ... values) {
this.proxyStaker = values == null ? Collections.emptyList() : List.of(values) ;
return this;
}
}
}