class HostnamePort {

    public boolean matches( URI toMatch )
    {
        boolean result = false;
        for ( int port = ports[0]; port <= ports[1]; port++ )
        {
            if ( port == toMatch.getPort() )
            {
                result = true;
                break;
            }
        }

        if ( host == null && toMatch.getHost() == null )
        {
            return result;
        }
        else if ( host == null )
        {
            return false;
        }

        // URI may contain IP, so make sure we check it too by converting ours, if necessary
        String toMatchHost = toMatch.getHost();

        // this tries to match hostnames as they are at first, then tries to extract and match ip addresses of both
        return result && (host.equalsIgnoreCase( toMatchHost ) ||
                getHost( null ).equalsIgnoreCase( getHostAddress( toMatchHost, toMatchHost ) ));
    }

    public  HostnamePort( String hostnamePort );
    public  HostnamePort( String host, int port );
    public  HostnamePort( String host, int portFrom, int portTo );

}