Example usage for org.apache.commons.lang3.math NumberUtils isDigits

List of usage examples for org.apache.commons.lang3.math NumberUtils isDigits

Introduction

In this page you can find the example usage for org.apache.commons.lang3.math NumberUtils isDigits.

Prototype

public static boolean isDigits(final String str) 

Source Link

Document

Checks whether the String contains only digit characters.

Null and empty String will return false.

Usage

From source file:org.phenotips.data.internal.controller.APGARController.java

@Override
public PatientData<Integer> readJSON(JSONObject json) {
    JSONObject container = json.optJSONObject(DATA_NAME);
    if (container != null) {
        Map<String, Integer> parsed = new LinkedHashMap<>();
        for (String propertyName : getProperties()) {
            try {
                /* could be 'unknown' rather than an int */
                String value = container.optString(propertyName);
                if (NumberUtils.isDigits(value)) {
                    parsed.put(propertyName, Integer.valueOf(value));
                }//  w w w. j a v  a  2s. co  m
                if (StringUtils.isEmpty(value)) {
                    parsed.put(propertyName, null);
                }
            } catch (Exception ex) {
                // should never happen
            }
        }
        return new DictionaryPatientData<>(DATA_NAME, parsed);
    }
    return null;
}

From source file:org.phenotips.data.internal.controller.VariantListController.java

private void parseVariantProperty(String property, JSONObject variantJson, Map<String, List<String>> enumValues,
        Map<String, String> singleVariant, List<String> enumValueKeys) {
    String field = "";
    if (INTERNAL_EVIDENCE_KEY.equals(property) && variantJson.getJSONArray(property).length() > 0) {
        JSONArray fieldArray = variantJson.getJSONArray(property);
        for (Object value : fieldArray) {
            if (enumValues.get(property).contains(value)) {
                field += "|" + value;
            }//from  w w w .  jav a  2s.  c om
        }
        singleVariant.put(property, field);
    } else if ((INTERNAL_START_POSITION_KEY.equals(property) || INTERNAL_END_POSITION_KEY.equals(property))
            && !StringUtils.isBlank(variantJson.getString(property))) {
        String value = variantJson.optString(property);
        if (NumberUtils.isDigits(value)) {
            singleVariant.put(property, value);
        }
    } else if (enumValueKeys.contains(property) && !StringUtils.isBlank(variantJson.getString(property))) {
        field = variantJson.getString(property);
        if (enumValues.get(property).contains(field.toLowerCase())) {
            singleVariant.put(property, field);
        }
    } else if (!StringUtils.isBlank(variantJson.getString(property))) {
        field = variantJson.getString(property);
        singleVariant.put(property, field);
    }
}

From source file:org.trimou.engine.resolver.IndexResolver.java

/**
 * @param name//ww  w  .j  a  v a2s  .c  o  m
 * @return <code>true</code> if the given key represents an index
 *         (must only contain digits)
 */
protected boolean isAnIndex(String name) {
    return NumberUtils.isDigits(name);
}

From source file:org.xwiki.filter.instance.internal.output.XWikiDocumentOutputFilterStream.java

@Override
public void beginWikiDocumentRevision(String version, FilterEventParameters parameters) throws FilterException {
    this.document = new XWikiDocument(
            this.entityResolver.resolve(this.currentEntityReference,
                    this.properties != null ? this.properties.getDefaultReference() : null),
            this.currentLocale);

    this.document.setCreationDate(
            getDate(WikiDocumentFilter.PARAMETER_CREATION_DATE, this.currentLocaleParameters, null));
    if (this.currentLocaleParameters.containsKey(WikiDocumentFilter.PARAMETER_CREATION_AUTHOR)) {
        this.document.setCreator(
                getString(WikiDocumentFilter.PARAMETER_CREATION_AUTHOR, this.currentLocaleParameters, null));
    }//ww w.  j  a  va 2  s.c o m
    this.document.setDefaultLocale(this.currentDefaultLocale);

    this.document.setSyntax(getSyntax(WikiDocumentFilter.PARAMETER_SYNTAX, parameters, null));

    this.document.setParentReference(getEntityReference(WikiDocumentFilter.PARAMETER_PARENT, parameters, null));
    this.document.setCustomClass(getString(WikiDocumentFilter.PARAMETER_CUSTOMCLASS, parameters, null));
    this.document.setTitle(getString(WikiDocumentFilter.PARAMETER_TITLE, parameters, null));
    this.document.setDefaultTemplate(getString(WikiDocumentFilter.PARAMETER_DEFAULTTEMPLATE, parameters, null));
    this.document
            .setValidationScript(getString(WikiDocumentFilter.PARAMETER_VALIDATIONSCRIPT, parameters, null));
    this.document.setHidden(getBoolean(WikiDocumentFilter.PARAMETER_HIDDEN, parameters, false));

    this.document.setMinorEdit(getBoolean(WikiDocumentFilter.PARAMETER_REVISION_MINOR, parameters, false));
    if (parameters.containsKey(WikiDocumentFilter.PARAMETER_REVISION_AUTHOR)) {
        this.document.setAuthor(getString(WikiDocumentFilter.PARAMETER_REVISION_AUTHOR, parameters, null));
    }
    this.document.setContentAuthor(getString(WikiDocumentFilter.PARAMETER_CONTENT_AUTHOR, parameters, null));

    String revisions = getString(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS, this.currentLocaleParameters,
            null);
    if (revisions != null) {
        try {
            this.document.setDocumentArchive(revisions);
        } catch (XWikiException e) {
            throw new FilterException("Failed to set document archive", e);
        }
    }

    if (version != null && this.properties.isVersionPreserved()) {
        if (VALID_VERSION.matcher(version).matches()) {
            this.document.setVersion(version);
        } else if (NumberUtils.isDigits(version)) {
            this.document.setVersion(version + ".1");
        } else {
            // TODO: log something, probably a warning
        }
    }

    this.document.setDate(getDate(WikiDocumentFilter.PARAMETER_REVISION_DATE, parameters, new Date()));
    this.document.setComment(getString(WikiDocumentFilter.PARAMETER_REVISION_COMMENT, parameters, ""));

    this.document
            .setContentUpdateDate(getDate(WikiDocumentFilter.PARAMETER_CONTENT_DATE, parameters, new Date()));

    // Content

    if (parameters.containsKey(WikiDocumentFilter.PARAMETER_CONTENT)) {
        this.document.setContent(getString(WikiDocumentFilter.PARAMETER_CONTENT, parameters, null));
    } else {
        if (this.properties != null && this.properties.getDefaultSyntax() != null) {
            this.document.setSyntax(this.properties.getDefaultSyntax());
        } else {
            // Make sure to set the default syntax if none were provided
            this.document.setSyntax(this.document.getSyntax());
        }

        ComponentManager componentManager = this.componentManagerProvider.get();

        if (componentManager.hasComponent(PrintRendererFactory.class, this.document.getSyntax().toIdString())) {
            PrintRendererFactory rendererFactory;
            try {
                rendererFactory = componentManager.getInstance(PrintRendererFactory.class,
                        this.document.getSyntax().toIdString());
            } catch (ComponentLookupException e) {
                throw new FilterException(String.format("Failed to find PrintRendererFactory for syntax [%s]",
                        this.document.getSyntax()), e);
            }

            this.currentWikiPrinter = new DefaultWikiPrinter();
            this.contentListener.setWrappedListener(rendererFactory.createRenderer(this.currentWikiPrinter));
        }
    }
}

From source file:org.xwiki.filter.instance.internal.output.XWikiDocumentOutputFilterStream.java

@Override
public void onWikiAttachment(String name, InputStream content, Long size, FilterEventParameters parameters)
        throws FilterException {
    XWikiAttachment attachment = new XWikiAttachment(this.document, name);

    try {/*from   ww w  .  ja v a2  s . com*/
        attachment.setContent(content);
    } catch (IOException e) {
        throw new FilterException("Failed to set attachment content", e);
    }

    // Author

    attachment.setAuthor(getString(WikiAttachmentFilter.PARAMETER_REVISION_AUTHOR, parameters, ""));

    // Version

    if (this.properties == null || this.properties.isVersionPreserved()) {
        if (parameters.containsKey(WikiAttachmentFilter.PARAMETER_REVISION)) {
            String version = getString(WikiAttachmentFilter.PARAMETER_REVISION, parameters, null);
            if (version != null) {
                if (VALID_VERSION.matcher(version).matches()) {
                    attachment.setVersion(version);
                } else if (NumberUtils.isDigits(version)) {
                    attachment.setVersion(version + ".1");
                } else {
                    // TODO: log something, probably a warning
                }
            }
        }
        attachment.setComment(getString(WikiAttachmentFilter.PARAMETER_REVISION_COMMENT, parameters, ""));
        attachment.setDate(getDate(WikiAttachmentFilter.PARAMETER_REVISION_DATE, parameters, new Date()));

        String revisions = getString(XWikiWikiAttachmentFilter.PARAMETER_JRCSREVISIONS, parameters, null);
        if (revisions != null) {
            try {
                attachment.setArchive(revisions);
            } catch (XWikiException e) {
                throw new FilterException("Failed to set attachment archive", e);
            }
        }

        attachment.setMetaDataDirty(false);
    }

    this.document.addAttachment(attachment);
}

From source file:org.xwiki.wikistream.instance.internal.output.XWikiDocumentOutputWikiStream.java

@Override
public void beginWikiDocumentRevision(String version, FilterEventParameters parameters)
        throws WikiStreamException {
    this.document = new XWikiDocument(this.entityResolver.resolve(this.currentEntityReference,
            this.properties != null ? this.properties.getDefaultReference() : null));

    this.document.setCreationDate(
            getDate(WikiDocumentFilter.PARAMETER_CREATION_DATE, this.currentLocaleParameters, null));
    if (this.currentLocaleParameters.containsKey(WikiDocumentFilter.PARAMETER_CREATION_AUTHOR)) {
        this.document.setCreator(
                getString(WikiDocumentFilter.PARAMETER_CREATION_AUTHOR, this.currentLocaleParameters, null));
    }// ww w .j av  a 2  s.c om
    this.document.setDefaultLocale(this.currentDefaultLocale);

    this.document.setSyntax(getSyntax(WikiDocumentFilter.PARAMETER_SYNTAX, parameters, null));

    this.document.setLocale(this.currentLocale);

    this.document.setParentReference(getEntityReference(WikiDocumentFilter.PARAMETER_PARENT, parameters, null));
    this.document.setCustomClass(getString(WikiDocumentFilter.PARAMETER_CUSTOMCLASS, parameters, null));
    this.document.setTitle(getString(WikiDocumentFilter.PARAMETER_TITLE, parameters, null));
    this.document.setDefaultTemplate(getString(WikiDocumentFilter.PARAMETER_DEFAULTTEMPLATE, parameters, null));
    this.document
            .setValidationScript(getString(WikiDocumentFilter.PARAMETER_VALIDATIONSCRIPT, parameters, null));
    this.document.setHidden(getBoolean(WikiDocumentFilter.PARAMETER_HIDDEN, parameters, false));

    this.document.setMinorEdit(getBoolean(WikiDocumentFilter.PARAMETER_REVISION_MINOR, parameters, false));
    if (parameters.containsKey(WikiDocumentFilter.PARAMETER_REVISION_AUTHOR)) {
        this.document.setAuthor(getString(WikiDocumentFilter.PARAMETER_REVISION_AUTHOR, parameters, null));
    }
    this.document.setContentAuthor(getString(WikiDocumentFilter.PARAMETER_CONTENT_AUTHOR, parameters, null));

    String revisions = getString(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS, this.currentLocaleParameters,
            null);
    if (revisions != null) {
        try {
            this.document.setDocumentArchive(revisions);
        } catch (XWikiException e) {
            throw new WikiStreamException("Failed to set document archive", e);
        }
    }

    if (version != null && this.properties.isVersionPreserved()) {
        if (VALID_VERSION.matcher(version).matches()) {
            this.document.setVersion(version);
        } else if (NumberUtils.isDigits(version)) {
            this.document.setVersion(version + ".1");
        } else {
            // TODO: log something, probably a warning
        }
    }

    this.document.setDate(getDate(WikiDocumentFilter.PARAMETER_REVISION_DATE, parameters, new Date()));
    this.document.setComment(getString(WikiDocumentFilter.PARAMETER_REVISION_COMMENT, parameters, ""));

    this.document
            .setContentUpdateDate(getDate(WikiDocumentFilter.PARAMETER_CONTENT_DATE, parameters, new Date()));

    // Content

    if (parameters.containsKey(WikiDocumentFilter.PARAMETER_CONTENT)) {
        this.document.setContent(getString(WikiDocumentFilter.PARAMETER_CONTENT, parameters, null));
    } else {
        if (this.properties != null && this.properties.getDefaultSyntax() != null) {
            this.document.setSyntax(this.properties.getDefaultSyntax());
        } else {
            // Make sure to set the default syntax if none were provided
            this.document.setSyntax(this.document.getSyntax());
        }

        ComponentManager componentManager = this.componentManagerProvider.get();

        if (componentManager.hasComponent(PrintRendererFactory.class, this.document.getSyntax().toIdString())) {
            PrintRendererFactory rendererFactory;
            try {
                rendererFactory = componentManager.getInstance(PrintRendererFactory.class,
                        this.document.getSyntax().toIdString());
            } catch (ComponentLookupException e) {
                throw new WikiStreamException(String.format(
                        "Failed to find PrintRendererFactory for syntax [%s]", this.document.getSyntax()), e);
            }

            this.currentWikiPrinter = new DefaultWikiPrinter();
            this.contentListener.setWrappedListener(rendererFactory.createRenderer(this.currentWikiPrinter));
        }
    }
}

From source file:org.xwiki.wikistream.instance.internal.output.XWikiDocumentOutputWikiStream.java

@Override
public void onWikiAttachment(String name, InputStream content, Long size, FilterEventParameters parameters)
        throws WikiStreamException {
    XWikiAttachment attachment = new XWikiAttachment(this.document, name);

    try {//from w w w.j  a  va 2  s  . c o m
        attachment.setContent(content);
    } catch (IOException e) {
        throw new WikiStreamException("Failed to set attachment content", e);
    }

    // Author

    attachment.setAuthor(getString(WikiAttachmentFilter.PARAMETER_REVISION_AUTHOR, parameters, ""));

    // Version

    if (this.properties == null || this.properties.isVersionPreserved()) {
        if (parameters.containsKey(WikiAttachmentFilter.PARAMETER_REVISION)) {
            String version = getString(WikiAttachmentFilter.PARAMETER_REVISION, parameters, null);
            if (version != null) {
                if (VALID_VERSION.matcher(version).matches()) {
                    attachment.setVersion(version);
                } else if (NumberUtils.isDigits(version)) {
                    attachment.setVersion(version + ".1");
                } else {
                    // TODO: log something, probably a warning
                }
            }
        }
        attachment.setComment(getString(WikiAttachmentFilter.PARAMETER_REVISION_COMMENT, parameters, ""));
        attachment.setDate(getDate(WikiAttachmentFilter.PARAMETER_REVISION_DATE, parameters, new Date()));

        String revisions = getString(XWikiWikiAttachmentFilter.PARAMETER_JRCSREVISIONS, parameters, null);
        if (revisions != null) {
            try {
                attachment.setArchive(revisions);
            } catch (XWikiException e) {
                throw new WikiStreamException("Failed to set attachment archive", e);
            }
        }

        attachment.setMetaDataDirty(false);
    }

    this.document.addAttachment(attachment);
}

From source file:rs.metropolitan.data_changer.DataFactory.java

public Object change(String data) {

    String trim = data.trim();/*  www  .java2  s .  c  o m*/
    System.out.println(trim);
    String[] seps = { ",", "{", "}" };
    if (StringUtils.containsAny(trim, seps)) {
        ToList lista = new ToList();
        return lista.changeString(trim);
    } else if (false) {

    } else if (NumberUtils.isDigits(trim)) {
        ToInteger toint = new ToInteger();
        return toint.changeString(trim);
    } else if (StringUtils.isAlphanumericSpace(trim)) {
        return data;
    }
    return null;

}

From source file:siddur.solidtrust.bi.data.DataPump.java

private static int getInt(Object obj) {
    if (obj instanceof String) {
        String s = (String) obj;
        if (StringUtils.isBlank(s)) {
            return 0;
        }//from  w  ww  . jav a 2 s  . c om
        s = s.trim().replace(".", "");
        if (NumberUtils.isDigits(s)) {
            return Integer.parseInt(s);
        }
        s = StringUtils.split(s.trim())[0].replace(".", "");
        if (NumberUtils.isDigits(s)) {
            return Integer.parseInt(s);
        }
        return 0;

    }
    return (int) obj;
}