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.qwazr.utils.Language.java

/**
 * Try to detect the language of a given text.
 * //w w  w.ja v a2s .c  om
 * @param text
 *            the text to identify
 * @param length
 *            the number of characters used for the language detection
 * @return the code of the detected language
 * @throws LangDetectException
 *             from langDetect package
 */
public static final String detect(String text, int length) throws LangDetectException {
    if (StringUtils.isEmpty(text))
        return null;
    Detector detector = DetectorFactory.create();
    detector.setMaxTextLength(length);
    detector.append(text);
    return detector.detect();
}

From source file:com.shenit.commons.codec.Base64Utils.java

/**
 * ?base 64?// w ww . j a  va  2 s  .  c om
 * 
 * @param str
 * @param enc
 * @return
 */
public static String base64EncodeHex(String str, String enc) {
    if (StringUtils.isEmpty(str))
        return null;
    enc = enc == null ? HttpUtils.ENC_UTF8 : enc;
    try {
        byte[] encoded = Base64.encodeBase64(str.getBytes(enc));
        return new String(encoded, enc);
    } catch (UnsupportedEncodingException e) {
        LOG.warn("[base64Encode] not supported encoding", e);
    }
    return null;
}

From source file:com.micromux.cassandra.jdbc.MetadataResultSetsTest.java

@BeforeClass
public static void setUpBeforeClass() throws Exception {

    // configure OPTIONS
    if (!StringUtils.isEmpty(TRUST_STORE)) {
        OPTIONS = String.format("trustStore=%s&trustPass=%s", URLEncoder.encode(TRUST_STORE), TRUST_PASS);
    }/*from w  w w . j  a  v  a 2  s.  c om*/

    Class.forName("com.micromux.cassandra.jdbc.CassandraDriver");
    String URL = String.format("jdbc:cassandra://%s:%d/%s?version=3.0.0&%s", HOST, PORT, "system", OPTIONS);
    System.out.println("Connection URL = '" + URL + "'");

    con = DriverManager.getConnection(URL);
    Statement stmt = con.createStatement();

    // Drop Keyspace
    String dropKS1 = String.format(DROP_KS, KEYSPACE1);
    String dropKS2 = String.format(DROP_KS, KEYSPACE2);

    try {
        stmt.execute(dropKS1);
        stmt.execute(dropKS2);
    } catch (Exception e) {
        /* Exception on DROP is OK */}

    // Create KeySpace
    String createKS1 = String.format(CREATE_KS, KEYSPACE1);
    String createKS2 = String.format(CREATE_KS, KEYSPACE2);
    stmt = con.createStatement();
    stmt.execute("USE system;");
    stmt.execute(createKS1);
    stmt.execute(createKS2);

    // Use Keyspace
    String useKS1 = String.format("USE \"%s\";", KEYSPACE1);
    String useKS2 = String.format("USE \"%s\";", KEYSPACE2);
    stmt.execute(useKS1);

    // Create the target Column family
    String createCF1 = "CREATE COLUMNFAMILY test1 (keyname text PRIMARY KEY," + " t1bValue boolean,"
            + " t1iValue int" + ") WITH comment = 'first TABLE in the Keyspace'" + ";";

    String createCF2 = "CREATE COLUMNFAMILY test2 (keyname text PRIMARY KEY," + " t2bValue boolean,"
            + " t2iValue int" + ") WITH comment = 'second TABLE in the Keyspace'" + ";";

    stmt.execute(createCF1);
    stmt.execute(createCF2);
    stmt.execute(useKS2);
    stmt.execute(createCF1);
    stmt.execute(createCF2);

    stmt.close();
    con.close();

    // open it up again to see the new CF
    con = DriverManager.getConnection(
            String.format("jdbc:cassandra://%s:%d/%s?version=3.0.0&%s", HOST, PORT, KEYSPACE1, OPTIONS));

}

From source file:com.github.hackersun.processor.factory.FactoryAnnotatedClass.java

/**
 * @throws ProcessingException if id() from annotation is null
 *//*from   w ww. j  a v  a  2 s.c  o  m*/
public FactoryAnnotatedClass(TypeElement classElement) throws ProcessingException {
    this.annotatedClassElement = classElement;
    Factory annotation = classElement.getAnnotation(Factory.class);
    id = annotation.id();

    if (StringUtils.isEmpty(id)) {
        throw new ProcessingException(classElement,
                "id() in @%s for class %s is null or empty! that's not allowed", Factory.class.getSimpleName(),
                classElement.getQualifiedName().toString());
    }

    // Get the full QualifiedTypeName
    try {
        Class<?> clazz = annotation.type();
        qualifiedGroupClassName = clazz.getCanonicalName();
        simpleFactoryGroupName = clazz.getSimpleName();
    } catch (MirroredTypeException mte) {
        DeclaredType classTypeMirror = (DeclaredType) mte.getTypeMirror();
        TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement();
        qualifiedGroupClassName = classTypeElement.getQualifiedName().toString();
        simpleFactoryGroupName = classTypeElement.getSimpleName().toString();
    }
}

From source file:lineage2.gameserver.network.clientpackets.RequestExDeletePostFriendForPostBox.java

/**
 * Method runImpl./*  w ww. j a  va2 s .c o  m*/
 */
@Override
protected void runImpl() {
    Player player = getClient().getActiveChar();
    if (player == null) {
        return;
    }
    if (StringUtils.isEmpty(_name)) {
        return;
    }
    int key = 0;
    IntObjectMap<String> postFriends = player.getPostFriends();
    for (IntObjectMap.Entry<String> entry : postFriends.entrySet()) {
        if (entry.getValue().equalsIgnoreCase(_name)) {
            key = entry.getKey();
        }
    }
    if (key == 0) {
        player.sendPacket(SystemMsg.THE_NAME_IS_NOT_CURRENTLY_REGISTERED);
        return;
    }
    player.getPostFriends().remove(key);
    CharacterPostFriendDAO.getInstance().delete(player, key);
    player.sendPacket(
            new SystemMessage2(SystemMsg.S1_WAS_SUCCESSFULLY_DELETED_FROM_YOUR_CONTACT_LIST).addString(_name));
}

From source file:com.baifendian.swordfish.common.mail.MailSendUtil.java

/**
 * ??//www . j a v  a  2s  . c om
 *
 * @param receivers
 * @param title
 * @param content
 * @return
 */
public static boolean sendMails(Collection<String> receivers, String title, String content) {
    if (receivers == null) {
        LOGGER.error("Mail receivers is null.");
        return false;
    }

    receivers.removeIf((from) -> (StringUtils.isEmpty(from)));

    if (receivers.isEmpty()) {
        LOGGER.error("Mail receivers is empty.");
        return false;
    }

    // ?? email
    HtmlEmail email = new HtmlEmail();

    try {
        //  SMTP ?????, 163 "smtp.163.com"
        email.setHostName(mailServerHost);

        email.setSmtpPort(mailServerPort);

        // ?
        email.setCharset("UTF-8");
        // 
        for (String receiver : receivers) {
            email.addTo(receiver);
        }
        // ??
        email.setFrom(mailSender, mailSender);
        // ???????-??????
        email.setAuthentication(mailSender, mailPasswd);
        // ???
        email.setSubject(title);
        // ???? HtmlEmail? HTML 
        email.setMsg(content);
        // ??
        email.send();

        return true;
    } catch (Throwable e) {
        LOGGER.error("Send email to {} failed", StringUtils.join(",", receivers), e);
    }

    return false;
}

From source file:com.esri.geoevent.test.performance.utils.KryoUtils.java

public static <T> T fromString(String data, Class<T> type) {
    if (StringUtils.isEmpty(data))
        return null;

    Kryo kryo = setupKryo();/*w ww .java  2  s  . co  m*/
    Input input = new Input(new ByteArrayInputStream(Base64.decodeBase64(data)));
    T returnObj = kryo.readObject(input, type);
    input.close();
    return returnObj;
}

From source file:com.thruzero.common.jsf.renderer.html5.helper.TzInputTypeResponseWriter.java

public TzInputTypeResponseWriter(ResponseWriter delegate, UIComponent component, Renderer renderer,
        String defaultType) {/*ww w. j  av a  2 s.  c o  m*/
    super(delegate, renderer);

    type = (String) component.getAttributes().get("type");

    if (StringUtils.isEmpty(type) && StringUtils.isNotEmpty(defaultType)) {
        type = defaultType;
    }
}

From source file:de.thomasvolk.genexample.model.AbstractPassagierFactory.java

protected int getWertung(String inEingabe) {
    String eingabe = inEingabe.trim();
    if (StringUtils.isEmpty(eingabe)) {
        return Wertung.NULL_GEWICHTUNG;
    }//w ww. j a va2  s.  c  o  m
    try {
        return Integer.valueOf(eingabe);
    } catch (NumberFormatException e) {
        int anzahl = eingabe.length();
        return Wertung.EINFACHE_GEWICHTUNG * anzahl;
    }
}

From source file:gov.nih.nci.caintegrator.external.caarray.CaArrayServiceFactoryImpl.java

private CaArrayServer connect(ServerConnectionProfile profile) throws ConnectionException {
    CaArrayServer server = new CaArrayServer(profile.getHostname(), profile.getPort());
    try {/*from   w  ww .j  av a  2  s . c  o m*/
        if (StringUtils.isEmpty(profile.getUsername())) {
            server.connect();
        } else {
            server.connect(profile.getUsername(), profile.getPassword());
        }
    } catch (FailedLoginException e) {
        throw new ConnectionException("Login to the specified server failed", e);
    } catch (ServerConnectionException e) {
        throw new ConnectionException("Couldn't connect to the specified server", e);
    } catch (EJBException e) {
        /**
         * For some reason (possibly related to differences in java versions between caArray
         * and caIntegrator, EJBAccessExceptions are only being caught by the generic EJBException (see CAINT-1197).
         */
        throw new ConnectionException("Login to the specified server failed", e);
    }
    return server;
}