/*
 * Automatically generated by jrpcgen 1.1.6 on 21.02.24 22:11
 * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
 * See http://remotetea.sourceforge.net for details
 */
package tests.org.acplt.oncrpc.jrpcgen;
import org.acplt.oncrpc.*;
import java.io.IOException;

/** TODO */
public class TREE2 implements XdrAble {
    /** TODO */
    public String key;
    /** TODO */
    public String value;
    /** TODO */
    public TREE2 left;
    /** TODO */
    public TREE2 right;

    public TREE2() {
    }

    public TREE2(XdrDecodingStream xdr)
           throws OncRpcException, IOException {
        xdrDecode(xdr);
    }

    public TREE2(String key, String value, TREE2 left, TREE2 right) {
        this.key = key;
        this.value = value;
        this.left = left;
        this.right = right;
    }

    @Override
    public void xdrEncode(XdrEncodingStream xdr)
           throws OncRpcException, IOException {
        for (TREE2 $current = this; $current != null; $current = $current.right) {
            xdr.xdrEncodeString($current.key);
            xdr.xdrEncodeString($current.value);
            xdr.xdrEncodeBoolean($current.left != null);
            if ($current.left != null) $current.left.xdrEncode(xdr);
            xdr.xdrEncodeBoolean($current.right != null);
        }
    }

    @Override
    public void xdrDecode(XdrDecodingStream xdr)
           throws OncRpcException, IOException {
        for (TREE2 $current = this; $current != null; $current = $current.right) {
            $current.key = xdr.xdrDecodeString();
            $current.value = xdr.xdrDecodeString();
            $current.left = xdr.xdrDecodeBoolean() ? new TREE2(xdr) : null;
            $current.right = xdr.xdrDecodeBoolean() ? new TREE2() : null;
        }
    }

    @Override
    public String toString() {
        return "TREE2 ["
        + "key=" + key + ", "
        + "value=" + value + ", "
        + "left=" + left + ", "
        + "right=" + right
        + "]";
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (getClass() != obj.getClass()) return false;
        TREE2 other = (TREE2)obj;
        if (! java.util.Objects.equals(this.key, other.key)) return false;
        if (! java.util.Objects.equals(this.value, other.value)) return false;
        if (! java.util.Objects.equals(this.left, other.left)) return false;
        if (! java.util.Objects.equals(this.right, other.right)) return false;
        return true;
    }

    @Override
    public int hashCode() {
        return XdrHashCode.hashCode(this);
    }

    public static void xdrEncodeFixedVector(XdrEncodingStream xdr, TREE2[] vector, int size)
           throws OncRpcException, IOException {
        if (vector.length != size) {
            throw new IllegalArgumentException("array size does not match protocol specification");
        }

        for (int index = 0; index < size; index++) {
            vector[index].xdrEncode(xdr);
        }
    }

    public static TREE2[] xdrDecodeFixedVector(XdrDecodingStream xdr, int size)
           throws OncRpcException, IOException {
        TREE2[] vector = new TREE2[size];

        for (int index = 0; index < size; index++) {
            vector[index] = new TREE2(xdr);
        }

        return vector;
    }

    public static void xdrEncodeDynamicVector(XdrEncodingStream xdr, TREE2[] vector)
           throws OncRpcException, IOException {
        xdr.xdrEncodeInt(vector.length);
        xdrEncodeFixedVector(xdr, vector, vector.length);
    }

    public static TREE2[] xdrDecodeDynamicVector(XdrDecodingStream xdr)
           throws OncRpcException, IOException {
        return xdrDecodeFixedVector(xdr, xdr.xdrDecodeInt());
    }

}
// End of TREE2.java
