Example usage for org.apache.commons.lang3 StringUtils isEmpty

List of usage examples for org.apache.commons.lang3 StringUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isEmpty.

Prototype

public static boolean isEmpty(final CharSequence cs) 

Source Link

Document

Checks if a CharSequence is empty ("") or null.

 StringUtils.isEmpty(null)      = true StringUtils.isEmpty("")        = true StringUtils.isEmpty(" ")       = false StringUtils.isEmpty("bob")     = false StringUtils.isEmpty("  bob  ") = false 

NOTE: This method changed in Lang version 2.0.

Usage

From source file:com.github.brosander.java.performance.sampler.analysis.PerformanceSampleAnalyzer.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("i", FILE_OPT, true, "The file to analyze.");
    options.addOption("o", OUTPUT_FILE_OPT, true, "The output file (default json to stdout).");
    options.addOption("p", RELEVANT_PATTERN_OPT, true,
            "Pattern(s) to include as roots in the output (default: " + DEFAULT_PATTERN + ")");
    CommandLineParser parser = new DefaultParser();
    try {/* w w w  . j  a v a  2s.com*/
        CommandLine commandLine = parser.parse(options, args);
        String file = commandLine.getOptionValue(FILE_OPT);
        if (StringUtils.isEmpty(file)) {
            printUsageAndExit("Must specify file", options, 1);
        }
        Pattern relevantPattern = Pattern
                .compile(commandLine.getOptionValue(RELEVANT_PATTERN_OPT, DEFAULT_PATTERN));
        PerformanceSampleElement performanceSampleElement = relevantElements(relevantPattern,
                new ObjectMapper().readValue(new File(file), PerformanceSampleElement.class));
        updateCounts(performanceSampleElement);
        String outputFile = commandLine.getOptionValue(OUTPUT_FILE_OPT);
        if (StringUtils.isEmpty(outputFile)) {
            new ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(System.out,
                    new OutputPerformanceSampleElement(performanceSampleElement));
        } else {
            new ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(new File(outputFile),
                    new OutputPerformanceSampleElement(performanceSampleElement));
        }
    } catch (Exception e) {
        e.printStackTrace();
        printUsageAndExit(e.getMessage(), options, 2);
    }
}

From source file:de.micromata.genome.gwiki.tools.PatchVersion.java

public static void main(String[] args) {
    PatchVersion pv = new PatchVersion(null);

    for (int i = 0; i < args.length; ++i) {
        String s = args[i];//from w w w  . ja v a  2  s .  c  om
        if (s.equals("-expected") == true) {
            if (args.length <= i + 1) {
                System.out.println("Required expected string");
                System.exit(1);
            }
            ++i;
            pv.expected = args[i];
            continue;
        }
        if (s.equals("-test") == true) {
            pv.testOnly = true;
            continue;
        }
        if (StringUtils.isEmpty(pv.version) == false) {
            System.out.println("Version already set");
            System.exit(1);
        } else {
            pv.version = s;
        }
    }
    if (StringUtils.isEmpty(pv.version) == true) {
        System.out.println("Missing required version");
        System.exit(1);
    }

    pv.patch();

}

From source file:io.cloudslang.lang.tools.build.SlangBuildMain.java

public static void main(String[] args) {
    loadUserProperties();/*www.j a va2 s  .c  o  m*/
    configureLog4j();

    ApplicationArgs appArgs = new ApplicationArgs();
    parseArgs(args, appArgs);
    String projectPath = parseProjectPathArg(appArgs);
    final String contentPath = defaultIfEmpty(appArgs.getContentRoot(), projectPath + CONTENT_DIR);
    final String testsPath = defaultIfEmpty(appArgs.getTestRoot(), projectPath + TEST_DIR);
    List<String> testSuites = parseTestSuites(appArgs);
    boolean shouldPrintCoverageData = appArgs.shouldOutputCoverage();
    boolean runTestsInParallel = appArgs.isParallel();
    int threadCount = parseThreadCountArg(appArgs, runTestsInParallel);
    String testCaseTimeout = parseTestTimeout(appArgs);
    setProperty(TEST_CASE_TIMEOUT_IN_MINUTES_KEY, valueOf(testCaseTimeout));
    final boolean shouldValidateDescription = appArgs.shouldValidateDescription();
    final boolean shouldValidateCheckstyle = appArgs.shouldValidateCheckstyle();
    String runConfigPath = FilenameUtils.normalize(appArgs.getRunConfigPath());

    BuildMode buildMode = null;
    Set<String> changedFiles = null;
    try {
        String smartModePath = appArgs.getChangesOnlyConfigPath();
        if (StringUtils.isEmpty(smartModePath)) {
            buildMode = BuildMode.BASIC;
            changedFiles = new HashSet<>();
            printBuildModeInfo(buildMode);
        } else {
            buildMode = BuildMode.CHANGED;
            changedFiles = readChangedFilesFromSource(smartModePath);
            printBuildModeInfo(buildMode);
        }
    } catch (Exception ex) {
        log.error("Exception: " + ex.getMessage());
        System.exit(1);
    }

    // Override with the values from the file if configured
    List<String> testSuitesParallel = new ArrayList<>();
    List<String> testSuitesSequential = new ArrayList<>();
    BulkRunMode bulkRunMode = runTestsInParallel ? ALL_PARALLEL : ALL_SEQUENTIAL;

    TestCaseRunMode unspecifiedTestSuiteRunMode = runTestsInParallel ? TestCaseRunMode.PARALLEL
            : TestCaseRunMode.SEQUENTIAL;
    if (get(runConfigPath).isAbsolute() && isRegularFile(get(runConfigPath), NOFOLLOW_LINKS)
            && equalsIgnoreCase(PROPERTIES_FILE_EXTENSION, FilenameUtils.getExtension(runConfigPath))) {
        Properties runConfigurationProperties = ArgumentProcessorUtils.getPropertiesFromFile(runConfigPath);
        shouldPrintCoverageData = getBooleanFromPropertiesWithDefault(TEST_COVERAGE, shouldPrintCoverageData,
                runConfigurationProperties);
        threadCount = getIntFromPropertiesWithDefaultAndRange(TEST_PARALLEL_THREAD_COUNT,
                Runtime.getRuntime().availableProcessors(), runConfigurationProperties, 1,
                MAX_THREADS_TEST_RUNNER + 1);
        testSuites = getTestSuitesForKey(runConfigurationProperties, TEST_SUITES_TO_RUN);
        testSuitesParallel = getTestSuitesForKey(runConfigurationProperties, TEST_SUITES_PARALLEL);
        testSuitesSequential = getTestSuitesForKey(runConfigurationProperties, TEST_SUITES_SEQUENTIAL);
        addErrorIfSameTestSuiteIsInBothParallelOrSequential(testSuitesParallel, testSuitesSequential);
        unspecifiedTestSuiteRunMode = getEnumInstanceFromPropertiesWithDefault(TEST_SUITES_RUN_UNSPECIFIED,
                unspecifiedTestSuiteRunMode, runConfigurationProperties);
        addWarningsForMisconfiguredTestSuites(unspecifiedTestSuiteRunMode, testSuites, testSuitesSequential,
                testSuitesParallel);
        bulkRunMode = POSSIBLY_MIXED;
    } else { // Warn when file is misconfigured, relative path, file does not exist or is not a properties file
        log.info(format(DID_NOT_DETECT_RUN_CONFIGURATION_PROPERTIES_FILE, runConfigPath));
    }

    String testCaseReportLocation = getProperty(TEST_CASE_REPORT_LOCATION);
    if (StringUtils.isBlank(testCaseReportLocation)) {
        log.info("Test case report location property [" + TEST_CASE_REPORT_LOCATION
                + "] is not defined. Report will be skipped.");
    }

    // Setting thread count for visibility in ParallelTestCaseExecutorService
    setProperty(SLANG_TEST_RUNNER_THREAD_COUNT, valueOf(threadCount));

    log.info(NEW_LINE + "------------------------------------------------------------");
    log.info("Building project: " + projectPath);
    log.info("Content root is at: " + contentPath);
    log.info("Test root is at: " + testsPath);
    log.info("Active test suites are: " + getListForPrint(testSuites));
    log.info("Parallel run mode is configured for test suites: " + getListForPrint(testSuitesParallel));
    log.info("Sequential run mode is configured for test suites: " + getListForPrint(testSuitesSequential));
    log.info("Default run mode '" + unspecifiedTestSuiteRunMode.name().toLowerCase()
            + "' is configured for test suites: " + getListForPrint(
                    getDefaultRunModeTestSuites(testSuites, testSuitesParallel, testSuitesSequential)));

    log.info("Bulk run mode for tests: " + getBulkModeForPrint(bulkRunMode));

    log.info("Print coverage data: " + valueOf(shouldPrintCoverageData));
    log.info("Validate description: " + valueOf(shouldValidateDescription));
    log.info("Validate checkstyle: " + valueOf(shouldValidateCheckstyle));
    log.info("Thread count: " + threadCount);
    log.info("Test case timeout in minutes: "
            + (isEmpty(testCaseTimeout) ? valueOf(MAX_TIME_PER_TESTCASE_IN_MINUTES) : testCaseTimeout));

    log.info(NEW_LINE + "Loading...");

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/testRunnerContext.xml");
    context.registerShutdownHook();
    SlangBuilder slangBuilder = context.getBean(SlangBuilder.class);
    LoggingService loggingService = context.getBean(LoggingServiceImpl.class);
    Slang slang = context.getBean(Slang.class);

    try {

        updateTestSuiteMappings(context.getBean(TestRunInfoService.class), testSuitesParallel,
                testSuitesSequential, testSuites, unspecifiedTestSuiteRunMode);

        registerEventHandlers(slang);

        List<RuntimeException> exceptions = new ArrayList<>();

        SlangBuildResults buildResults = slangBuilder.buildSlangContent(projectPath, contentPath, testsPath,
                testSuites, shouldValidateDescription, shouldValidateCheckstyle, bulkRunMode, buildMode,
                changedFiles);
        exceptions.addAll(buildResults.getCompilationExceptions());
        if (exceptions.size() > 0) {
            logErrors(exceptions, projectPath, loggingService);
        }
        IRunTestResults runTestsResults = buildResults.getRunTestsResults();
        Map<String, TestRun> skippedTests = runTestsResults.getSkippedTests();

        if (isNotEmpty(skippedTests)) {
            printSkippedTestsSummary(skippedTests, loggingService);
        }
        printPassedTests(runTestsResults, loggingService);
        if (shouldPrintCoverageData) {
            printTestCoverageData(runTestsResults, loggingService);
        }

        if (isNotEmpty(runTestsResults.getFailedTests())) {
            printBuildFailureSummary(projectPath, runTestsResults, loggingService);
        } else {
            printBuildSuccessSummary(contentPath, buildResults, runTestsResults, loggingService);
        }
        loggingService.waitForAllLogTasksToFinish();

        generateTestCaseReport(context.getBean(SlangTestCaseRunReportGeneratorService.class), runTestsResults,
                testCaseReportLocation);
        System.exit(isNotEmpty(runTestsResults.getFailedTests()) ? 1 : 0);

    } catch (Throwable e) {
        logErrorsPrefix(loggingService);
        loggingService.logEvent(Level.ERROR, "Exception: " + e.getMessage());
        logErrorsSuffix(projectPath, loggingService);
        loggingService.waitForAllLogTasksToFinish();
        System.exit(1);
    }
}

From source file:com.cnten.platform.util.FileUtil.java

public static void createDir(String dirPath) {
    if (StringUtils.isEmpty(dirPath)) {
        return;/*from  w ww. j  a  va2 s.  c  o  m*/
    }
    File file = new File(dirPath);
    if (!file.exists()) {
        file.setWritable(true, false);//linux java ???
        file.mkdirs();
    }
}

From source file:net.mamian.mySpringboot.utils.ShellUtils.java

/**
 * /*w ww  .j  av a 2 s.  c  o  m*/
 * 
 * @param shPath shell
 * @param param ?
 * @return 
 */
public static int exe(String shPath, String... param) {
    if (StringUtils.isEmpty(shPath)) {
        log.info("shell?shpath={}", shPath);
        return -1;
    }
    Process p;
    try {
        shPath = "chmod 755 " + shPath;
        if (null != param) {
            for (String paramItem : param) {
                shPath += " " + paramItem;
            }
        }
        log.info("shellshpath={}", shPath);
        p = Runtime.getRuntime().exec(shPath);
        p.waitFor();
        log.info("shellshpath={}", shPath);
    } catch (IOException | InterruptedException ex) {
        log.info("shellshpath={} exception={}", shPath, ex);
        return -1;
    }
    return 0;
}

From source file:badminton.common.Util.StringUtil.java

/**
 * <p>//  ww w  .  j a  va 2s .  co m
 * Checks if a String is empty ("") or null.
 * </p>
 *
 * @param str
 *            the String to check, may be null
 * @return <code>true</code> if the String is empty or null
 */
public static boolean isEmpty(final String str) {
    return StringUtils.isEmpty(str);
}

From source file:com.deploymentio.cfnstacker.template.VelocityUtil.java

public static String valueOrDefault(Object val, String defaultVal) {
    if (val == null || ((val instanceof String) && StringUtils.isEmpty((String) val))) {
        return defaultVal;
    }/*from   w w  w .j  av  a2  s  .  c  o  m*/
    return val.toString();
}

From source file:de.micromata.genome.gwiki.page.gspt.BeanTools.java

public static String propertyToGetterMethod(String prop) {
    if (StringUtils.isEmpty(prop) == true)
        return "";
    return "get" + prop.substring(0, 1).toUpperCase() + prop.substring(1) + "()";
}

From source file:com.sixwonders.courtkiosk.CitationAdapter.java

public static ArrayList<Citation> adaptCitationData(ArrayList<JSONObject> jsonObjects) {
    ArrayList<Citation> citations = new ArrayList<Citation>();
    try {/*from  ww w. jav  a  2  s.c  o  m*/
        for (JSONObject jsonObject : jsonObjects) {
            Citation citation = new Citation();
            //id,,,,,date_of_birth,defendant_address,defendant_city,defendant_state,drivers_license_number,court_date,court_location,court_address
            if (jsonObject.getInt("citation_number") != 0) {
                citation.setCitation_number(jsonObject.getInt("citation_number"));
            }
            if (!StringUtils.isEmpty(jsonObject.get("citation_date").toString())) {
                citation.setCitation_date(StringUtils.split(jsonObject.getString("citation_date"), ' ')[0]);
            }
            if (!StringUtils.isEmpty(jsonObject.get("first_name").toString())) {
                citation.setFirst_name(jsonObject.getString("first_name"));
            }
            if (!StringUtils.isEmpty(jsonObject.get("last_name").toString())) {
                citation.setFirst_name(jsonObject.getString("last_name"));
            }
            if (!StringUtils.isEmpty(jsonObject.get("court_location").toString())) {
                citation.setCourt_location(jsonObject.getString("court_location"));
            }
            citations.add(citation);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return citations;
}

From source file:com.mb.framework.util.StringUtil.java

/**
 * This method is used for checking whether string is empty
 * //from  w  ww  .j a  v  a 2  s.c  o  m
 * @param str
 * @return
 */
public static boolean isEmtpy(String str) {
    return StringUtils.isEmpty(str);
}