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

io.github.shanqiang.sp.Node Maven / Gradle / Ivy

The newest version!
package io.github.shanqiang.sp;

import static java.util.Objects.requireNonNull;

public class Node implements Comparable {
    private final String host;
    private final int port;

    public Node(String host, int port) {
        this.host = requireNonNull(host);
        this.port = port;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    @Override
    public int compareTo(Node that) {
        if (this == that) {
            return 0;
        }

        if (this.host.equals(that.host)) {
            return this.port - that.port;
        }

        return this.host.compareTo(that.host);
    }

    @Override
    public boolean equals(Object another) {
        if (this == another) {
            return true;
        }
        if (another instanceof Node) {
            Node that = (Node) another;
            return host.equals(that.host) && port == that.port;
        }
        return false;
    }

    @Override
    public String toString() {
        return host + ":" + port;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy