Example usage for org.springframework.util Assert hasText

List of usage examples for org.springframework.util Assert hasText

Introduction

In this page you can find the example usage for org.springframework.util Assert hasText.

Prototype

public static void hasText(@Nullable String text, Supplier<String> messageSupplier) 

Source Link

Document

Assert that the given String contains valid text content; that is, it must not be null and must contain at least one non-whitespace character.

Usage

From source file:com.joyveb.dbpimpl.cass.prepare.util.ParsingUtils.java

public static void setPropertyValue(BeanDefinitionBuilder builder, Element element, String attrName,
        String propertyName) {/*  www . j  a va 2 s. c o  m*/

    Assert.notNull(builder, "BeanDefinitionBuilder must not be null");
    Assert.notNull(element, "Element must not be null");
    Assert.hasText(attrName, "Attribute name must not be null");
    Assert.hasText(propertyName, "Property name must not be null");

    String attr = element.getAttribute(attrName);

    if (StringUtils.hasText(attr)) {
        builder.addPropertyValue(propertyName, attr);
    }
}

From source file:example.springdata.cassandra.util.CassandraSocket.java

/**
 * @param host must not be {@literal null} or empty.
 * @param port/*ww  w. jav a2 s  .c om*/
 * @return {@literal true} if the TCP port accepts a connection.
 */
public static boolean isConnectable(String host, int port) {

    Assert.hasText(host, "Host must not be null or empty!");

    try (Socket socket = new Socket()) {

        socket.setSoLinger(true, 0);
        socket.connect(new InetSocketAddress(host, port),
                (int) TimeUnit.MILLISECONDS.convert(10, TimeUnit.SECONDS));

        return true;

    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

/**
 * Checks in under a given root element whether it can find a child element
 * which matches the name supplied. Returns {@link Element} if exists.
 * //from  www .j  a v  a2s  .  c o m
 * @param name the Element name (required)
 * @param root the parent DOM element (required)
 * 
 * @return the Element if discovered
 */
public static Element findFirstElementByName(String name, Element root) {
    Assert.hasText(name, "Element name required");
    Assert.notNull(root, "Root element required");
    return (Element) root.getElementsByTagName(name).item(0);
}

From source file:com.frank.search.solr.core.query.QueryFunction.java

/**
 * @param queryString/* w  ww  . j av  a  2s. c  om*/
 * @return
 */
public static QueryFunction query(String queryString) {
    Assert.hasText(queryString, "Cannot create query function for 'empty' queryString.");

    return query(new SimpleStringCriteria(queryString));
}

From source file:com.azaptree.services.commons.xml.jaxb.JAXBContextCache.java

/**
 * If the JAXBContext is not cached, then it will create a new instance and cache it.
 * // w  ww .j av a  2 s  .  c o  m
 * @param contextPath
 *            REQUIRED
 * @return
 */
public static JAXBContext get(final String contextPath) {
    Assert.hasText(contextPath, "contextPath is required");
    JAXBContext ctx = jaxbContexts.get(contextPath);
    if (ctx == null) {
        try {
            ctx = JAXBContext.newInstance(contextPath);
        } catch (final JAXBException e) {
            throw new IllegalArgumentException(
                    "Failed to create JAXBContext - invalid JAXB context path: " + contextPath, e);
        }
        jaxbContexts.put(contextPath, ctx);
        LoggerFactory.getLogger(JAXBContextCache.class).info("cached : {}", contextPath);
    }
    return ctx;
}

From source file:com.frank.search.solr.core.query.NotFunction.java

/**
 * @param fieldname must not be empty/*w w  w . j a v a 2s  .  c  o  m*/
 * @return
 */
public static NotFunction not(String fieldname) {
    Assert.hasText(fieldname, "Fieldname for not function must not be 'empty'.");

    return new NotFunction(fieldname);
}

From source file:com.frank.search.solr.core.query.DefaultValueFunction.java

/**
 * Creates new {@link DefaultValueFunction} representing {@code def(fieldname, defaultValue))}
 *
 * @param fieldName must not be empty/*from  www . ja va2 s .c  o m*/
 * @param defaultValue must not be null
 * @return
 */
public static DefaultValueFunction defaultValue(String fieldName, Object defaultValue) {
    Assert.hasText(fieldName, "Fieldname must not be 'empty' for default value operation.");
    Assert.notNull(defaultValue, "DefaultValue must not be 'null'.");

    return new DefaultValueFunction(fieldName, defaultValue);
}

From source file:example.app.model.Customer.java

public static Customer newCustomer(String firstName, String lastName) {
    Assert.hasText(firstName, "firstName is required");
    Assert.hasText(lastName, "lastName is required");

    Customer customer = new Customer();

    customer.setFirstName(firstName);//from  ww  w  .  jav  a  2 s .c  o  m
    customer.setLastName(lastName);

    return customer;
}

From source file:com.frank.search.solr.core.query.IfFunction.java

public static Builder when(String fieldname) {
    Assert.hasText(fieldname, "Fieldname cannot be 'null' for if clause.");

    return new Builder(fieldname);
}

From source file:com.frank.search.solr.core.query.ExistsFunction.java

/**
 * Creates new {@link ExistsFunction} representing {@code exists(fieldname)}
 *
 * @param fieldname/*from   w w  w .  j a  va 2  s.  co m*/
 * @return
 */
public static ExistsFunction exists(String fieldname) {
    Assert.hasText(fieldname, "Fieldname cannot be 'empty' for exists operation.");

    return new ExistsFunction(fieldname);
}