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.multivalue.CBORLayer2Information.java

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

    this.vlanName = vlanName;
}

From source file:jongo.JongoUtils.java

/**
 * Infers the java.sql.Types of the given String and returns the JDBC mappable Object corresponding to it.
 * The conversions are like this:/*from  w ww  .ja  va 2s  . c om*/
 * String -> String
 * Numeric -> Integer
 * Date or Time -> Date
 * Decimal -> BigDecimal
 * ??? -> TimeStamp
 * @param val a String with the value to be mapped
 * @return a JDBC mappable object instance with the value
 */
public static Object parseValue(String val) {
    Object ret = null;
    if (!StringUtils.isWhitespace(val) && StringUtils.isNumeric(val)) {
        try {
            ret = Integer.valueOf(val);
        } catch (Exception e) {
            l.debug(e.getMessage());
        }
    } else {
        DateTime date = JongoUtils.isDateTime(val);
        if (date != null) {
            l.debug("Got a DateTime " + date.toString(ISODateTimeFormat.dateTime()));
            ret = new java.sql.Timestamp(date.getMillis());
        } else {
            date = JongoUtils.isDate(val);
            if (date != null) {
                l.debug("Got a Date " + date.toString(ISODateTimeFormat.date()));
                ret = new java.sql.Date(date.getMillis());
            } else {
                date = JongoUtils.isTime(val);
                if (date != null) {
                    l.debug("Got a Time " + date.toString(ISODateTimeFormat.time()));
                    ret = new java.sql.Time(date.getMillis());
                }
            }
        }

        if (ret == null && val != null) {
            l.debug("Not a datetime. Try someting else. ");
            try {
                ret = new BigDecimal(val);
            } catch (NumberFormatException e) {
                l.debug(e.getMessage());
                ret = val;
            }
        }
    }
    return ret;
}

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

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

    this.dhcpServer = dhcpServer;
}

From source file:ca.nines.ise.writer.RTFWriter.java

private void startParagraph(RtfParagraphStyle style) throws DocumentException {
    if (!p.isEmpty() && !StringUtils.isWhitespace(p.getContent())) {
        doc.add(p);//  w  w w  .j a va2 s .c  om
    }
    p = new Paragraph("", style);
}

From source file:cz.matfyz.oskopek.learnr.tools.DatasetIO.java

/**
 * A manual method of importing a dataset from a text file.
 * <p/>/*from w  ww .  j  av  a2 s .com*/
 * Used for plain dataset distribution. Does not import statistics of any kind.
 * <p/>
 * <b>Warning:</b> Expects a syntactically perfect dataset according to the TXT dataset format specification! (See documentation).
 *
 * @param filename the filename from which to import
 * @return the imported dataset
 * @throws IOException if an error during read occurs
 */
public static Dataset importTXTDataset(String filename) throws IOException {
    LOGGER.debug("Import dataset from TXT: \'{}\'", filename);
    Dataset dataset = new Dataset();
    BufferedReader br = new BufferedReader(new FileReader(filename));

    br.readLine(); // PREAMBLE
    dataset.setName(br.readLine().split(":")[1].trim());
    dataset.setDescription(br.readLine().split(":")[1].trim());
    dataset.setAuthor(br.readLine().split(":")[1].trim());
    dataset.setCreatedDate(Long.parseLong(br.readLine().split(":")[1].trim()));
    int initWeight = Integer.parseInt(br.readLine().split(":")[1].trim());
    String[] limitsStr = br.readLine().split("/");
    Limits limits = new Limits(Integer.parseInt(limitsStr[0].split(":")[1].trim()),
            Integer.parseInt(limitsStr[1]));
    dataset.setLimits(limits);
    String answerCheckTypeStr = br.readLine().split(":")[1].trim();
    dataset.setAnswerCheckType(Dataset.AnswerCheckType.valueOf(answerCheckTypeStr));
    dataset.setGoodAnswerPenalty(Integer.parseInt(br.readLine().split(":")[1].trim()));
    dataset.setBadAnswerPenalty(Integer.parseInt(br.readLine().split(":")[1].trim()));

    String buffer;
    br.readLine(); // QUESTIONS
    TreeSet<Question> questionSet = new TreeSet<>();
    while ((buffer = br.readLine()) != null) {
        if (StringUtils.isWhitespace(buffer))
            continue;
        String[] split = buffer.split(";");
        String text = split[0].trim();

        List<Answer> answerList = new ArrayList<>();
        for (int i = 1; i < split.length; i++) {
            Answer answer = new Answer();
            answer.setValue(split[i].trim());
            answerList.add(answer);
        }
        Question q = new Question(text, new Statistics(), answerList, initWeight);

        LOGGER.debug("Reading question \'{}\'; weight \'{}\'.", q.getText(), q.getWeight());
        if (!questionSet.add(q)) {
            LOGGER.warn("Question \'{}\' already in dataset, adding as an answer.", q.getText());
            Iterator<Question> descIter = questionSet.descendingIterator(); // Descending iterator, because it's probably last
            while (descIter.hasNext()) {
                Question current = descIter.next();
                if (current.equals(q)) {
                    current.getAnswerList().addAll(q.getAnswerList());
                    break;
                }
            }
        }
    }
    dataset.setQuestionSet(questionSet);
    dataset.setFinishedSet(new TreeSet<Question>());

    br.close();
    return dataset;
}

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

/**
 * Set the manufacturer for this metadata.
 * The manufacturer may be null to remove this value from the metadata. If not null,
 * the manufacturer MUST NOT be an empty string or whitespace only.
 *
 * @param manufacturer Manufacturer name
 *///from w  ww.jav a  2 s  . com
public void setManufacturer(String manufacturer) {
    if (StringUtils.isWhitespace(manufacturer)) {
        throw new IllegalArgumentException("Manufacturer must not be empty or whitespace only");
    }

    this.manufacturer = manufacturer;
}

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

/**
 * Set the information string 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 Information string
 *//*  w w w  . j  av a2  s. c o m*/
public void setInformation(String information) {
    if (StringUtils.isWhitespace(information)) {
        throw new IllegalArgumentException("Information must not be whitespace only");
    }

    this.information = information;
}

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

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

    this.model = model;
}

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

/**
 * Set the type string for this metadata.
 * The type may be null to remove this value from the metadata. If not null,
 * the type MUST NOT be an empty string or whitespace only.
 *
 * @param type Type string//from  ww  w . ja  v  a2s.  c  om
 */
public void setType(String type) {
    if (StringUtils.isWhitespace(type)) {
        throw new IllegalArgumentException("Type must not be whitespace only");
    }

    this.type = type;
}

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

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

    this.os = os;
}