Example usage for org.apache.commons.lang3 Validate notEmpty

List of usage examples for org.apache.commons.lang3 Validate notEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang3 Validate notEmpty.

Prototype

public static <T extends CharSequence> T notEmpty(final T chars, final String message, final Object... values) 

Source Link

Document

Validate that the specified argument character sequence is neither null nor a length of zero (no characters); otherwise throwing an exception with the specified message.

Usage

From source file:co.runrightfast.commons.utils.ValidationUtils.java

static void notEmpty(final Collection<?> coll, final String argName) {
    Validate.notEmpty(coll, "%s cannot be empty", argName);
}

From source file:io.github.swagger2markup.internal.utils.TagUtils.java

/**
 * Groups the operations by tag. The key of the Multimap is the tag name.
 * The value of the Multimap is a PathOperation
 *
 * @param allOperations     all operations
 * @param operationOrdering comparator for operations, for a given tag
 * @return Operations grouped by Tag/*from   w ww  . ja  v a2s. c o  m*/
 */
public static Multimap<String, PathOperation> groupOperationsByTag(List<PathOperation> allOperations,
        Comparator<PathOperation> operationOrdering) {

    Multimap<String, PathOperation> operationsGroupedByTag;
    if (operationOrdering == null) {
        operationsGroupedByTag = LinkedHashMultimap.create();
    } else {
        operationsGroupedByTag = MultimapBuilder.linkedHashKeys().treeSetValues(operationOrdering).build();
    }
    for (PathOperation operation : allOperations) {
        List<String> tags = operation.getOperation().getTags();

        Validate.notEmpty(tags, "Can't GroupBy.TAGS. Operation '%s' has no tags", operation);
        for (String tag : tags) {
            if (logger.isDebugEnabled()) {
                logger.debug("Added path operation '{}' to tag '{}'", operation, tag);
            }
            operationsGroupedByTag.put(tag, operation);
        }
    }

    return operationsGroupedByTag;
}

From source file:com.feedzai.fos.common.validation.ValidationUtils.java

/**
 * Gets a <code>String[]</code> from the given configuration.
 *
 * @param configuration the configuration where the parameter lies
 * @param parameterName the name of the parameter
 * @return the <code>String[]</code>
 * @throws IllegalArgumentException if the parameter is empty
 *//*  w  w w  .  ja v  a  2  s  .  c o m*/
@NotEmpty
public static String[] getStringArrayNotEmpty(Configuration configuration, @NotBlank String parameterName) {
    return Validate.notEmpty(configuration.getStringArray(parameterName), NOT_EMPTY, parameterName);
}

From source file:io.github.robwin.swagger2markup.utils.TagUtils.java

/**
 * Groups the operations by tag. The key of the Multimap is the tag name.
 * The value of the Multimap is a PathOperation
 *
 * @param allOperations all operations/* w  ww  . j a v  a 2s . c o m*/
 * @param tagOrdering comparator for tags
 * @param operationOrdering comparator for operations, for a given tag
 * @return Operations grouped by Tag
 */
public static Multimap<String, PathOperation> groupOperationsByTag(Set<PathOperation> allOperations,
        Comparator<String> tagOrdering, Comparator<PathOperation> operationOrdering) {
    MultimapBuilder.MultimapBuilderWithKeys<String> multimapBuilderWithKeys;

    if (tagOrdering == null)
        multimapBuilderWithKeys = MultimapBuilder.SortedSetMultimapBuilder.treeKeys(Ordering.<String>natural()); // FIXME as-is sorting not supported because of limitations in MultiMap::hashkeys(). Replaced with Ordering.natural()
    else
        multimapBuilderWithKeys = MultimapBuilder.SortedSetMultimapBuilder.treeKeys(tagOrdering);

    Multimap<String, PathOperation> operationsGroupedByTag;
    if (operationOrdering == null)
        operationsGroupedByTag = multimapBuilderWithKeys.hashSetValues().build();
    else
        operationsGroupedByTag = multimapBuilderWithKeys.treeSetValues(operationOrdering).build();

    for (PathOperation operation : allOperations) {
        List<String> tags = operation.getOperation().getTags();
        Validate.notEmpty(tags, "Can't GroupBy.TAGS > Operation '%s' has not tags", operation);
        for (String tag : tags) {
            if (LOG.isInfoEnabled()) {
                LOG.info("Added path operation '{}' to tag '{}'", operation, tag);
            }
            operationsGroupedByTag.put(tag, operation);
        }
    }

    return operationsGroupedByTag;
}

From source file:com.premiumminds.billy.core.util.BillyValidator.java

public static <T extends Collection<?>> T notEmpty(T object, String fieldName) {
    Validate.notEmpty(object, BillyValidator.instance.localizer.getString("invalid.empty", fieldName),
            fieldName);//from  ww  w.  j a  v  a2  s  .c om
    return object;
}

From source file:net.community.chest.gitcloud.facade.backend.git.BackendRepositoryResolver.java

@Inject
public BackendRepositoryResolver(@Value(REPOS_BASE_INJECTION_VALUE) String baseDir) {
    this(new File(Validate.notEmpty(baseDir, "No base folder", ArrayUtils.EMPTY_OBJECT_ARRAY)));
}

From source file:edu.sabanciuniv.sentilab.sare.controllers.aspect.AspectLexiconFactory.java

protected AspectLexiconFactory addXmlAspect(AspectLexicon lexicon, Node aspectNode)
        throws XPathExpressionException {

    Validate.notNull(lexicon, CannedMessages.NULL_ARGUMENT, "lexicon");
    Validate.notNull(aspectNode, CannedMessages.NULL_ARGUMENT, "node");

    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();

    // if the node is called "lexicon" then we're at the root, so we won't need to add an aspect and its expressions.
    AspectLexicon aspect = lexicon;/*from   w  w w  . j a  va  2s .  co  m*/
    if (!"aspect-lexicon".equalsIgnoreCase(aspectNode.getLocalName())) {
        String title = Validate.notEmpty(
                (String) xpath.compile("./@title").evaluate(aspectNode, XPathConstants.STRING),
                CannedMessages.EMPTY_ARGUMENT, "./aspect/@title");
        ;

        // fetch or create aspect.
        aspect = lexicon.findAspect(title);
        if (aspect == null) {
            aspect = lexicon.addAspect(title);
        }

        // get all expressions or keywords, whatever they're called.
        NodeList expressionNodes = (NodeList) xpath.compile("./expressions/expression").evaluate(aspectNode,
                XPathConstants.NODESET);
        if (expressionNodes == null || expressionNodes.getLength() == 0) {
            expressionNodes = (NodeList) xpath.compile("./keywords/keyword").evaluate(aspectNode,
                    XPathConstants.NODESET);
        }

        // add each of them if they don't exist.
        if (expressionNodes != null) {
            for (int index = 0; index < expressionNodes.getLength(); index++) {
                String expression = expressionNodes.item(index).getTextContent().trim();
                if (!aspect.hasExpression(expression)) {
                    aspect.addExpression(expression);
                }
            }
        }
    }

    // get all sub-aspects and add them recursively.
    NodeList subAspectNodes = (NodeList) xpath.compile("./aspects/aspect").evaluate(aspectNode,
            XPathConstants.NODESET);
    if (subAspectNodes != null) {
        for (int index = 0; index < subAspectNodes.getLength(); index++) {
            this.addXmlAspect(aspect, subAspectNodes.item(index));
        }
    }

    return this;
}

From source file:cz.jirutka.validator.collection.CommonEachValidator.java

public void initialize(Annotation eachAnnotation) {

    Class<? extends Annotation> eachAType = eachAnnotation.annotationType();
    LOG.trace("Initializing CommonEachValidator for {}", eachAType);

    if (factory == null) {
        LOG.debug("No ValidatorFactory injected, building default one");
        factory = Validation.buildDefaultValidatorFactory();
    }/*from   w  w  w .  java  2  s . c o  m*/
    validatorInstances = new ConcurrentHashMap<>(2);

    if (eachAType.isAnnotationPresent(EachConstraint.class)) {
        Class constraintClass = eachAType.getAnnotation(EachConstraint.class).validateAs();

        Annotation constraint = createConstraintAndCopyAttributes(constraintClass, eachAnnotation);
        ConstraintDescriptor descriptor = createConstraintDescriptor(constraint);

        descriptors = unmodifiableList(asList(descriptor));

        // legacy
    } else if (isWrapperAnnotation(eachAType)) {
        Annotation[] constraints = unwrapConstraints(eachAnnotation);
        Validate.notEmpty(constraints, "%s annotation does not contain any constraint", eachAType);

        List<ConstraintDescriptor> list = new ArrayList<>(constraints.length);
        for (Annotation constraint : constraints) {
            list.add(createConstraintDescriptor(constraint));
        }
        descriptors = unmodifiableList(list);

        this.earlyInterpolate = true;

    } else {
        throw new IllegalArgumentException(String.format(
                "%s is not annotated with @EachConstraint and doesn't declare 'value' of type Annotation[] either.",
                eachAType.getName()));
    }
    // constraints are always of the same type, so just pick first
    ConstraintDescriptor descriptor = descriptors.get(0);

    validators = categorizeValidatorsByType(descriptor.getConstraintValidatorClasses());
    Validate.notEmpty(validators, "No validator found for constraint: %s",
            descriptor.getAnnotation().annotationType());
}

From source file:edu.sabanciuniv.sentilab.sare.models.base.PersistentObject.java

/**
 * Gets a flag indicating whether this object has the given property attached or not.
 * @param property the name of the property to look for.
 * @return {@code true} if the property exists, {@code false} otherwise.
 *//*from w w  w  . j  a  va2  s .c o  m*/
public boolean hasProperty(String property) {
    Validate.notEmpty(property, CannedMessages.EMPTY_ARGUMENT, "property");
    return this.getOtherData().has(property);
}

From source file:edu.sabanciuniv.sentilab.sare.models.base.PersistentObject.java

/**
 * Gets an attached property of this object.
 * @param property the name of the property to get.
 * @param typeOfT the type of object expected.
 * @return the retrieved property; {@code null} if not present or if the type is not correct.
 *///from   w w w.  j  a  v a2  s. com
public <T> T getProperty(String property, Type typeOfT) {
    Validate.notEmpty(property, CannedMessages.EMPTY_ARGUMENT, "property");
    Validate.notNull(typeOfT, CannedMessages.NULL_ARGUMENT, "typeOfT");

    try {
        return new Gson().fromJson(this.getOtherData(), typeOfT);
    } catch (JsonSyntaxException e) {
        return null;
    }
}