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

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

Introduction

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

Prototype

public static boolean isNumericSpace(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only Unicode digits or space ( ' ' ).

Usage

From source file:kenh.expl.functions.IsNumericSpace.java

public boolean process(String cs) {
    return StringUtils.isNumericSpace(cs);
}

From source file:com.jwebmp.core.generics.XYObject.java

/**
 * An Array Representation [X,Y]/*from  www.j  a va 2 s. c  o  m*/
 *
 * @return
 */
@Override
@JsonValue
@JsonRawValue
public String toString() {
    if (getX() != null && getY() != null) {
        if (!StringUtils.isNumericSpace(getX().toString())) {
            if (getX() instanceof Date) {
                return "['" + outputFormat.format((Date) getX()) + "'," + getY() + "]";
            } else if (getX() instanceof String) {
                return "['" + getX() + "'," + getY() + "]";
            }
        }
        return "[" + getX() + StaticStrings.STRING_COMMNA + getY() + "]";
    }
    return "[]";
}

From source file:net.sf.jabb.util.stat.TimePeriod.java

/**
 * Parse strings like '1 hour', '2 days', '3 Years', '12 minute' into TimePeriod.
 * Short formats like '1H', '2 D', '3y' are also supported.
 * @param quantityAndUnit   the string to be parsed
 * @return   Both quantity and unit//  w  w  w  . ja va  2  s .  c om
 */
static public TimePeriod from(String quantityAndUnit) {
    String trimed = quantityAndUnit.trim();
    String allExceptLast = trimed.substring(0, trimed.length() - 1);
    if (StringUtils.isNumericSpace(allExceptLast)) { // short format
        long quantity = Long.parseLong(allExceptLast.trim());
        TimePeriodUnit unit = TimePeriodUnit.from(Character.toUpperCase(trimed.charAt(trimed.length() - 1)));
        return new TimePeriod(quantity, unit);
    } else {
        String[] durationAndUnit = StringUtils.split(trimed);
        Long duration = Long.valueOf(durationAndUnit[0]);
        TimePeriodUnit unit = TimePeriodUnit.from(durationAndUnit[1]);
        return new TimePeriod(duration, unit);
    }
}

From source file:de.jfachwert.bank.GeldbetragFormatter.java

private static String findCurrencyString(String[] parts) {
    if (!StringUtils.isNumericSpace(parts[0])) {
        return parts[0];
    }//from  w  ww  .j  ava2s . c om
    if (!StringUtils.isNumericSpace(parts[parts.length - 1])) {
        return parts[parts.length - 1];
    }
    return "";
}

From source file:ke.co.tawi.babblesms.server.servlet.upload.UploadUtil.java

/**
 * Checks that an uploaded Contact file is in proper order.
 * /*from  w w  w.  j  a  v  a  2s.  co m*/
 * @param file
 * @return the feedback of having inspected the file, whether it was proper
 */
protected String inspectContactFile(File file) {
    String feedback = ContactUpload.UPLOAD_SUCCESS;
    int count = 1;

    LineIterator lineIterator = null;
    try {
        lineIterator = FileUtils.lineIterator(file, "UTF-8");

        String line;
        String[] rowTokens, phoneTokens, networkTokens;
        String network;
        while (lineIterator.hasNext()) {
            line = lineIterator.nextLine();

            rowTokens = StringUtils.split(line, ',');

            if (rowTokens.length != 3 && line.length() > 0) {// Every row must have 3 columns
                return ("Invalid format on line " + count + ": " + line);
            }

            phoneTokens = StringUtils.split(rowTokens[1], ';');
            networkTokens = StringUtils.split(rowTokens[2], ';');

            // Check that the number of phone numbers and number of networks match
            if (phoneTokens.length != networkTokens.length) {
                return ("Invalid format on line " + count + ": " + line);
            }

            // Check that the phone numbers contain only numbers or spaces
            for (String phone : phoneTokens) {
                if (!StringUtils.isNumericSpace(phone)) {
                    return ("Invalid number on line " + count + ": " + line);
                }
            }

            // Check to see that only valid networks have been provided
            for (String s : networkTokens) {
                network = StringUtils.lowerCase(StringUtils.trimToEmpty(s));
                if (!networkList.contains(network)) {
                    return ("Invalid network on line " + count + ": " + line);
                }
            }

            count++;
        }

    } catch (IOException e) {
        logger.error("IOException when inspecting: " + file);
        logger.error(e);

    } finally {
        if (lineIterator != null) {
            lineIterator.close();
        }
    }

    return feedback;
}

From source file:org.gbif.ipt.validation.ExtensionMappingValidator.java

public ValidationStatus validate(ExtensionMapping mapping, Resource resource, List<String[]> peek) {
    ValidationStatus v = new ValidationStatus();
    // check required fields
    Extension ext = mapping.getExtension();
    if (ext != null) {
        for (ExtensionProperty p : ext.getProperties()) {
            if (p.isRequired() && !mapping.isMapped(p)) {
                v.addMissingRequiredField(p);
            }/* w  ww  .j  a va2s .c  o  m*/
        }

        // check data types for default mappings
        for (PropertyMapping pm : mapping.getFields()) {
            ExtensionProperty extProperty = mapping.getExtension().getProperty(pm.getTerm());
            DataType type = extProperty != null ? extProperty.getType() : null;
            if (type != null && DataType.string != type) {
                // non string data type. check
                if (!isValidDataType(type, pm, peek)) {
                    v.addWrongDataTypeField(pm.getTerm());
                }
            }
        }

        // check id mapping
        if (mapping.getIdColumn() == null) {
            // no id, ok if this is a core
            if (!ext.isCore()) {
                v.setIdProblem("validation.mapping.coreid.missing");
            }
        } else if (mapping.getIdColumn().equals(ExtensionMapping.IDGEN_LINE_NUMBER)) {
            // pure integers are not allowed as line numbers plus integers will result in duplicates
            if (StringUtils.isNumericSpace(StringUtils.trimToNull(mapping.getIdSuffix()))) {
                v.setIdProblem("validation.mapping.coreid.linenumber.integer");
            }
            // if its core make sure all other mappings to the same extensions dont use linenumber with the same suffix or
            if (ext.isCore()) {
                Set<ExtensionMapping> maps = new HashSet<ExtensionMapping>(
                        resource.getMappings(ext.getRowType()));
                maps.remove(mapping);
                if (!maps.isEmpty()) {
                    // we more mappings to the same extension, compare their id policy
                    for (ExtensionMapping m : maps) {
                        if (m.getIdColumn() != null
                                && m.getIdColumn().equals(ExtensionMapping.IDGEN_LINE_NUMBER)) {
                            // do we have different suffices?
                            if (StringUtils.trimToEmpty(mapping.getIdSuffix()).equals(m.getIdSuffix())) {
                                v.setIdProblem("validation.mapping.coreid.linenumber.samesufix");
                            }
                        }
                    }
                }
            } else {
                // linenumbers for extensions only make sense when there is a core with the same suffix
                boolean found = false;
                for (ExtensionMapping m : resource.getCoreMappings()) {
                    if (m.getIdColumn() != null && m.getIdColumn().equals(ExtensionMapping.IDGEN_LINE_NUMBER)) {
                        // do they have the same suffix?
                        if (StringUtils.trimToEmpty(mapping.getIdSuffix())
                                .equals(StringUtils.trimToEmpty(m.getIdSuffix()))) {
                            found = true;
                            break;
                        }
                    }
                }
                if (!found) {
                    v.setIdProblem("validation.mapping.coreid.linenumber.nocoresuffix");
                }
            }
        } else if (mapping.getIdColumn().equals(ExtensionMapping.IDGEN_UUID)) {
            // not allowed for extensions
            if (ext.isCore()) {
                // if there are any extensions existing the cant link to the new UUIDs
                for (ExtensionMapping m : resource.getMappings()) {
                    if (!m.isCore()) {
                        v.setIdProblem("validation.mapping.coreid.uuid.extensions.exist");
                    }
                }
            } else {
                v.setIdProblem("validation.mapping.coreid.uuid.extension");
            }
        } // else {
          // TODO: anything to check for regular columns?
          // }
    }
    return v;
}

From source file:org.languagetool.rules.WordRepeatRule.java

private boolean isWord(String token) {
    boolean isWord = true;
    if (StringUtils.isNumericSpace(token)) {
        isWord = false;/*from   w ww .  ja v a2s .c  om*/
    } else if (token.length() == 1) {
        char c = token.charAt(0);
        if (!Character.isLetter(c)) {
            isWord = false;
        }
    }
    return isWord;
}

From source file:org.openestate.is24.restapi.utils.XmlUtils.java

/**
 * Write a {@link String} value into XML output
 * with a valid phone number area code.//from w w  w.  j a  v a 2s  .  c o m
 *
 * @param value
 * value to write
 *
 * @return
 * XML string
 *
 * @throws IllegalArgumentException
 * if a validation error occured
 */
public static String printPhoneNumberAreaCode(String value) {
    String val = StringUtils.trimToNull(value);
    if (val == null || !StringUtils.isNumericSpace(val)) {
        throw new IllegalArgumentException("The provided area phone code '" + value + "' is invalid!");
    }

    val = StringUtils.trimToNull(val.replaceAll("\\D", ""));
    if (val == null || val.length() > 10) {
        throw new IllegalArgumentException("The provided area phone code '" + value + "' is invalid!");
    }

    return val;
}

From source file:org.paxml.selenium.rc.SelectFrameTag.java

@Override
public String getLocator() {

    if (StringUtils.isBlank(target)) {
        return super.getLocator();
    } else if (TOP.equalsIgnoreCase(target)) {
        return "relative=top";
    } else if (PARENT.equalsIgnoreCase(target)) {
        return "relative=parent";
    } else if (StringUtils.isNumericSpace(target)) {
        return "index=" + Long.parseLong(target);
    } else {//from  www  . j  a  v a  2  s .c  o m
        throw new PaxmlRuntimeException("Unknown target: " + target);
    }
}

From source file:za.co.mmagon.jwebswing.generics.XYObject.java

/**
 * An Array Representation [X,Y]// w  ww . j av a  2  s  . c om
 *
 * @return
 */
@Override
@JsonValue
@JsonRawValue
public String toString() {
    if (!StringUtils.isNumericSpace(getX().toString())) {
        if (getX() instanceof Date) {
            String formatted = "['" + outputFormat.format(Date.class.cast(getX())) + "'," + getY() + "]";
            return formatted;
        } else if (getX() instanceof String) {
            return "['" + getX() + "'," + getY() + "]";
        }
    }
    return "[" + getX() + "," + getY() + "]";
}