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

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

Introduction

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

Prototype

public static String deleteWhitespace(String str) 

Source Link

Document

Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .

Usage

From source file:uk.ac.ebi.embl.api.validation.check.feature.CollectionDateQualifierCheck.java

public ValidationResult check(Feature feature) {
    result = new ValidationResult();
    if (feature == null) {
        return result;
    }//from  ww w .j av a  2  s  . c o m

    List<Qualifier> collectionDateQualifiers = feature.getQualifiers(Qualifier.COLLECTION_DATE_QUALIFIER_NAME);

    if (collectionDateQualifiers.size() == 0) {
        return result;
    }

    for (Qualifier collectionQualifier : collectionDateQualifiers) {
        String value = collectionQualifier.getValue();
        if (value == null || value.isEmpty()) {
            reportError(collectionQualifier.getOrigin(), DATE_FORMAT_ERROR, collectionQualifier.getName(), "");
        }

        String valueNoWhitespace = StringUtils.deleteWhitespace(value);

        if (valueNoWhitespace == null || valueNoWhitespace.isEmpty()) {
            reportError(collectionQualifier.getOrigin(), DATE_FORMAT_ERROR, collectionQualifier.getName(), "");
        }

        if (!valueNoWhitespace.equals(value)) {
            collectionQualifier.setValue(valueNoWhitespace);
            value = valueNoWhitespace;
        }

        Matcher m = DATE_RANGE_PATTERN.matcher(value);

        if (m.matches()) {
            CheckDateResult fromResult = checkDate(collectionQualifier, m.group(1));
            CheckDateResult toResult = checkDate(collectionQualifier, m.group(2));

            if (fromResult.date != null && toResult.date != null) {
                if (fromResult.pattern != toResult.pattern) {
                    // Different range date formats.
                    reportError(collectionQualifier.getOrigin(), DATE_FORMAT_ERROR,
                            collectionQualifier.getName(), value);
                }
                if (fromResult.date.compareTo(toResult.date) > 0) {
                    // From date in a range is larger than to date.                  
                    reportError(collectionQualifier.getOrigin(), DATE_FORMAT_ERROR,
                            collectionQualifier.getName(), value);
                }
            }
        } else {
            checkDate(collectionQualifier, value);
        }
    }
    return result;
}