Example usage for java.lang Integer decode

List of usage examples for java.lang Integer decode

Introduction

In this page you can find the example usage for java.lang Integer decode.

Prototype

public static Integer decode(String nm) throws NumberFormatException 

Source Link

Document

Decodes a String into an Integer .

Usage

From source file:Main.java

public static void main(String[] args) {

    System.out.println(Integer.decode("010"));// octal numbers
    System.out.println(Integer.decode("0XA"));// hexadecimal numbers
    System.out.println(Integer.decode("-0XA"));// minus hexadecimal numbers
    System.out.println(Integer.decode("-#A"));// minus hexadecimal numbers
}

From source file:Main.java

public static void main(String[] args) {
    String decimal = "10"; // Decimal
    String hexa = "0XFF"; // Hexa
    String octal = "077"; // Octal

    Integer number = Integer.decode(decimal);
    System.out.println("String [" + decimal + "] = " + number);

    number = Integer.decode(hexa);
    System.out.println("String [" + hexa + "] = " + number);

    number = Integer.decode(octal);
    System.out.println("String [" + octal + "] = " + number);
}

From source file:org.kchine.r.server.CoreMain.java

public static void main(String[] args) throws Exception {
    PoolUtils.initLog4J();//from w  w  w .  ja  va2 s  .  c  o  m

    if (System.getProperty("rmi.port.start") != null && !System.getProperty("rmi.port.start").equals("")) {

        int width = 300;
        if (System.getProperty("submit.ssh.rmi.port.width") != null
                && !System.getProperty("submit.ssh.rmi.port.width").equals("")) {
            width = Integer.decode(System.getProperty("submit.ssh.rmi.port.width"));
        }

        int rmi_port_start = Integer.decode(System.getProperty("rmi.port.start"));
        Integer valid_port = null;
        for (int i = 0; i < (width / RServantImpl.PORT_RANGE_WIDTH); ++i) {
            try {
                ServerSocket s = new ServerSocket(rmi_port_start + i * RServantImpl.PORT_RANGE_WIDTH);
                s.close();
                valid_port = rmi_port_start + i * RServantImpl.PORT_RANGE_WIDTH;
                break;
            } catch (Exception e) {
            }
        }
        if (valid_port == null) {
            log.info("all available ports are taken, can't create server");
            System.exit(0);
        }

        System.setProperty("rmi.port.start", "" + valid_port);
        log.info("rmi.port.start:" + System.getProperty("rmi.port.start"));
    }

    Vector<URL> codeUrls = new Vector<URL>();
    if (args.length > 0) {
        for (int i = 0; i < args.length; ++i) {
            codeUrls.add(new URL(args[i]));
        }
    } else {
        /*
        String jar = CoreMain.class.getResource("/org/kchine/r/server/CoreMain.class").toString();
        if (jar.startsWith("jar:")) {
           String jarfile = jar.substring("jar:".length(), jar.length() - "/org/kchine/r/server/CoreMain.class".length() - 1);
           System.out.println("jarfile:" + jarfile);
           try {
              codeUrls.add(new URL(jarfile));
           } catch (Exception e) {
              e.printStackTrace();
           }
        }
        */
    }

    boolean wait = System.getProperty("wait") == null || System.getProperty("wait").equals("")
            || new Boolean(System.getProperty("wait"));

    RServices r = null;

    if (ServerDefaults.isRegistryAccessible()) {
        String name = System.getProperty("name");
        String rbinary = System.getProperty("r.binary");
        r = ServerManager.createR(rbinary, false, wait ? false : true, PoolUtils.getHostIp(),
                LocalHttpServer.getLocalHttpServerPort(), ServerManager.getNamingInfo(),
                ServerDefaults._memoryMin, ServerDefaults._memoryMax, name, false,
                (URL[]) codeUrls.toArray(new URL[0]), System.getProperty("log.file"), "standard",
                new Runnable() {
                    public void run() {
                        System.exit(0);
                    }
                }, null);

    } else {
        System.out.println("Can't Launch R Server, Rmi Registry is not accessible!!");
    }

    /*
     * inet httpServerPort=-1; try { if
     * (System.getProperty("http.port")!=null &&
     * !System.getProperty("http.port").equals("")) {
     * httpServerPort=Integer.decode(System.getProperty("http.port")); } }
     * catch (Exception e) {} if (httpServerPort!=-1) {
     * r.startHttpServer(httpServerPort); }
     */

    if (wait) {
        while (true) {
            try {
                Thread.sleep(100);
            } catch (Exception e) {
            }
        }
    } else {
        System.exit(0);
    }
}

From source file:Main.java

public static byte toByte(String value) {
    return Integer.decode(value).byteValue();
}

From source file:Main.java

public static void incrementAttributeValue(Node node, String attName, String attValue) {
    try {//  ww  w  . ja v a2 s  . co  m
        incrementAttributeValue(node, attName, Integer.decode(attValue));
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:Main.java

public static byte[] hexStringToBytes(String hex) {
    byte[] bytes = new byte[hex.length() / 2];
    int j = 0;/*  ww w  .j  a v  a 2 s  . c o  m*/

    for (int i = 0; i < hex.length(); i += 2) {
        try {
            String hexByte = hex.substring(i, i + 2);
            Integer I = new Integer(0);
            I = Integer.decode("0x" + hexByte);
            int k = I.intValue();
            bytes[j++] = new Integer(k).byteValue();
        } catch (NumberFormatException e) {
            Log.d(LOG_TAG, "hexStringToBytes", e);
            return bytes;
        } catch (StringIndexOutOfBoundsException e) {
            Log.d(LOG_TAG, "hexStringToBytes", e);
            return bytes;
        }
    }
    return bytes;
}

From source file:Main.java

/**
 * get a color as a int from a string, alpha is set to 255
 * if we can not get the color then we return 0
 *//*  ww w  . j  ava  2s.c  o m*/
public static int getColor(String nm) {

    Integer color = (Integer) stringToInt.get(nm);
    if (color != null) {
        return color.intValue();
    }

    try {

        Integer result = Integer.decode(nm);

        // the 0xff000000 | means the alpha is 255
        return 0xff000000 | result.intValue();
    } catch (Exception ex) {

        //System.out.print("Error: unable to find color "+s+".\n"); // testing
        return 0;
    }
}

From source file:Main.java

/**
 * @param string/*from  w  w  w  .java 2  s .  com*/
 * @return
 */
public static byte[] toByte(String string) {
    byte[] data = new byte[string.length() / 2];

    int loc = 0;
    for (int i = 0; i < string.length(); i += 2) {
        int hex = Integer.decode("0x" + string.charAt(i) + "" + string.charAt(i + 1));
        data[loc++] = (byte) hex;
    }

    return data;
}

From source file:Main.java

@SuppressWarnings("checkstyle:magicnumber")
private static int decodeColor(String colorString) {
    final Integer intval = Integer.decode(colorString);
    return intval.intValue();
}

From source file:Main.java

public static int parseDuration(String dur) {
    if (TextUtils.isEmpty(dur))
        return 0;
    String[] strings = dur.split(":");
    if (strings.length != 3)
        return 0;
    try {//from www . jav  a  2 s  .  c o  m
        int sec = 0;
        if (!TextUtils.isEmpty(strings[0])) {
            sec += TimeUnit.SECONDS.convert(Integer.decode(strings[0]), TimeUnit.HOURS);
        }
        sec += TimeUnit.SECONDS.convert(Integer.decode(strings[1]), TimeUnit.MINUTES);
        sec += TimeUnit.SECONDS.convert(Integer.decode(strings[2].substring(0, 2)), TimeUnit.SECONDS);
        return sec;
    } catch (NumberFormatException e) {
        return 0;
    }

}