Example usage for java.lang Boolean parseBoolean

List of usage examples for java.lang Boolean parseBoolean

Introduction

In this page you can find the example usage for java.lang Boolean parseBoolean.

Prototype

public static boolean parseBoolean(String s) 

Source Link

Document

Parses the string argument as a boolean.

Usage

From source file:Main.java

public static Boolean getAttribAsBoolean(Element e, String name, Boolean dft) {
    if (getAttribute(e, name) == null)
        return dft;
    else// ww  w .ja  va 2s  . co m
        return Boolean.parseBoolean(getAttribute(e, name));
}

From source file:Main.java

public static Boolean getElementAsBoolean(Element e, String name, Boolean dft) {
    if (getElement(e, name) == null)
        return dft;
    else//from www  .  ja  v  a 2 s.  co m
        return Boolean.parseBoolean(getElement(e, name));
}

From source file:com.hpe.nv.samples.advanced.AdvAllTestClassMethods.java

public static void main(String[] args) throws Exception {
    try {/*w  w  w  . j a v  a2s . c o m*/
        // program arguments
        Options options = new Options();
        options.addOption("i", "server-ip", true, "[mandatory] NV Test Manager IP");
        options.addOption("o", "server-port", true, "[mandatory] NV Test Manager port");
        options.addOption("u", "username", true, "[mandatory] NV username");
        options.addOption("w", "password", true, "[mandatory] NV password");
        options.addOption("e", "ssl", true, "[optional] Pass true to use SSL. Default: false");
        options.addOption("y", "proxy", true, "[optional] Proxy server host:port");
        options.addOption("t", "site-url", true,
                "[optional] Site under test URL. Default: Default: HPE Network Virtualization site URL. If you change this value, make sure to change the --xpath argument too");
        options.addOption("x", "xpath", true,
                "[optional] Parameter for ExpectedConditions.visibilityOfElementLocated(By.xpath(...)) method. Use an xpath expression of some element in the site. Default: //div[@id='content']");
        options.addOption("a", "active-adapter-ip", true,
                "[optional] Active adapter IP. Default: --server-ip argument");
        options.addOption("m", "mode", true, "[mandatory] Test mode - ntx or custom");
        options.addOption("n", "ntx-file-path", true,
                "[mandatory in ntx mode] File path of an .ntx/.ntxx file - used to start the test in ntx mode");
        options.addOption("z", "zip-result-file-path", true,
                "[optional] File path to store the analysis results as a .zip file");
        options.addOption("k", "analysis-ports", true,
                "[optional] A comma-separated list of ports for test analysis");
        options.addOption("p", "packet-list-id", true,
                "[optional] A packet list ID used for capturing a specific packet list and downloading its corresponding .shunra file");
        options.addOption("c", "packet-list-file-path", true,
                "[optional] .pcap file path - used to store all captured packet lists");
        options.addOption("s", "shunra-file-path", true, "[optional] .shunra file path for download");
        options.addOption("b", "browser", true,
                "[optional] The browser for which the Selenium WebDriver is built. Possible values: Chrome and Firefox. Default: Firefox");
        options.addOption("d", "debug", true,
                "[optional] Pass true to view console debug messages during execution. Default: false");
        options.addOption("h", "help", false, "[optional] Generates and prints help information");

        // parse and validate the command line arguments
        CommandLineParser parser = new DefaultParser();
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help")) {
            // print help if help argument is passed
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("AdvAllTestClassMethods.java", options);
            return;
        }

        if (line.hasOption("mode")) {
            mode = ((String) line.getOptionValue("mode")).toLowerCase();
        } else {
            throw new Exception("Missing argument -m/--mode <mode>");
        }

        if (!mode.equals("custom") && !mode.equals("ntx")) {
            throw new Exception("Mode not supported. Supported modes are: ntx or custom");
        }

        if (mode.equals("ntx")) {
            if (line.hasOption("ntx-file-path")) {
                ntxFilePath = line.getOptionValue("ntx-file-path");
            } else {
                throw new Exception("Missing argument -n/--ntx-file-path <ntxFilePath>");
            }
        }

        if (line.hasOption("server-ip")) {
            serverIp = line.getOptionValue("server-ip");
            if (serverIp.equals("0.0.0.0")) {
                throw new Exception(
                        "Please replace the server IP argument value (0.0.0.0) with your NV Test Manager IP");
            }
        } else {
            throw new Exception("Missing argument -i/--server-ip <serverIp>");
        }

        if (line.hasOption("server-port")) {
            serverPort = Integer.parseInt(line.getOptionValue("server-port"));
        } else {
            throw new Exception("Missing argument -o/--server-port <serverPort>");
        }

        if (line.hasOption("username")) {
            username = line.getOptionValue("username");
        } else {
            throw new Exception("Missing argument -u/--username <username>");
        }

        if (line.hasOption("password")) {
            password = line.getOptionValue("password");
        } else {
            throw new Exception("Missing argument -w/--password <password>");
        }

        if (line.hasOption("ssl")) {
            ssl = Boolean.parseBoolean(line.getOptionValue("ssl"));
        }

        if (line.hasOption("zip-result-file-path")) {
            zipResultFilePath = line.getOptionValue("zip-result-file-path");
        }

        if (line.hasOption("packet-list-id")) {
            packetListId = line.getOptionValue("packet-list-id");
        }

        if (line.hasOption("packet-list-file-path")) {
            packetListFilePath = line.getOptionValue("packet-list-file-path");
        }

        if (line.hasOption("shunra-file-path")) {
            shunraFilePath = line.getOptionValue("shunra-file-path");
        }

        if (line.hasOption("site-url")) {
            siteUrl = line.getOptionValue("site-url");
        } else {
            siteUrl = "http://www8.hp.com/us/en/software-solutions/network-virtualization/index.html";
        }

        if (line.hasOption("xpath")) {
            xpath = line.getOptionValue("xpath");
        } else {
            xpath = "//div[@id='content']";
        }

        if (line.hasOption("proxy")) {
            proxySetting = line.getOptionValue("proxy");
        }

        if (line.hasOption("active-adapter-ip")) {
            activeAdapterIp = line.getOptionValue("active-adapter-ip");
        } else {
            activeAdapterIp = serverIp;
        }

        if (line.hasOption("analysis-ports")) {
            String analysisPortsStr = line.getOptionValue("analysis-ports");
            analysisPorts = analysisPortsStr.split(",");
        } else {
            analysisPorts = new String[] { "80", "8080" };
        }

        if (line.hasOption("browser")) {
            browser = line.getOptionValue("browser");
        } else {
            browser = "Firefox";
        }

        if (line.hasOption("debug")) {
            debug = Boolean.parseBoolean(line.getOptionValue("debug"));
        }

        String newLine = System.getProperty("line.separator");
        String testDescription = "***   This sample demonstrates all of the Test class APIs except for the                      ***"
                + newLine
                + "***   real-time update API, which is demonstrated in AdvRealtimeUpdate.java.                  ***"
                + newLine
                + "***   You can start the test in this sample using either the NTX or Custom modes.             ***"
                + newLine
                + "***                                                                                           ***"
                + newLine
                + "***   You can view the actual steps of this sample in the AdvAllTestClassMethods.java file.   ***"
                + newLine;

        // print the sample's description
        System.out.println(testDescription);

        // start console spinner
        if (!debug) {
            spinner = new Thread(new Spinner());
            spinner.start();
        }

        // sample execution steps
        /*****    Part 1 - Initialize the TestManager object to pass logon credentials, the NV Test Manager IP, the port, and so on                                                      *****/
        printPartDescription(
                "\b------    Part 1 - Initialize the TestManager object to pass logon credentials, the NV Test Manager IP, the port, and so on");
        initTestManager();
        printPartSeparator();
        /*****    Part 2 - Set the active adapter and start the NV test                                                                                                                  *****/
        printPartDescription("------    Part 2 - Set the active adapter and start the NV test");
        setActiveAdapter();
        startTest();
        testRunning = true;
        connectToTransactionManager();
        printPartSeparator();
        /*****    Part 3 - Start packet list capture, get the packet list information and print it to the console (if the --debug argument is set to true)                               *****/
        printPartDescription(
                "------    Part 3 - Start packet list capture, get the packet list information and print it to the console (if the --debug argument is set to true)");
        startPacketListCapture();
        getPacketListInfo();
        printPartSeparator();
        /*****    Part 4 - Start the NV transaction and navigate to the site                                                                                                             *****/
        printPartDescription("------    Part 4 - Start the NV transaction and navigate to the site");
        startTransaction();
        transactionInProgress = true;
        buildSeleniumWebDriver();
        seleniumNavigateToPage();
        printPartSeparator();
        /*****    Part 5 - Get the NV test statistics and print the Client-in statistics to the console (if the --debug argument is set to true)                                         *****/
        printPartDescription(
                "------    Part 5 - Get the NV test statistics and print the Client-in statistics to the console (if the --debug argument is set to true)");
        getTestStatistics();
        printPartSeparator();
        /*****    Part 6 - Stop the NV transaction and the packet list capture, get the packet list information and print it to the console (if the --debug argument is set to true)     *****/
        printPartDescription(
                "------    Part 6 - Stop the NV transaction and the packet list capture, get the packet list information and print it to the console (if the --debug argument is set to true)");
        stopTransaction();
        transactionInProgress = false;
        stopPacketListCapture();
        getPacketListInfo();
        printPartSeparator();
        /*****    Part 7 - Disconnect from the transaction manager and stop the NV test                                                                                                  *****/
        printPartDescription("------    Part 7 - Disconnect from the transaction manager and stop the NV test");
        disconnectFromTransactionManager();
        stopTest();
        testRunning = false;
        printPartSeparator();
        /*****    Part 8 - Analyze the NV test and print the results to the console                                                                                                      *****/
        printPartDescription("------    Part 8 - Analyze the NV test and print the results to the console");
        analyzeTest();
        printPartSeparator();
        /*****    Part 9 - Download the specified packet list and the .shunra file                                                                                                      *****/
        printPartDescription("------    Part 9 - Download the specified packet list and the .shunra file");
        downloadPacketList();
        downloadShunra();
        printPartSeparator();
        doneCallback();
    } catch (Exception e) {
        try {
            handleError(e.getMessage());
        } catch (Exception e2) {
            System.out.println("Error occurred: " + e2.getMessage());
        }
    }
}

From source file:Main.java

/**
 * //  w  w  w. j  a  va2  s  .  c  om
 * @param object
 * @return
 */
protected static Boolean toBoolean(Object object) {
    String str = toString(object);
    if ("".equals(str))
        return true;
    else
        return Boolean.parseBoolean(str);
}

From source file:Main.java

/**
 * Safely converts an object into an boolean
 *
 * @param obj//ww  w .j  av  a  2 s .  c  o  m
 *            The object to convert.
 * @return a Boolean representing the boolean value of the Object (null if
 *         the object cannot be converted to Boolean)
 */
public static Boolean safeJsonToBoolean(Object obj) {
    Boolean booleanValue;

    try {
        booleanValue = Boolean.parseBoolean(safeJsonToString(obj));
    } catch (NumberFormatException e) {
        booleanValue = null;
    }

    return booleanValue;
}

From source file:Main.java

/**
 * Parses the value of the given attribute as an boolean.
 * @param attributeName the name of the attribute.
 * @param map the map that contains all the attributes.
 * @return the float value.// ww w  .ja v a 2s .c o m
 */
public static boolean parseBoolean(String attributeName, NamedNodeMap map) {
    org.w3c.dom.Node attr = map.getNamedItem(attributeName);
    return attr != null ? Boolean.parseBoolean(attr.getTextContent()) : false;
}

From source file:Main.java

/**
 * parse value to boolean/*from   w w w  .  j a v  a2 s  .  c o  m*/
 */
public static boolean toBoolean(String value) {
    return TextUtils.isEmpty(value) ? false : Boolean.parseBoolean(value);
}

From source file:Main.java

/**
 * This method parses the given value into the specified primitive or wrapper class.
 * @param clazz - primitive or wrapper class used to parse
 * @param value - string to be parsed/*from   w w w .j  ava  2  s  .  c  o  m*/
 * @return object of type clazz parsed from the string
 * @author Trisan Bepler
 */
public static Object toObject(Class<?> clazz, String value) {
    if (Boolean.TYPE == clazz)
        return Boolean.parseBoolean(value);
    if (Byte.TYPE == clazz)
        return Byte.parseByte(value);
    if (Short.TYPE == clazz)
        return Short.parseShort(value);
    if (Integer.TYPE == clazz)
        return Integer.parseInt(value);
    if (Long.TYPE == clazz)
        return Long.parseLong(value);
    if (Float.TYPE == clazz)
        return Float.parseFloat(value);
    if (Double.TYPE == clazz)
        return Double.parseDouble(value);
    if (Boolean.class == clazz)
        return Boolean.parseBoolean(value);
    if (Byte.class == clazz)
        return Byte.parseByte(value);
    if (Short.class == clazz)
        return Short.parseShort(value);
    if (Integer.class == clazz)
        return Integer.parseInt(value);
    if (Long.class == clazz)
        return Long.parseLong(value);
    if (Float.class == clazz)
        return Float.parseFloat(value);
    if (Double.class == clazz)
        return Double.parseDouble(value);
    if (Character.class == clazz)
        return value.charAt(0);
    if (Character.TYPE == clazz)
        return value.charAt(0);
    return value;
}

From source file:Main.java

public static Boolean getAttributeValueAsBoolean(Node node, String attributeName) {
    final Node attributeNode = node.getAttributes().getNamedItem(attributeName);

    return attributeNode != null ? Boolean.parseBoolean(attributeNode.getTextContent()) : null;
}

From source file:Main.java

public static boolean toBool(String b) {
    try {//from   w w  w. j  a v  a2 s.  co  m
        return Boolean.parseBoolean(b);
    } catch (Exception e) {
    }
    return false;
}