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 parse(String str, boolean fallback) {
    if (str == null) {
        return fallback;
    }/*from w w w  .j a  v a 2 s .  c  o  m*/
    return Boolean.parseBoolean(str);
}

From source file:Main.java

public static Boolean TransformBoolean(String str) {
    if (TextUtils.isEmpty(str) || str.equals("null")) {
        return false;
    }/*from  www  . ja  v  a 2 s .c  o m*/
    return Boolean.parseBoolean(str);
}

From source file:Main.java

public static boolean str2Bool(String obj, Boolean defValue) {
    try {/* w w  w  . j a v  a 2s . c  o m*/
        if (TextUtils.isEmpty(obj))
            return defValue;
        return Boolean.parseBoolean(obj);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return defValue;
}

From source file:Main.java

public static Boolean getAttributeBooleanValue(Element element, String attributeName) {
    String stringValue = getAttributeStringValue(element, attributeName);
    return Boolean.parseBoolean(stringValue);
}

From source file:Main.java

public static boolean doBoolean(Object obj, boolean defValue) {
    return obj != null ? Boolean.parseBoolean(obj.toString()) : defValue;
}

From source file:Main.java

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

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

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

public static void main(String[] args) throws Exception {
    try {//  ww w. j a v  a2s  .com
        // 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: 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("s", "shunra-file-path", true,
                "[optional] File path for the .shunra file to analyze");
        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("f", "first-test-flow-tcp-port", true,
                "[optional] TCP port for the flow of the first test");
        options.addOption("g", "second-test-flow-tcp-port", true,
                "[optional] TCP port for the flow of the second test");
        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("AdvAllTestManagerClassMethods.java", options);
            return;
        }

        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("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("zip-result-file-path")) {
            zipResultFilePath = line.getOptionValue("zip-result-file-path");
        }

        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("shunra-file-path")) {
            shunraFilePath = line.getOptionValue("shunra-file-path");
        }

        if (line.hasOption("firstTestFlowTcpPort")) {
            firstTestFlowTcpPort = Integer.parseInt(line.getOptionValue("firstTestFlowTcpPort"));
        } else {
            firstTestFlowTcpPort = 8080;
        }

        if (line.hasOption("secondTestFlowTcpPort")) {
            secondTestFlowTcpPort = Integer.parseInt(line.getOptionValue("secondTestFlowTcpPort"));
        } else {
            secondTestFlowTcpPort = 80;
        }

        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 TestManager class APIs. These APIs let you:                                 ***"
                + newLine
                + "***   * initialize the TestManager object to pass logon credentials, the NV Test Manager IP, the port, and so on      ***"
                + newLine
                + "***   * set/get the NV configuration and active adapter                                                               ***"
                + newLine
                + "***   * get the running tests tokens                                                                                  ***"
                + newLine
                + "***   * start/stop packet list capture                                                                                ***"
                + newLine
                + "***   * get packet list information                                                                                   ***"
                + newLine
                + "***   * stop a specified array of tests or all of the running tests                                                   ***"
                + newLine
                + "***   * analyze a .shunra file, which is a compressed file that includes an events file, metadata, and packet lists   ***"
                + newLine
                + "***                                                                                                                   ***"
                + newLine
                + "***   You can view the actual steps of this sample in the AdvAllTestManagerClassMethods.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/get the NV configuration and active adapter                                                                     *****/
        printPartDescription("------    Part 2 - Set/get the NV configuration and active adapter");
        setActiveAdapter();
        getActiveAdapter();
        setConfiguration();
        getConfiguration();
        printPartSeparator();
        /*****    Part 3 - Start tests and get the NV tests' tokens                                                                             *****/
        printPartDescription("------    Part 3 - Start tests and get the NV tests' tokens");
        startTest1();
        connectTest1ToTransactionManager();
        startTest2();
        connectTest2ToTransactionManager();
        getTestTokens();
        printPartSeparator();
        /*****    Part 4 - Start NV transactions, navigate to the site and start capturing the packet lists                                     *****/
        printPartDescription(
                "------    Part 4 - Start NV transactions, navigate to the site and start capturing the packet lists");
        startTransaction1();
        startTransaction2();
        startPacketListCapture();
        buildSeleniumWebDriver();
        seleniumNavigateToPage();
        printPartSeparator();
        /*****    Part 5 - Get the packet list information and print it to the console (if the --debug argument is set to true)                 *****/
        printPartDescription(
                "------    Part 5 - Get the packet list information and print it to the console (if the --debug argument is set to true)");
        getPacketListInfo();
        printPartSeparator();
        /*****    Part 6 - Stop capturing packet lists and stop the NV transactions                                                             *****/
        printPartDescription("------    Part 6 - Stop capturing packet lists and stop the NV transactions");
        stopPacketListCapture();
        stopTransaction1();
        siteTransaction1 = null;
        stopTransaction2();
        siteTransaction2 = null;
        printPartSeparator();
        /*****    Part 7 - Stop the first NV test using the "stopTests" method and then stop the second test using the "stopAllTests" method    *****/
        printPartDescription(
                "------    Part 7 - Stop the first NV test using the \"stopTests\" method and then stop the second test using the \"stopAllTests\" method");
        stopTest1();
        siteTest1 = null;
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        stopAllTests();
        siteTest2 = null;
        printPartSeparator();
        /*****    Part 8 - Analyze the specified .shunra file and print the results to the console                                              *****/
        printPartDescription(
                "------    Part 8 - Analyze the specified .shunra file and print the results to the console");
        analyzeShunra();
        printPartSeparator();
        doneCallback();
    } catch (Exception e) {
        try {
            handleError(e.getMessage());
        } catch (Exception e2) {
            System.out.println("Error occurred: " + e2.getMessage());
        }
    }
}

From source file:Main.java

public static final boolean getBooleanAttribute(final Attributes pAttributes, final String pAttributeName,
        final boolean pDefaultValue) {
    final String value = pAttributes.getValue("", pAttributeName);
    return (value != null) ? Boolean.parseBoolean(value) : pDefaultValue;
}

From source file:Main.java

/**
 * Tries to parse specified object to boolean. If object is null, returns null.
 *
 * @param o Object to be parsed//from   w w w  . j  a v a  2  s  .c  o  m
 * @return Parsed object or null
 */
public static Boolean parseBoolean(Object o) {
    if (o == null) {
        return null;
    }
    return Boolean.parseBoolean((String) o);
}

From source file:Main.java

public static boolean getTagValueAsBoolean(Document document, String tagName) {
    boolean tagValue = false;

    String tempVal = getTagValueAsString(document, tagName);
    tagValue = Boolean.parseBoolean(tempVal);

    return tagValue;
}