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

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

Introduction

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

Prototype

public static boolean isEmpty(String str) 

Source Link

Document

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

Usage

From source file:com.mmj.app.common.core.lang.ArrayUtils.java

public static void main(String[] args) {
    String[] s = { "zxc", null, "", "" };
    s = ArrayUtils.replaceNullElement(s, new IHandle<String>() {

        @Override/* w  ww  .j  a  va  2 s. com*/
        public boolean isNull(String obj) {
            return obj == null || StringUtils.isEmpty((String) obj);
        }

        @Override
        public String init(Class<String> clazz) {
            if (clazz.equals(String.class)) {
                return (String) new String("wu");
            }
            try {
                return clazz.newInstance();
            } catch (InstantiationException e) {
                System.out.println(e.getMessage());
            } catch (IllegalAccessException e) {
                System.out.println(e.getMessage());
            }
            System.out.println("replaceNullElement: init error");
            return null;
        }
    });
    System.out.println(StringUtils.join(s, ";"));

    String[] a = removeBlankElement(new String[] { "1", null, "2", "", "3" });
    for (int i = 0, j = a.length; i < j; i++) {
        System.out.println(a[i]);
    }

    String[] t = null;
    System.out.println("Orignal:" + org.apache.commons.lang.ArrayUtils.toString(t, "NULL"));
    System.out.println("shift:" + org.apache.commons.lang.ArrayUtils.toString(shift(t, "a"), "NULL"));
    System.out.println("unshift:" + org.apache.commons.lang.ArrayUtils.toString(unshift(t, "a"), "NULL"));
    System.out.println("add(-1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, -1, "a"), "NULL"));
    System.out.println("add(0):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length+1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 1, "a"), "NULL"));
    t = new String[] { "1", null, "2", "", "3" };
    System.out.println("Orignal:" + org.apache.commons.lang.ArrayUtils.toString(t, "NULL"));
    System.out.println("shift:" + org.apache.commons.lang.ArrayUtils.toString(shift(t, "a"), "NULL"));
    System.out.println("unshift:" + org.apache.commons.lang.ArrayUtils.toString(unshift(t, "a"), "NULL"));
    System.out.println("add(-1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, -1, "a"), "NULL"));
    System.out.println("add(0):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length+1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 1, "a"), "NULL"));
}

From source file:com.zb.app.common.core.lang.ArrayUtils.java

public static void main(String[] args) {
    String[] s = { "zxc", null, "zuobian", "" };
    s = ArrayUtils.replaceNullElement(s, new IHandle<String>() {

        @Override/*from w  w w  .j  a  v a  2  s. c  o  m*/
        public boolean isNull(String obj) {
            return obj == null || StringUtils.isEmpty((String) obj);
        }

        @Override
        public String init(Class<String> clazz) {
            if (clazz.equals(String.class)) {
                return (String) new String("wu");
            }
            try {
                return clazz.newInstance();
            } catch (InstantiationException e) {
                System.out.println(e.getMessage());
            } catch (IllegalAccessException e) {
                System.out.println(e.getMessage());
            }
            System.out.println("replaceNullElement: init error");
            return null;
        }
    });
    System.out.println(StringUtils.join(s, ";"));

    String[] a = removeBlankElement(new String[] { "1", null, "2", "", "3" });
    for (int i = 0, j = a.length; i < j; i++) {
        System.out.println(a[i]);
    }

    String[] t = null;
    System.out.println("Orignal:" + org.apache.commons.lang.ArrayUtils.toString(t, "NULL"));
    System.out.println("shift:" + org.apache.commons.lang.ArrayUtils.toString(shift(t, "a"), "NULL"));
    System.out.println("unshift:" + org.apache.commons.lang.ArrayUtils.toString(unshift(t, "a"), "NULL"));
    System.out.println("add(-1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, -1, "a"), "NULL"));
    System.out.println("add(0):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length+1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 1, "a"), "NULL"));
    t = new String[] { "1", null, "2", "", "3" };
    System.out.println("Orignal:" + org.apache.commons.lang.ArrayUtils.toString(t, "NULL"));
    System.out.println("shift:" + org.apache.commons.lang.ArrayUtils.toString(shift(t, "a"), "NULL"));
    System.out.println("unshift:" + org.apache.commons.lang.ArrayUtils.toString(unshift(t, "a"), "NULL"));
    System.out.println("add(-1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, -1, "a"), "NULL"));
    System.out.println("add(0):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length+1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 1, "a"), "NULL"));
}

From source file:com.fengduo.bee.commons.core.lang.ArrayUtils.java

public static void main(String[] args) {
    String[] s = { "zxc", null, "msunmss", "" };
    s = ArrayUtils.replaceNullElement(s, new IHandle<String>() {

        @Override//from   w  ww  . j  av  a 2s .c  om
        public boolean isNull(String obj) {
            return obj == null || StringUtils.isEmpty((String) obj);
        }

        @Override
        public String init(Class<String> clazz) {
            if (clazz.equals(String.class)) {
                return (String) new String("wu");
            }
            try {
                return clazz.newInstance();
            } catch (InstantiationException e) {
                System.out.println(e.getMessage());
            } catch (IllegalAccessException e) {
                System.out.println(e.getMessage());
            }
            System.out.println("replaceNullElement: init error");
            return null;
        }
    });
    System.out.println(StringUtils.join(s, ";"));

    String[] a = removeBlankElement(new String[] { "1", null, "2", "", "3" });
    for (int i = 0, j = a.length; i < j; i++) {
        System.out.println(a[i]);
    }

    String[] t = null;
    System.out.println("Orignal:" + org.apache.commons.lang.ArrayUtils.toString(t, "NULL"));
    System.out.println("shift:" + org.apache.commons.lang.ArrayUtils.toString(shift(t, "a"), "NULL"));
    System.out.println("unshift:" + org.apache.commons.lang.ArrayUtils.toString(unshift(t, "a"), "NULL"));
    System.out.println("add(-1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, -1, "a"), "NULL"));
    System.out.println("add(0):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length+1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 1, "a"), "NULL"));
    t = new String[] { "1", null, "2", "", "3" };
    System.out.println("Orignal:" + org.apache.commons.lang.ArrayUtils.toString(t, "NULL"));
    System.out.println("shift:" + org.apache.commons.lang.ArrayUtils.toString(shift(t, "a"), "NULL"));
    System.out.println("unshift:" + org.apache.commons.lang.ArrayUtils.toString(unshift(t, "a"), "NULL"));
    System.out.println("add(-1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, -1, "a"), "NULL"));
    System.out.println("add(0):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length+1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 1, "a"), "NULL"));
}

From source file:com.cws.esolutions.security.main.UserManagementUtility.java

public static final void main(final String[] args) {
    final String methodName = UserManagementUtility.CNAME + "#main(final String[] args)";

    if (DEBUG) {//from w w w.  ja  v a  2 s.c  om
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", (Object) args);
    }

    if (args.length == 0) {
        HelpFormatter usage = new HelpFormatter();
        usage.printHelp(UserManagementUtility.CNAME, options, true);

        return;
    }

    try {
        CommandLineParser parser = new PosixParser();
        CommandLine commandLine = parser.parse(options, args);

        if (DEBUG) {
            DEBUGGER.debug("CommandLineParser parser: {}", parser);
            DEBUGGER.debug("CommandLine commandLine: {}", commandLine);
            DEBUGGER.debug("CommandLine commandLine.getOptions(): {}", (Object[]) commandLine.getOptions());
            DEBUGGER.debug("CommandLine commandLine.getArgList(): {}", commandLine.getArgList());
        }

        if ((commandLine.hasOption("configFile"))
                && (!(StringUtils.isBlank(commandLine.getOptionValue("configFile"))))) {
            SecurityServiceInitializer.initializeService(commandLine.getOptionValue("configFile"),
                    UserManagementUtility.LOG_CONFIG, true);
        } else {
            SecurityServiceInitializer.initializeService(UserManagementUtility.SEC_CONFIG,
                    UserManagementUtility.LOG_CONFIG, true);
        }

        AccountControlResponse response = null;

        final UserAccount userAccount = new UserAccount();
        final RequestHostInfo reqInfo = new RequestHostInfo();
        final SecurityConfigurationData secConfigData = UserManagementUtility.svcBean.getConfigData();
        final SecurityConfig secConfig = secConfigData.getSecurityConfig();

        try {
            reqInfo.setHostAddress(InetAddress.getLocalHost().getHostAddress());
            reqInfo.setHostName(InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException uhx) {
            reqInfo.setHostAddress("127.0.0.1");
            reqInfo.setHostName("localhost");
        }

        if (DEBUG) {
            DEBUGGER.debug("SecurityConfigurationData secConfig: {}", secConfigData);
            DEBUGGER.debug("SecurityConfig secConfig: {}", secConfig);
            DEBUGGER.debug("RequestHostInfo reqInfo: {}", reqInfo);
        }

        AccountControlRequest request = new AccountControlRequest();
        request.setApplicationId(secConfig.getApplicationId());
        request.setApplicationName(secConfig.getApplicationName());
        request.setHostInfo(reqInfo);
        request.setRequestor(secConfig.getSvcAccount());

        if (DEBUG) {
            DEBUGGER.debug("AccountControlRequest request: {}", request);
        }

        if (commandLine.hasOption("search")) {
            if (StringUtils.isEmpty(commandLine.getOptionValue("search"))) {
                throw new ParseException("No entry option was provided. Cannot continue.");
            }

            userAccount.setEmailAddr(commandLine.getOptionValue("search"));

            if (DEBUG) {
                DEBUGGER.debug("UserAccount userAccount: {}", userAccount);
            }

            request.setUserAccount(userAccount);

            if (DEBUG) {
                DEBUGGER.debug("AccountControlRequest: {}", request);
            }

            response = processor.searchAccounts(request);
        } else if (commandLine.hasOption("load")) {
            if (StringUtils.isEmpty(commandLine.getOptionValue("load"))) {
                throw new ParseException("No entry option was provided. Cannot continue.");
            }

            userAccount.setGuid(commandLine.getOptionValue("load"));

            request.setUserAccount(userAccount);

            if (DEBUG) {
                DEBUGGER.debug("AccountControlRequest: {}", request);
            }

            response = processor.loadUserAccount(request);
        }

        if (DEBUG) {
            DEBUGGER.debug("AccountControlResponse response: {}", response);
        }

        if ((response != null) && (response.getRequestStatus() == SecurityRequestStatus.SUCCESS)) {
            UserAccount account = response.getUserAccount();

            if (DEBUG) {
                DEBUGGER.debug("UserAccount: {}", account);
            }

            System.out.println(account);
        }
    } catch (ParseException px) {
        ERROR_RECORDER.error(px.getMessage(), px);

        System.err.println("An error occurred during processing: " + px.getMessage());
    } catch (SecurityException sx) {
        ERROR_RECORDER.error(sx.getMessage(), sx);

        System.err.println("An error occurred during processing: " + sx.getMessage());
    } catch (SecurityServiceException ssx) {
        ERROR_RECORDER.error(ssx.getMessage(), ssx);

        System.err.println("An error occurred during processing: " + ssx.getMessage());
    }
}

From source file:io.sightly.tck.TCK.java

public static void main(String[] args) {

    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt(CLI_EXTRACT).withDescription(CLI_EXTRACT_DESCRIPTION)
            .hasOptionalArg().withArgName("DIR").create());
    options.addOption(OptionBuilder.withLongOpt(CLI_URL).withDescription(CLI_URL_DESCRIPTION).hasOptionalArg()
            .withArgName("URL").create());
    options.addOption(OptionBuilder.withLongOpt(CLI_AUTH_USER).withDescription(CLI_AUTH_USER_DESCRIPTION)
            .hasOptionalArg().withArgName("USER").create());
    options.addOption(OptionBuilder.withLongOpt(CLI_AUTH_PASS).withDescription(CLI_AUTH_PASS_DESCRIPTION)
            .hasOptionalArg().withArgName("PASS").create());
    try {/* w w w  . j a  v a 2 s  .  c  om*/
        CommandLine line = parser.parse(options, args);
        if (!line.iterator().hasNext()) {
            printUsage(options);
            die();
        } else if (line.hasOption(CLI_EXTRACT)) {
            String extractDir = line.getOptionValue(CLI_EXTRACT);
            if (StringUtils.isEmpty(extractDir)) {
                // assume user wants to extract stuff in current directory
                extractDir = System.getProperty("user.dir");
            }
            INSTANCE.extract(extractDir);
            LOG.info("Extracted testing resources in folder {}.", extractDir + File.separator + TESTFILES);
        } else {
            if (line.hasOption(CLI_URL)) {
                String url = line.getOptionValue(CLI_URL);
                if (StringUtils.isEmpty(url)) {
                    LOG.error("Missing value for --" + CLI_URL + " command line option.");
                    printUsage(options);
                    die();
                }
                System.setProperty(Constants.SYS_PROP_SERVER_URL, url);
            }
            if (line.hasOption(CLI_AUTH_USER) || line.hasOption(CLI_AUTH_PASS)) {
                String user = line.getOptionValue(CLI_AUTH_USER);
                if (StringUtils.isEmpty(user)) {
                    LOG.error("Missing value for --" + CLI_AUTH_USER + " command line option");
                    printUsage(options);
                    die();
                }
                String pass = line.getOptionValue(CLI_AUTH_PASS);
                if (StringUtils.isEmpty(pass)) {
                    LOG.error("Missing value for --" + CLI_AUTH_PASS + " command line option");
                    printUsage(options);
                    die();
                }
                System.setProperty(Constants.SYS_PROP_USER, user);
                System.setProperty(Constants.SYS_PROP_PASS, pass);
            }
            INSTANCE.run();
        }

    } catch (ParseException e) {
        printUsage(options);
        die();
    } catch (IOException e) {
        LOG.error("IO Error.", e);
        die();
    }
}

From source file:com.cy.common.util.ValidateUtil.java

/**
 * ????/*from  w ww . jav a 2s  .  co m*/
 * @return false:?; true:
 * */
public static boolean validateTelePhone(String telephone) {
    if (StringUtils.isEmpty(telephone)) {
        return false;
    }
    Pattern pattern = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$");
    Matcher macher = pattern.matcher(telephone);
    return macher.matches();
}

From source file:com.cy.driver.common.util.ValidateUtil.java

/**
 * ????/*from   w w w. j av a 2s .  c o  m*/
 * @return false:?; true:
 * */
public static boolean validateTelePhone(String telephone) {
    if (StringUtils.isEmpty(telephone)) {
        return false;
    }
    String regx = "^((13[0-9])|(15[^4,\\D])|(18[0-9])|(17[0-9])|(14[0-9]))\\d{8}$";
    Pattern pattern = Pattern.compile(regx);
    Matcher macher = pattern.matcher(telephone);
    return macher.matches();
}

From source file:com.bstek.dorado.idesupport.StandaloneRuleSetExporter.java

public static void main(String[] args) throws Exception {
    String ruleSetFile = null;//from   w  w w.j av  a 2  s  .c  om
    String doradoHome = null;
    if (args.length >= 2) {
        ruleSetFile = args[0];
        doradoHome = args[1];
    } else {
        throw new IllegalArgumentException();
    }

    if (StringUtils.isEmpty(doradoHome)) {
        doradoHome = System.getenv("DORADO_HOME");
    }

    StandaloneRuleSetExporter instance = new StandaloneRuleSetExporter(doradoHome);

    FileOutputStream fos = new FileOutputStream(ruleSetFile);
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(fos, Constants.DEFAULT_CHARSET));
    try {
        instance.exportRuleSet(writer);
    } finally {
        writer.flush();
        writer.close();
        fos.close();
    }
}

From source file:com.enonic.cms.business.core.content.ContentNameValidator.java

public static void validate(String contentName) {
    if (StringUtils.isEmpty(contentName)) {
        throw new ContentNameValidatorException("Content name cannot be empty");
    }/*  w  w  w .j  a  va  2  s  .  c om*/

    if (StringUtils.startsWith(contentName, " ") || StringUtils.endsWith(contentName, " ")) {
        throw new ContentNameValidatorException("Content name cannot start or end with whitespace");
    }

    if (StringUtils.containsAny(contentName, FORBIDDEN_CHARS)) {
        throw new ContentNameValidatorException(
                "Content name cannot contain any of these characters: " + FORBIDDEN_CHARS);
    }

    if (contentName.length() > CONTENT_NAME_MAX_LENGTH) {
        throw new ContentNameValidatorException("Content name is too long: " + contentName.length()
                + " . Maximum length is " + CONTENT_NAME_MAX_LENGTH + " characters.");
    }
}

From source file:com.clican.pluto.common.util.TimeUtils.java

/**
 * ???//  ww  w .  j  a  va  2s .co  m
 * 
 * @param expr
 * @return
 */
public static long getMillisionSecond(String expr) {
    if (StringUtils.isEmpty(expr)) {
        return -1;
    }
    if (expr.endsWith("ms")) {
        return Long.parseLong(expr.replaceAll(expr, "ms"));
    } else if (expr.endsWith("sec")) {
        expr = expr.replaceAll("sec", "");
        return Long.parseLong(expr) * 1000;
    } else if (expr.endsWith("min")) {
        expr = expr.replaceAll("min", "");
        return Long.parseLong(expr) * 1000 * 60;
    } else if (expr.endsWith("hour")) {
        expr = expr.replaceAll("hour", "");
        return Long.parseLong(expr) * 1000 * 60 * 60;
    } else if (expr.endsWith("day")) {
        expr = expr.replaceAll("day", "");
        return Long.parseLong(expr) * 1000 * 60 * 60 * 24;
    } else if (expr.endsWith("week")) {
        expr = expr.replaceAll("week", "");
        return Long.parseLong(expr) * 1000 * 60 * 60 * 24 * 7;
    } else if (expr.endsWith("month")) {
        expr = expr.replaceAll("month", "");
        return Long.parseLong(expr) * 1000 * 60 * 60 * 24 * 30;
    } else {
        throw new IllegalArgumentException("illegal expression arg");
    }
}