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:minor.login.AddPortfolio.java

@Override
public void validate() {
    if (StringUtils.isEmpty(getQuantity())) {
        addFieldError("quantity", "Quantity cannot be blank.");
    }/*w  w w .  j a va 2 s  .c o m*/
    if (StringUtils.isEmpty(getBuy_price())) {
        addFieldError("buy_price", "Buy Price cannot be blank.");
    }
}

From source file:com.arcanix.php.phar.DirectoryPharEntryProvider.java

public DirectoryPharEntryProvider(final File directory, final String localPath,
        final PharCompression pharCompression) {
    if (directory == null) {
        throw new IllegalArgumentException("Directory cannot be null");
    }//from  ww  w .j av  a 2 s  . c  o  m
    if (!directory.isDirectory()) {
        throw new IllegalArgumentException("Directory must be a valid directory");
    }
    if (StringUtils.isEmpty(localPath)) {
        throw new IllegalArgumentException("Local path cannot be empty");
    }
    if (pharCompression == null) {
        throw new IllegalArgumentException("Phar compression cannot be null");
    }
    this.rootPath = directory.toPath();
    this.localPath = localPath;
    this.pharCompression = pharCompression;
}

From source file:com.esofthead.mycollab.core.utils.DateTimeUtils.java

public static Date convertDateByString(String strDate, String format) {
    if (!StringUtils.isEmpty(strDate)) {
        try {//w  w w .j  a v  a2  s  .  c  om
            SimpleDateFormat formatter = new SimpleDateFormat(format);
            return formatter.parse(strDate);
        } catch (ParseException e) {
            LOG.error("Error while parse date", e);
        }
    }
    return new Date();
}

From source file:com.linkedin.urls.detection.CharUtils.java

/**
 * Splits a string without the use of a regex, which could split either by isDot() or %2e
 * @param input the input string that will be split by dot
 * @return an array of strings that is a partition of the original string split by dot
 *//*from  ww  w .j a  va  2s.  c o m*/
public static String[] splitByDot(String input) {
    ArrayList<String> splitList = new ArrayList<String>();
    StringBuilder section = new StringBuilder();
    if (StringUtils.isEmpty(input)) {
        return new String[] { "" };
    }
    InputTextReader reader = new InputTextReader(input);
    while (!reader.eof()) {
        char curr = reader.read();
        if (isDot(curr)) {
            splitList.add(section.toString());
            section.setLength(0);
        } else if (curr == '%' && reader.canReadChars(2) && reader.peek(2).equalsIgnoreCase("2e")) {
            reader.read();
            reader.read(); //advance past the 2e
            splitList.add(section.toString());
            section.setLength(0);
        } else {
            section.append(curr);
        }
    }
    splitList.add(section.toString());
    return splitList.toArray(new String[splitList.size()]);
}

From source file:com.adobe.cq.wcm.core.components.internal.Utils.java

/**
 * Given a {@link Page}, this method returns the correct URL, taking into account that the provided {@code page} might provide a
 * vanity URL./*from  www . j  a  va  2s .co m*/
 *
 * @param request the current request, used to determine the server's context path
 * @param page    the page
 * @return the URL of the page identified by the provided {@code path}, or the original {@code path} if this doesn't identify a
 * {@link Page}
 */
@Nonnull
public static String getURL(@Nonnull SlingHttpServletRequest request, @Nonnull Page page) {
    String vanityURL = page.getVanityUrl();
    return StringUtils.isEmpty(vanityURL) ? request.getContextPath() + page.getPath() + ".html"
            : request.getContextPath() + vanityURL;
}

From source file:com.streamsets.pipeline.lib.jdbc.JdbcMetastoreUtil.java

public static LinkedHashMap<String, JdbcTypeInfo> convertRecordToJdbcType(Record record,
        String precisionAttribute, String scaleAttribute, JdbcSchemaWriter schemaWriter)
        throws OnRecordErrorException, JdbcStageCheckedException {
    if (!record.get().getType().isOneOf(Field.Type.MAP, Field.Type.LIST_MAP)) {
        throw new OnRecordErrorException(record, JdbcErrors.JDBC_300, record.getHeader().getSourceId(),
                record.get().getType().toString());
    }//  w  ww  . ja  v  a  2  s .  c om
    LinkedHashMap<String, JdbcTypeInfo> columns = new LinkedHashMap<>();
    Map<String, Field> list = record.get().getValueAsMap();
    for (Map.Entry<String, Field> pair : list.entrySet()) {
        if (StringUtils.isEmpty(pair.getKey())) {
            throw new OnRecordErrorException(record, JdbcErrors.JDBC_301, "Field name is empty");
        }
        String fieldPath = pair.getKey();
        Field currField = pair.getValue();

        // Some types requires special checks or alterations
        JdbcType jdbcType = JdbcType.getJdbcTypeforFieldType(currField.getType());
        JdbcTypeInfo jdbcTypeInfo;
        if (jdbcType == JdbcType.DECIMAL) {
            int precision = resolveScaleOrPrecisionExpression("precision", currField, precisionAttribute,
                    fieldPath);
            int scale = resolveScaleOrPrecisionExpression("scale", currField, scaleAttribute, fieldPath);
            schemaWriter.validateScaleAndPrecision(pair.getKey(), currField, precision, scale);
            jdbcTypeInfo = jdbcType.getSupport().generateJdbcTypeInfoFromRecordField(currField, schemaWriter,
                    precision, scale);
        } else {
            jdbcTypeInfo = jdbcType.getSupport().generateJdbcTypeInfoFromRecordField(currField, schemaWriter);
        }

        columns.put(pair.getKey().toLowerCase(), jdbcTypeInfo);
    }
    return columns;
}

From source file:com.thoughtworks.go.config.MqlCriteria.java

public static boolean isEmpty(Object attributes) {
    return attributes == null || StringUtils.isEmpty((String) ((Map) attributes).get(MQL));
}

From source file:com.aboutdata.web.controller.AvatarsController.java

/**
 * Get download from file-system//ww  w  . j a va  2 s.  co  m
 *
 * @param avatar
 * @param t type png jpg
 * @param v ? v=1
 * @param s
 * @param response {@link HttpServletResponse}
 */
@RequestMapping(value = "/{avatar}", method = RequestMethod.GET)
public void download(@PathVariable("avatar") String avatar, String t, String v, String s,
        HttpServletResponse response) {
    if (StringUtils.isEmpty(s)) {
        File file = new File("/var/avatars/" + avatar + "." + t);
        try {
            FileUtils.copyFile(file, response.getOutputStream());
        } catch (IOException ex) {
            logger.error("error {}", ex);
            response.setHeader("message", "?");
            response.setStatus(404);
        }
    } else {
        File file = new File("/var/avatars/" + avatar + "-" + s + "." + t);
        try {
            FileUtils.copyFile(file, response.getOutputStream());
        } catch (IOException ex) {
            logger.error("error {}", ex);
            response.setHeader("message", "?");
            response.setStatus(404);
        }
    }

}

From source file:cn.guoyukun.spring.jpa.repository.hibernate.type.CollectionToStringUserType.java

@Override
public void setParameterValues(Properties parameters) {
    String separator = (String) parameters.get("separator");
    if (!StringUtils.isEmpty(separator)) {
        this.separator = separator;
    } else {//from ww w  .j a va  2 s.c  o  m
        this.separator = ",";
    }

    String collectionType = (String) parameters.get("collectionType");
    if (!StringUtils.isEmpty(collectionType)) {
        try {
            this.collectionType = Class.forName(collectionType);
        } catch (ClassNotFoundException e) {
            throw new HibernateException(e);
        }
    } else {
        this.collectionType = java.util.ArrayList.class;
    }

    String elementType = (String) parameters.get("elementType");
    if (!StringUtils.isEmpty(elementType)) {
        try {
            this.elementType = Class.forName(elementType);
        } catch (ClassNotFoundException e) {
            throw new HibernateException(e);
        }
    } else {
        this.elementType = Long.TYPE;
    }
}

From source file:com.salesforce.ide.apex.internal.core.tooling.systemcompletions.model.Method.java

@Override
public String getDisplayString() {
    if (StringUtils.isEmpty(name))
        return null;

    StringBuilder sb = new StringBuilder();
    sb.append(name);/*  w w  w. ja v a  2  s.  c  o m*/
    sb.append('(');
    if (parameters != null) {
        sb.append(StringUtils.join(parameters, ","));
    }
    sb.append(')');
    sb.append(" - ");
    sb.append(returnType);
    return sb.toString();
}