Java Socket Address Get compareAddresses(InetSocketAddress addr1, InetSocketAddress addr2)

Here you can find the source of compareAddresses(InetSocketAddress addr1, InetSocketAddress addr2)

Description

compare Addresses

License

Open Source License

Declaration

public static int compareAddresses(InetSocketAddress addr1, InetSocketAddress addr2) 

Method Source Code


//package com.java2s;
import java.net.InetSocketAddress;

public class Main {
    public static int compareAddresses(InetSocketAddress addr1, InetSocketAddress addr2) {
        byte[] addr1Array = addr1.getAddress().getAddress();
        byte[] addr2Array = addr2.getAddress().getAddress();
        for (int i = 0; i < addr1Array.length && i < addr2Array.length; i++)
            if (addr1Array[i] < addr2Array[i])
                return -1;

        int port1 = addr1.getPort();
        int port2 = addr2.getPort();
        if (port1 < port2)
            return -1;
        else if (port1 > port2)
            return 1;
        else/*w ww. j  a v  a2  s.  c  om*/
            return 0;
    }
}

Related

  1. addressMapToString( Map> map)
  2. addressToString(InetSocketAddress a)
  3. addressToString(InetSocketAddress address, Boolean useIpAddress)
  4. asString(SocketAddress socketAddress)
  5. cast2SocketAddress(String addr)
  6. convertToHostString(SocketAddress hostAddress)
  7. create(SocketAddress address, SocketAddress port)
  8. createBoundServerSocket(final SocketAddress socketAddress)
  9. createClientSocket(InetSocketAddress site)