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

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

Introduction

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

Prototype

public static boolean isWhitespace(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only whitespace.

null will return false .

Usage

From source file:tinyequationscoringengine.MathScoringService.java

public boolean isEmpty(MathExpression mathexp) {
    if (mathexp == null) {
        return true;
    } else if (mathexp.getMathMLNodeList() == null) {
        // One of the MathExpression object constructors is defined to bypass
        // MathML processing and therefore
        // isEmpty function has to account for the case when MathML is left empty
        // but Sympy representation exists
        if (mathexp.getSympyResponse() == null || mathexp.getSympyResponse().size() == 0)
            return true;

        char[] charsToTrim = { ' ', '(', ')' };
        for (int expInd = 0; expInd < mathexp.getSympyResponse().size(); expInd++) {
            if (!StringUtils.isEmpty(StringHelper.trim(mathexp.getSympyResponse().get(expInd), charsToTrim)))
                return false;
        }//from w ww  .j a  v a  2  s  .co  m
        return true;
    }

    XmlNamespaceManager nsmgr = new XmlNamespaceManager();
    nsmgr.addNamespace("math", "http://www.w3.org/1998/Math/MathML");
    for (Element node_i : mathexp.getMathMLNodeList()) {
        List<Element> text_nodes = new XmlElement(node_i)
                .selectNodes("..//math:mo/text()|..//math:mi/text()|..//math:mn/text()", nsmgr);
        for (Element node_j : text_nodes) {
            if (!StringUtils.isEmpty(node_j.getValue()) && !StringUtils.isWhitespace(node_j.getValue()))
                return false;
        }
    }
    return true;
}