Example usage for java.lang Integer valueOf

List of usage examples for java.lang Integer valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Integer valueOf(int i) 

Source Link

Document

Returns an Integer instance representing the specified int value.

Usage

From source file:Main.java

public static String toMHz(String mhzString) {
    return new StringBuilder().append(Integer.valueOf(mhzString) / 1000).append(" MHz").toString();
}

From source file:com.taobao.tddl.jdbc.group.util.GroupHintParser.java

public static Integer convertHint2Index(String sql) {
    String groupIndexHint = extractTDDLGroupHintString(sql);
    if (null != groupIndexHint && !groupIndexHint.equals("")) {
        String[] piece = groupIndexHint.split(":");
        return Integer.valueOf(piece[1]);
    } else {/*from  w  w w  . j a  v  a2 s  .co  m*/
        return DBSelector.NOT_EXIST_USER_SPECIFIED_INDEX;
    }
}

From source file:com.lfv.lanzius.Main.java

public static void main(String[] args) {

    /*/*  w w w  . ja va 2 s.c o m*/
     * debug levels:
     * error - Runtime errors or unexpected conditions. Expect these to be immediately visible on a status console. See also Internationalization.
     * warn  - Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Expect these to be immediately visible on a status console. See also Internationalization.
     * info  - Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum. See also Internationalization.
     * debug - detailed information on the flow through the system. Expect these to be written to logs only.
     */

    Log log = null;
    DOMConfigurator conf = new DOMConfigurator();
    DOMConfigurator.configure("data/properties/loggingproperties.xml");
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");

    try {
        if (args.length >= 1) {
            // Help
            if (args[0].startsWith("-h")) {
                printUsage();
                return;
            }
            // List devices
            else if (args[0].startsWith("-l")) {
                AudioTest.listDevices();
                return;
            }
            // Test seleted device
            else if (args[0].startsWith("-d")) {
                System.setProperty("org.apache.commons.logging.Log",
                        "org.apache.commons.logging.impl.SimpleLog");
                System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "warn");
                try {
                    String option = "all";
                    if (args.length >= 4)
                        option = args[3];

                    if (option.equals("loop:direct"))
                        AudioTest.testDevicesDirect(Integer.parseInt(args[1]), Integer.parseInt(args[2]));
                    else {
                        if (option.indexOf("debug") != -1)
                            System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "debug");

                        AudioTest.testDevices(Integer.parseInt(args[1]), Integer.parseInt(args[2]), option,
                                (args.length >= 5) ? args[4] : null, (args.length >= 6) ? args[5] : null,
                                (args.length >= 7) ? args[6] : null);
                    }
                } catch (Exception ex) {
                    System.out.println();
                    System.out.println(Config.VERSION);
                    System.out.println();
                    System.out.println("Usage:");
                    System.out.println(
                            "  yada.jar -d output_device input_device <option> <jitter_buffer> <output_buffer> <input_buffer>");
                    System.out.println("  option:");
                    System.out.println("    all(default)");
                    System.out.println("    clip");
                    System.out.println("    loop:jspeex");
                    System.out.println("    loop:null");
                    System.out.println("    loop:direct");
                    System.out.println("    loopdebug:jspeex");
                    System.out.println("    loopdebug:null");
                    System.out.println("  jitter_buffer:");
                    System.out.println("    size of jitter buffer in packets (1-20)");
                    System.out.println("  output_buffer:");
                    System.out.println("    size of output buffer in packets (1.0-4.0)");
                    System.out.println("  input_buffer:");
                    System.out.println("    size of input buffer in packets (1.0-4.0)");
                    System.out.println();
                    if (AudioTest.showStackTrace && !(ex instanceof ArrayIndexOutOfBoundsException))
                        ex.printStackTrace();
                }
                //System.out.println("Exiting...");
                return;
            } else if (args[0].startsWith("-m")) {
                System.setProperty("org.apache.commons.logging.Log",
                        "org.apache.commons.logging.impl.SimpleLog");
                System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "warn");
                try {
                    AudioTest.testMicrophoneLevel(Integer.parseInt(args[1]));
                } catch (Exception ex) {
                    System.out.println();
                    System.out.println(Config.VERSION);
                    System.out.println();
                    System.out.println("Usage:");
                    System.out.println("  yada.jar -m input_device");
                    System.out.println();
                    if (AudioTest.showStackTrace && !(ex instanceof ArrayIndexOutOfBoundsException))
                        ex.printStackTrace();
                }
                return;
            } else if (args[0].startsWith("-s")) {
                Packet.randomSeed = 9182736455L ^ System.currentTimeMillis();
                if (args.length > 2 && args[1].startsWith("-configuration")) {
                    String configFilename = args[2];
                    if (args.length > 4 && args[3].startsWith("-exercise")) {
                        String exerciseFilename = args[4];

                        LanziusServer.start(configFilename, exerciseFilename);
                    } else {
                        LanziusServer.start(configFilename);
                    }
                } else {
                    LanziusServer.start();
                }
                return;
            } else if (args[0].startsWith("-f")) {
                System.setProperty("org.apache.commons.logging.Log",
                        "org.apache.commons.logging.impl.SimpleLog");
                System.setProperty(
                        "org.apache.commons.logging.simplelog.log.com.lfv.lanzius.application.FootSwitchController",
                        "debug");
                try {
                    System.out.println("Starting footswitch controller test using device " + args[1]);
                    try {
                        boolean inverted = false;
                        if (args.length >= 3)
                            inverted = args[2].toLowerCase().startsWith("inv");
                        FootSwitchController c = new FootSwitchController(null, args[1],
                                Constants.PERIOD_FTSW_CONNECTED, inverted);
                        c.start();
                        Thread.sleep(30000);
                    } catch (UnsatisfiedLinkError err) {
                        if (args.length > 1)
                            System.out.println("UnsatisfiedLinkError: " + err.getMessage());
                        else
                            throw new ArrayIndexOutOfBoundsException();
                        System.out.println("Missing ftsw library (ftsw.dll or libftsw.so)");
                        if (!args[1].equalsIgnoreCase("ftdi"))
                            System.out
                                    .println("Missing rxtxSerial library (rxtxSerial.dll or librxtxSerial.so)");
                        if (AudioTest.showStackTrace)
                            err.printStackTrace();
                    }
                } catch (Exception ex) {
                    if (ex instanceof NoSuchPortException)
                        System.out.println("The serial port " + args[1] + " does not exist!");
                    else if (ex instanceof PortInUseException)
                        System.out.println("The serial port " + args[1] + " is already in use!");
                    System.out.println();
                    System.out.println(Config.VERSION);
                    System.out.println();
                    System.out.println("Usage:");
                    System.out.println("  yada.jar -f interface <invert>");
                    System.out.println("  interface:");
                    System.out.println("    ftdi");
                    System.out.println("    comport (COMx or /dev/ttyx)");
                    System.out.println("  invert:");
                    System.out.println("    true");
                    System.out.println("    false (default)");
                    System.out.println();
                    if (AudioTest.showStackTrace && !(ex instanceof ArrayIndexOutOfBoundsException))
                        ex.printStackTrace();
                }
                return;
            } else if (args[0].startsWith("-c")) {
                Packet.randomSeed = 7233103157L ^ System.currentTimeMillis();
                if (args.length >= 2) {
                    try {
                        int id = Integer.valueOf(args[1]);
                        if (id <= 0)
                            throw new NumberFormatException();
                        Controller c = Controller.getInstance();
                        if (args.length >= 3) {
                            if (args[2].equalsIgnoreCase("test")) {
                                c.setAutoTester(true);
                            }
                        }
                        c.init(id);
                        return;
                    } catch (NumberFormatException ex) {
                        printUsage();
                    }
                } else {
                    Controller.getInstance().init(0);
                }
            } else
                printUsage();
        } else
            printUsage();
    } catch (Throwable t) {
        if (log == null)
            log = LogFactory.getLog(Main.class);
        log.error("Unhandled exception or error", t);
    }
}

From source file:Main.java

public static Integer getIntegerAttr(Element element, String name, int def) {
    String attr = element.getAttribute(name);
    if (!attr.isEmpty()) {
        Integer ret = Integer.valueOf(attr);
        return ret;
    }// w w w . j ava  2  s  .c  om
    return def;
}

From source file:Main.java

public static Object typeConversion(Class<?> cls, String str) {
    Object obj = null;//from  www  .  ja v  a  2 s  . c  om
    String nameType = cls.getSimpleName();
    if ("Integer".equals(nameType)) {
        obj = Integer.valueOf(str);
    }
    if ("String".equals(nameType)) {
        obj = str;
    }
    if ("Float".equals(nameType)) {
        obj = Float.valueOf(str);
    }
    if ("Double".equals(nameType)) {
        obj = Double.valueOf(str);
    }

    if ("Boolean".equals(nameType)) {
        obj = Boolean.valueOf(str);
    }
    if ("Long".equals(nameType)) {
        obj = Long.valueOf(str);
    }

    if ("Short".equals(nameType)) {
        obj = Short.valueOf(str);
    }

    if ("Character".equals(nameType)) {
        obj = str.charAt(1);
    }

    return obj;
}

From source file:Main.java

public static Integer getViewablePeriod(String viewablePeriod) {
    String viewable = null;// w w  w. j  a v  a 2s  . co m

    if (viewablePeriod.substring(9, 10).equals(" ")) {
        viewable = String.valueOf((Integer.parseInt(viewablePeriod.substring(0, 4)) * 365)
                + (Integer.parseInt(viewablePeriod.substring(5, 7)) * 30)
                + Integer.parseInt(viewablePeriod.substring(8, 9)));
    } else if (viewablePeriod.substring(10, 11).equals(" ")) {
        viewable = String.valueOf((Integer.parseInt(viewablePeriod.substring(0, 4)) * 365)
                + (Integer.parseInt(viewablePeriod.substring(5, 7)) * 30)
                + Integer.parseInt(viewablePeriod.substring(8, 10)));
    } else if (viewablePeriod.substring(11, 12).equals(" ")) {
        viewable = String.valueOf((Integer.parseInt(viewablePeriod.substring(0, 4)) * 365)
                + (Integer.parseInt(viewablePeriod.substring(5, 7)) * 30)
                + Integer.parseInt(viewablePeriod.substring(8, 11)));
    }

    return Integer.valueOf(viewable);
}

From source file:Main.java

/**
 * Converts to object array.// w  w  w  .jav  a  2 s . c om
 */
public static Integer[] valuesOf(int[] array) {
    Integer[] dest = new Integer[array.length];
    for (int i = 0; i < array.length; i++) {
        dest[i] = Integer.valueOf(array[i]);
    }
    return dest;
}

From source file:Main.java

/**
 * Get the VNC port forward/*from   w  w w . j a va 2s. co m*/
 * 
 * @param serial port number
 * @return VNC port
 */
public static int getVncServerPortFoward(String serial) {
    if (serial == null) {
        return 0;
    }

    int stringSize = serial.length();
    String lastTwoNumbers = serial.substring(stringSize - 2, stringSize);

    int port = INITIAL_VNC_PORT_VALUE;

    try {
        port += Integer.valueOf(lastTwoNumbers);
    } catch (NumberFormatException e) {
        // do nothing (this should not happen)
    }

    return port;

}

From source file:Main.java

/** Given a parent element, locate integer value of a child node.
 *  @param parent Parent element/* w w w .  ja v  a2  s .c  om*/
 *  @param name Name of child element
 *  @return Value of child element, or empty result
 *  @throws Exception on error parsing the number
 */
public static Optional<Integer> getChildInteger(final Element parent, final String name) throws Exception {
    final Element child = getChildElement(parent, name);
    if (child == null)
        return Optional.empty();
    try {
        return Optional.of(Integer.valueOf(getString(child)));
    } catch (NumberFormatException ex) {
        throw new Exception("Expected integer for <" + name + ">", ex);
    }
}

From source file:Main.java

public static int string2Time(String text) {
    String[] splitted = text.split(":");

    if (splitted.length > 3) {
        throw new IllegalArgumentException(
                "Badely formatted string in string2time, formats allowed are mm, mm:ss or hh:mm:ss.");
    }// w  w  w  .j a  va 2 s.c  o m

    if (splitted.length == 1) { // "mm"
        return Integer.valueOf(splitted[0]) * 60;
    } else if (splitted.length == 2) { // "mm:ss"
        return Integer.valueOf(splitted[0]) * 60 + Integer.valueOf(splitted[1]);
    } else { // "hh:mm:ss"
        return Integer.valueOf(splitted[0]) * 3600 + Integer.valueOf(splitted[1]) * 60
                + Integer.valueOf(splitted[2]);
    }
}