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:de.decoit.simu.cbor.ifmap.metadata.singlevalue.CBORWlanInformation.java

/**
 * Set the SSID for this metadata./*from www. j a va 2 s  .  c om*/
 * The SSID may be null to remove this value from the metadata. If not null,
 * the SSID MUST NOT be an empty string or whitespace only.
 *
 * @param ssid SSID for this metadata
 */
public void setSsid(String ssid) {
    if (StringUtils.isWhitespace(ssid)) {
        throw new IllegalArgumentException("SSID must not be empty or whitespace only");
    }

    this.ssid = ssid;
}

From source file:de.decoit.simu.cbor.ifmap.metadata.multivalue.CBORDeviceCharacteristic.java

/**
 * Set the operating system version for this metadata.
 * The operating system version may be null to remove this value from the metadata. If not null,
 * the operating system version MUST NOT be an empty string or whitespace only.
 *
 * @param osVersion Operating system version
 *///from w w w .jav  a2  s .  c  o m
public void setOsVersion(String osVersion) {
    if (StringUtils.isWhitespace(osVersion)) {
        throw new IllegalArgumentException("OS version must not be empty or whitespace only");
    }

    this.osVersion = osVersion;
}

From source file:de.decoit.simu.cbor.ifmap.metadata.multivalue.CBOREnforcementReport.java

/**
 * Set the enforcement-reason for this metadata.
 * The enforcement-reason may be null to remove this value from the metadata. If not null,
 * the enforcement-reason MUST NOT be an empty string or whitespace only.
 *
 * @param enforcementReason enforcement-reason for this metadata
 *///from   ww  w. j  a va  2  s .  co  m
public void setEnforcementReason(String enforcementReason) {
    if (StringUtils.isWhitespace(enforcementReason)) {
        throw new IllegalArgumentException("administrative-domain must not be empty or whitespace only");
    }

    this.enforcementReason = enforcementReason;
}

From source file:jongo.filter.DefaultFormatFilter.java

private String formatSuccessJSONResponse(final JongoSuccess response) {
    final StringBuilder b = new StringBuilder("{");
    b.append("\"success\":");
    b.append(response.isSuccess());//from   ww w. j av  a 2s . c om
    b.append(",\"cells\":[ "); //this last space is important!
    for (Row r : response.getRows()) {
        List<String> args = new ArrayList<String>();
        for (String key : r.getCells().keySet()) {
            String val = StringEscapeUtils.escapeJson(r.getCells().get(key));
            if (StringUtils.isNumeric(val)) {
                if (StringUtils.isWhitespace(val)) {
                    args.add("\"" + key.toLowerCase() + "\"" + ":" + "\"\"");
                } else {
                    args.add("\"" + key.toLowerCase() + "\"" + ":" + val);
                }
            } else {
                args.add("\"" + key.toLowerCase() + "\"" + ":" + "\"" + val + "\"");
            }
        }

        b.append("{");
        b.append(StringUtils.join(args, ","));
        b.append("}");
        b.append(",");
    }
    b.deleteCharAt(b.length() - 1);
    b.append("]}");
    return b.toString();
}

From source file:de.decoit.simu.cbor.ifmap.metadata.multivalue.CBOREvent.java

/**
 * Set an information for this metadata.
 * The information may be null to remove this value from the metadata. If not null,
 * the information MUST NOT be an empty string or whitespace only.
 *
 * @param information administrative-domain value, may be null
 *//*from ww w  .  j a va 2s.c o  m*/
public void setInformation(String information) {
    if (StringUtils.isWhitespace(information)) {
        throw new IllegalArgumentException("Information must not be empty or whitespace only");
    }

    this.information = information;
}

From source file:de.decoit.simu.cbor.ifmap.metadata.multivalue.CBORDeviceCharacteristic.java

/**
 * Set the device type for this metadata.
 * The device type may be null to remove this value from the metadata. If not null,
 * the device type MUST NOT be an empty string or whitespace only.
 *
 * @param deviceType Device type/*from  w w  w .  j  av  a2s . com*/
 */
public void setDeviceType(String deviceType) {
    if (StringUtils.isWhitespace(deviceType)) {
        throw new IllegalArgumentException("Device type must not be empty or whitespace only");
    }

    this.deviceType = deviceType;
}

From source file:de.gbv.ole.Marc21ToOleBulk.java

/**
 * Throws a MarcException if the parameter is not a valid isbn10 number
 * with valid check digit./*from   w  w w. j a v  a2 s.  c o  m*/
 * 
 * Valid: "00", "19", "27",
 * "2121212124", 
 * "9999999980",
 * "9999999999"
 * 
 * @param isbn10 the number to validate
 */
static void validateIsbn10(final String isbn10) {
    if (StringUtils.isEmpty(isbn10)) {
        throw new MarcException("null or empty number");
    }
    if (StringUtils.isWhitespace(isbn10)) {
        throw new MarcException("number expected, found only whitespace");
    }
    if (StringUtils.containsWhitespace(isbn10)) {
        throw new MarcException(
                "number plus check digit expected, but contains " + "whitespace: '" + isbn10 + "'");
    }
    if (isbn10.length() < 2) {
        throw new MarcException("number plus check digit expected, " + "but found: " + isbn10);
    }
    if (isbn10.length() > 10) {
        throw new MarcException("maximum length of number plus " + "check digit is 10 (9 + 1 check digit),\n"
                + "input is " + isbn10.length() + " characters long: " + isbn10);
    }
    String checkdigit = StringUtils.right(isbn10, 1);
    if (!StringUtils.containsOnly(checkdigit, "0123456789xX")) {
        throw new MarcException("check digit must be 0-9, x or X, " + "but is " + checkdigit);
    }
    String number = withoutCheckdigit(isbn10);
    if (!StringUtils.containsOnly(number, "0123456789")) {
        throw new MarcException("number before check digit must " + "contain 0-9 only, but is " + checkdigit);
    }
    String calculatedCheckdigit = isbn10checkdigit(Integer.parseInt(number));
    if (!StringUtils.equalsIgnoreCase(checkdigit, calculatedCheckdigit)) {
        throw new MarcException("wrong checkdigit " + checkdigit + ", correct check digit is "
                + calculatedCheckdigit + ": " + isbn10);
    }
}

From source file:de.decoit.simu.cbor.ifmap.metadata.multivalue.CBOREvent.java

/**
 * Set an vulnerability URI for this metadata.
 * The vulnerability URI may be null to remove this value from the metadata. If not null,
 * the vulnerability URI MUST NOT be an empty string or whitespace only.
 *
 * @param vulnerabilityUri Vulnerability URI, may be null
 *//* w w w . j  ava2  s.  c o  m*/
public void setVulnerabilityUri(String vulnerabilityUri) {
    if (StringUtils.isWhitespace(vulnerabilityUri)) {
        throw new IllegalArgumentException("Vulnerability URI must not be empty or whitespace only");
    }

    this.vulnerabilityUri = vulnerabilityUri;
}

From source file:de.decoit.simu.cbor.xml.dictionary.parser.DictionaryParser.java

/**
 * Read the next line from the {@link BufferedReader}.
 * This method skips empty lines and returns either lines filled with content
 * or null (end of file).// www. j a v a  2s  . c  o  m
 *
 * @return Source file or null (end of file)
 * @throws IOException if reading from the source file fails
 */
private String readLineFromBuffer() throws IOException {
    String srcLine;
    do {
        // Read lines until the line is null or not empty
        srcLine = this.br.readLine();
    } while (StringUtils.isWhitespace(srcLine));

    // If line is not null trim leading and trailing whitespaces
    if (srcLine != null) {
        srcLine = srcLine.trim();
    }

    if (log.isDebugEnabled()) {
        log.debug("Source line: " + srcLine);

        if (srcLine == null) {
            log.debug("Reached EOF!");
        }
    }

    return srcLine;
}

From source file:candr.yoclip.Parser.java

/**
 * Creates a {@code ParsedOptionParameter} for the option parameter at the head of the queue. The parsed option will not contain an error if an
 * option value is missing. The parsed option will contain an error if the option appears to have an associated value and does not take a value.
 *
 * @param parameters The current queue of command parameters.
 * @return a parsed option parameter or {@code null} in the following cases.
 * <ul>//from w  ww  . ja  va 2s.c o  m
 * <li>The parameters queue is empty.</li>
 * <li>The head of the parameters queue is not an option.</li>
 * </ul>
 */
protected ParsedOption<T> getParsedOption(final Queue<String> parameters) {

    ParsedOption<T> parsedOptionParameter = null;

    final String parameter = parameters.peek();
    if (!StringUtils.isEmpty(parameter) && isOption(parameter)) {

        final String prefix = getParserOptions().getPrefix();
        final String separator = getParserOptions().getSeparator();
        final boolean isSeparatorWhitespace = StringUtils.isWhitespace(separator);

        final int separatorIndex = isSeparatorWhitespace ? -1 : parameter.indexOf(separator);
        final String optionParameterKey = parameter.substring(prefix.length(),
                separatorIndex < 0 ? parameter.length() : separatorIndex);
        final ParserOption<T> optionParameter = getParserOptions().get(optionParameterKey);
        if (null != optionParameter) {

            parameters.remove();

            // get the value if the option takes one
            if (optionParameter.hasValue()) {

                String value = null;
                if (isSeparatorWhitespace) {

                    if (parameters.size() > 0 && !isOption(parameters.peek())) {

                        // remove the value from the queue
                        value = parameters.remove();
                    }

                } else if (separatorIndex != -1) {

                    final int valueIndex = separatorIndex + 1;
                    if (valueIndex < parameter.length()) {
                        value = parameter.substring(valueIndex);
                    }
                }

                // The value can be null here, without it being an error condition, to facilitate actions later on
                // such as using a default.
                parsedOptionParameter = new ParsedOption<T>(optionParameter, value);

            } else if (separatorIndex > 1) {

                // if the separator is not white space and a value was present with the option parameter
                parsedOptionParameter = new ParsedOption<T>(optionParameter, null);
                parsedOptionParameter.setError("Does not take a value.");

            } else {

                // If the option does not take a value it must be a boolean so force it true
                parsedOptionParameter = new ParsedOption<T>(optionParameter, Boolean.TRUE.toString());
            }
        }
    }

    return parsedOptionParameter;
}