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

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

Introduction

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

Prototype

public static boolean isNotBlank(final CharSequence cs) 

Source Link

Document

Checks if a CharSequence is not empty (""), not null and not whitespace only.

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

Usage

From source file:com.omertron.themoviedbapi.enumeration.TVSeasonMethod.java

/**
 * Convert a string into an Enum type/* www.ja  va 2s  .c om*/
 *
 * @param method
 * @return
 * @throws IllegalArgumentException If type is not recognised
 *
 */
public static TVSeasonMethod fromString(String method) {
    if (StringUtils.isNotBlank(method)) {
        try {
            return TVSeasonMethod.valueOf(method.trim().toUpperCase());
        } catch (IllegalArgumentException ex) {
            throw new IllegalArgumentException("Method " + method + " does not exist.", ex);
        }
    }
    throw new IllegalArgumentException("Method must not be null");
}

From source file:com.omertron.themoviedbapi.enumeration.TVEpisodeMethod.java

/**
 * Convert a string into an Enum type/*from  w w  w. j a  v a  2 s. c o  m*/
 *
 * @param method
 * @return
 * @throws IllegalArgumentException If type is not recognised
 *
 */
public static TVEpisodeMethod fromString(String method) {
    if (StringUtils.isNotBlank(method)) {
        try {
            return TVEpisodeMethod.valueOf(method.trim().toUpperCase());
        } catch (IllegalArgumentException ex) {
            throw new IllegalArgumentException("Method " + method + " does not exist.", ex);
        }
    }
    throw new IllegalArgumentException("Method must not be null");
}

From source file:com.netflix.genie.common.model.JobStatus.java

/**
 * Parse job status./*from   w  ww .j  a v a 2 s .  c om*/
 *
 * @param value string to parse/convert
 * @return INIT, RUNNING, SUCCEEDED, KILLED, FAILED if match
 * @throws GeniePreconditionException if invalid value passed in
 */
public static JobStatus parse(final String value) throws GeniePreconditionException {
    if (StringUtils.isNotBlank(value)) {
        for (final JobStatus status : JobStatus.values()) {
            if (value.equalsIgnoreCase(status.toString())) {
                return status;
            }
        }
    }
    throw new GeniePreconditionException(
            "Unacceptable job status. Must be one of {Init, Running, Succeeded, Killed, Failed}");
}

From source file:com.omertron.bgg.enums.LinkType.java

/**
 * Convert a string into an Enum type/*w  w w.ja  va  2s . co m*/
 *
 * @param source String representation of the enum to convert
 * @return The enum that matches the source
 * @throws IllegalArgumentException If type is not recognised
 */
public static LinkType fromString(String source) {
    if (StringUtils.isNotBlank(source)) {
        try {
            return LinkType.valueOf(source.trim().toUpperCase());
        } catch (IllegalArgumentException ex) {
            throw new IllegalArgumentException("LinkType " + source + " does not exist.", ex);
        }
    }
    throw new IllegalArgumentException("LinkType must not be null");
}

From source file:com.ericsson.eiffel.remrem.publish.helper.PublishUtils.java

/**
 * Method returns the MsgService based on the mp(message protocol) from the list of MsgService beans. 
 * @param mp(message protocol) Specifies which service we consider from the list of MsgService beans
 * @param msgServices List of msgService beans or instances
 * @return msgService or null if message service not available.
 *//*  www.  jav  a  2  s .  com*/
public static MsgService getMessageService(String mp, MsgService msgServices[]) {
    if (StringUtils.isNotBlank(mp)) {
        for (MsgService service : msgServices) {
            if (service.getServiceName().equals(mp)) {
                return service;
            }
        }
    } else {
        for (MsgService service : msgServices) {
            //if (service instanceof SemanticsService) {
            return service;
            // }
        }
    }
    log.error("No protocol service has been found registered.");
    return null;
}

From source file:com.goodhuddle.huddle.repository.TagSpecification.java

public static Specification<Tag> search(final Huddle huddle, final SearchTagsRequest request) {
    return new Specification<Tag>() {
        @Override/*from  w  ww. ja va  2 s  .c  om*/
        public Predicate toPredicate(Root<Tag> tag, CriteriaQuery<?> query, CriteriaBuilder builder) {

            Predicate conjunction = builder.conjunction();
            conjunction.getExpressions().add(builder.equal(tag.get("huddle"), huddle));

            if (StringUtils.isNotBlank(request.getName())) {
                String nameTerm = "%" + request.getName().toLowerCase() + "%";
                conjunction.getExpressions()
                        .add(builder.like(builder.lower(tag.<String>get("name")), nameTerm));
            }

            return conjunction;
        }
    };
}

From source file:com.goodhuddle.huddle.repository.BlogPostSpecification.java

public static Specification<BlogPost> search(final Huddle huddle, final SearchBlogPostRequest request) {
    return new Specification<BlogPost>() {
        @Override/* w  w w . ja  v a  2s .  co  m*/
        public Predicate toPredicate(Root<BlogPost> blogPost, CriteriaQuery<?> query, CriteriaBuilder builder) {

            Predicate conjunction = builder.conjunction();
            conjunction.getExpressions().add(builder.equal(blogPost.get("huddle"), huddle));

            if (StringUtils.isNotBlank(request.getPhrase())) {
                String phrase = "%" + request.getPhrase().toLowerCase() + "%";
                conjunction.getExpressions()
                        .add(builder.like(builder.lower(blogPost.<String>get("title")), phrase));
            }

            if (CollectionUtils.isNotEmpty(request.getBlogIds())) {
                Join<Object, Object> blog = blogPost.join("blog");
                conjunction.getExpressions().add(builder.in(blog.get("id")).value(request.getBlogIds()));
            }

            if (!request.isIncludeUnpublished()) {
                conjunction.getExpressions()
                        .add(builder.lessThan((Expression) blogPost.get("publishedOn"), new DateTime()));
            }

            return conjunction;
        }
    };
}

From source file:com.moviejukebox.model.artwork.ArtworkType.java

/**
 * Convert a string into an Enum type/*w  ww . ja  va2s  .  c  o  m*/
 *
 * @param artworkTypeString
 * @return
 * @throws IllegalArgumentException If type is not recognised
 *
 */
public static ArtworkType fromString(String artworkTypeString) {
    if (StringUtils.isNotBlank(artworkTypeString)) {
        try {
            return ArtworkType.valueOf(artworkTypeString.trim().toUpperCase());
        } catch (IllegalArgumentException ex) {
            throw new IllegalArgumentException("ArtworkType " + artworkTypeString + " does not exist.", ex);
        }
    }
    // We've not found the type, so raise an exception
    throw new IllegalArgumentException("ArtworkType " + artworkTypeString + " does not exist.");
}

From source file:com.moviejukebox.model.enumerations.WatchedWithExtension.java

/**
 * Convert a string into an Enum type//from  www  .j  a  v  a  2 s  .c om
 *
 * @param extensionString
 * @return
 */
public static WatchedWithExtension fromString(String extensionString) {
    if (StringUtils.isNotBlank(extensionString)) {
        for (final WatchedWithExtension extension : EnumSet.allOf(WatchedWithExtension.class)) {
            if (extensionString.equalsIgnoreCase(extension.type)) {
                return extension;
            }
        }
    }
    // We've not found the type, so return both
    return BOTH;
}

From source file:com.norconex.collector.http.pipeline.importer.HttpImporterPipelineUtil.java

public static void enhanceHTTPHeaders(HttpMetadata metadata) {
    if (StringUtils.isNotBlank(metadata.getString(HttpMetadata.COLLECTOR_CONTENT_TYPE))) {
        return;/*from w w w .  j  av a  2  s.  c  o  m*/
    }

    String contentType = metadata.getString(HttpMetadata.HTTP_CONTENT_TYPE);
    if (StringUtils.isBlank(contentType)) {
        for (String key : metadata.keySet()) {
            if (StringUtils.endsWith(key, HttpMetadata.HTTP_CONTENT_TYPE)) {
                contentType = metadata.getString(key);
            }
        }
    }
    if (StringUtils.isNotBlank(contentType)) {
        String mimeType = contentType.replaceFirst("(.*?)(;.*)", "$1");
        String charset = contentType.replaceFirst("(.*?)(; )(.*)", "$3");
        charset = charset.replaceFirst("(charset=)(.*)", "$2");
        metadata.addString(HttpMetadata.COLLECTOR_CONTENT_TYPE, mimeType);
        metadata.addString(HttpMetadata.COLLECTOR_CONTENT_ENCODING, charset);
    }
}