Example usage for com.google.common.base Strings isNullOrEmpty

List of usage examples for com.google.common.base Strings isNullOrEmpty

Introduction

In this page you can find the example usage for com.google.common.base Strings isNullOrEmpty.

Prototype

public static boolean isNullOrEmpty(@Nullable String string) 

Source Link

Document

Returns true if the given string is null or is the empty string.

Usage

From source file:org.imsglobal.caliper.validators.SensorValidator.java

/**
 * Check if Sensor identifier is null or empty.
 * @param id/*w w w  .  j  av  a 2 s  .  c o  m*/
 * @throws IllegalArgumentException
 */
public static void checkSensorId(String id) throws IllegalArgumentException {
    checkArgument(!(Strings.isNullOrEmpty(id)), "Sensor identifier must be specified");
}

From source file:com.codeabovelab.dm.common.kv.KvUtils.java

/**
 * Utility which correct join path components. <p/>
 * Accept any '/component/' with or without '/' at ends and join they in correct '/component1/component2/.../componentN/' path.
 * @param components//  www.j  a  va  2  s  . c om
 * @return
 */
public static String join(String... components) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < components.length; ++i) {
        String component = components[i];
        if (Strings.isNullOrEmpty(component)) {
            throw new IllegalArgumentException(
                    "Null or empty component at " + i + " in " + Arrays.toString(components));
        }
        final int lastChar = sb.length() - 1;
        if (component.charAt(0) != '/' && (lastChar < 0 || sb.charAt(lastChar) != '/')) {
            sb.append('/');
        }
        sb.append(component);
    }
    if (sb.length() > 0 && sb.charAt(sb.length() - 1) != '/') {
        sb.append('/');
    }
    return sb.toString();
}

From source file:org.apache.isis.core.progmodel.facets.object.encodeable.EncoderDecoderUtil.java

static String encoderDecoderNameFromConfiguration(final Class<?> type, final IsisConfiguration configuration) {
    final String key = ENCODER_DECODER_NAME_KEY_PREFIX + type.getCanonicalName()
            + ENCODER_DECODER_NAME_KEY_SUFFIX;
    final String encoderDecoderName = configuration.getString(key);
    return !Strings.isNullOrEmpty(encoderDecoderName) ? encoderDecoderName : null;
}

From source file:th.co.geniustree.intenship.advisor.validator.MobileUniqueValidator.java

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {

    if (Strings.isNullOrEmpty(value)) {
        return true;
    }/*from ww  w  .j av a  2s .  c o m*/
    return studentRepo.findByMobileIgnoreCase(value) == null;
}

From source file:th.co.geniustree.dental.angular.validator.MobileUniqueValidator.java

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {

    if (Strings.isNullOrEmpty(value)) {
        return true;
    }//  w w w .j a  v  a 2 s.  c o m
    return customerRepo.findByMobileIgnoreCase(value) == null;
}

From source file:org.opendaylight.groupbasedpolicy.neutron.mapper.util.Utils.java

/**
 * This implementation does not use nameservice lookups (e.g. no DNS).
 *
 * @param cidr - format must be valid for regex in {@link Ipv4Prefix} or {@link Ipv6Prefix}
 * @return the {@link IpPrefix} having the given cidr string representation
 * @throws IllegalArgumentException - if the argument is not a valid CIDR string
 *//*w w w  . ja va2 s  .c o  m*/
public static IpPrefix createIpPrefix(String cidr) {
    checkArgument(!Strings.isNullOrEmpty(cidr), "Cannot be null or empty.");
    String[] ipAndPrefix = cidr.split("/");
    checkArgument(ipAndPrefix.length == 2, "Bad format.");
    InetAddress ip = InetAddresses.forString(ipAndPrefix[0]);
    if (ip instanceof Inet4Address) {
        return new IpPrefix(new Ipv4Prefix(cidr));
    }
    return new IpPrefix(new Ipv6Prefix(cidr));
}

From source file:intelligent.wiki.editor.io_impl.wiki.template_data.TemplateParameterBuilder.java

/**
 * Start point of template parameter creation. Note, that it is necessary
 * to set parameter name, so {@link IllegalArgumentException} will be
 * thrown if method argument is <code>null</code> or empty.
 *
 * @param name name of template parameter
 * @return builder object//from  w w w.j  a  v a  2s . c o m
 * @throws IllegalArgumentException if parameter is null or empty
 */
public static TemplateParameterBuilder parameterWithName(String name) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(name));

    TemplateParameterBuilder builder = new TemplateParameterBuilder();
    builder.name = name;
    return builder;
}

From source file:org.sonar.db.purge.period.KeepWithVersionFilter.java

private static boolean isDeletable(PurgeableAnalysisDto snapshot) {
    return !snapshot.isLast() && Strings.isNullOrEmpty(snapshot.getVersion());
}

From source file:com.google.api.tools.framework.snippet.Values.java

/**
 * Determines whether a value is 'true', where true is interpreted depending on the values
 * type.//  w  w  w. ja va  2s . co m
 */
@SuppressWarnings("rawtypes")
static boolean isTrue(Object v1) {
    if (v1 instanceof Number) {
        // For numbers, compare with  the default value (zero), which we obtain by
        // creating an array.
        return !Array.get(Array.newInstance(Primitives.unwrap(v1.getClass()), 1), 0).equals(v1);
    }
    if (v1 instanceof Boolean) {
        return (Boolean) v1;
    }
    if (v1 instanceof Doc) {
        return !((Doc) v1).isWhitespace();
    }
    if (v1 instanceof String) {
        return !Strings.isNullOrEmpty((String) v1);
    }
    if (v1 instanceof Iterable) {
        return ((Iterable) v1).iterator().hasNext();
    }
    return false;
}

From source file:org.apache.kylin.metrics.property.JobPropertyEnum.java

public static JobPropertyEnum getByName(String name) {
    if (Strings.isNullOrEmpty(name)) {
        return null;
    }/*from   ww w .  j  a  va  2s .c om*/
    for (JobPropertyEnum property : JobPropertyEnum.values()) {
        if (property.propertyName.equals(name.toUpperCase())) {
            return property;
        }
    }

    return null;
}