Java Host Name Get getHostCore(final String quadGraph)

Here you can find the source of getHostCore(final String quadGraph)

Description

This method should be used over others because it -safely- and accurately trims the host name by 1.

License

Apache License

Declaration

public static String getHostCore(final String quadGraph) throws URISyntaxException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.URISyntaxException;

public class Main {
    /**//  w  w w.j a  v  a  2s.  com
     * This method should be used over others because it -safely- and accurately trims the host name by 1.
     */
    public static String getHostCore(final String quadGraph) throws URISyntaxException {
        //      if (quadGraph == null) {
        //         System.out.println("null");
        //      }

        final String[] graphurisplit = quadGraph.split("\\.");
        StringBuilder host = new StringBuilder();

        try {
            Integer.valueOf(graphurisplit[graphurisplit.length - 1]);
            host.append(quadGraph);
        } catch (NumberFormatException e) {
            for (int i = Math.min(1, Math.max(graphurisplit.length - 2, 0)); i < graphurisplit.length; i++) {
                host.append(graphurisplit[i] + ".");
            }
            host.deleteCharAt(host.length() - 1);
        }
        // String[] graphurisplit = quadGraph.toString().split("\\.");
        // final String host = ((Resource) quadGraph).getHost();

        /*
        if (graphurisplit.length > 1) {
           host = graphurisplit[graphurisplit.length - 2] + "." + graphurisplit[graphurisplit.length - 1];
        } else if (graphurisplit.length == 1) {
           host = graphurisplit[0];
        } else {
           host = "";
        }
        */
        return host.toString();
    }
}

Related

  1. getHost()
  2. getHost()
  3. getHost(String host)
  4. getHost(String link)
  5. getHost(String s)
  6. getHostGateway()
  7. getHostInformation()
  8. getHostMac(String host)
  9. getHostName()