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:co.cask.hydrator.plugin.common.CubeUtils.java

public static Map<String, String> parseAndGetProperties(String property, String propertyValue, String delimiter,
        String fieldDelimiter, Function<String, String> keyFunction) {
    Map<String, String> result = new HashMap<>();
    List<String> fieldGroups = Arrays.asList(propertyValue.split(delimiter));
    for (String group : fieldGroups) {
        String[] split = group.split(fieldDelimiter);
        if (split.length != 2) {
            //should not happen
            throw new IllegalArgumentException(
                    String.format("For Property {} Parameter {} , name or value is empty, please check config",
                            property, group));
        }//from w w  w  .j a  va 2 s.c o m
        if (Strings.isNullOrEmpty(split[0])) {
            throw new IllegalArgumentException(String.format("Empty key/value is not allowed in {}", property));
        }
        if (Strings.isNullOrEmpty(split[1])) {
            throw new IllegalArgumentException(String.format("Empty key/value is not allowed in {}", property));
        }
        result.put(keyFunction.apply(split[0]), split[1]);
    }
    return result;
}

From source file:org.apache.isis.core.metamodel.facets.param.parameter.regex.RegExFacetForParameterAnnotation.java

public static RegExFacet create(final Parameter parameter, final Class<?> parameterType,
        final FacetHolder holder) {

    if (parameter == null) {
        return null;
    }// www  .j  a va2s .  c  o m
    if (!Annotations.isString(parameterType)) {
        return null;
    }

    final String pattern = parameter.regexPattern();
    if (Strings.isNullOrEmpty(pattern)) {
        return null;
    }

    final String replacement = parameter.regexPatternReplacement();
    final int patternFlags = parameter.regexPatternFlags();

    return new RegExFacetForParameterAnnotation(pattern, patternFlags, holder, replacement);
}

From source file:org.apache.isis.core.metamodel.facets.properties.property.regex.RegExFacetForPropertyAnnotation.java

public static RegExFacet create(final Property annotation, final Class<?> returnType,
        final FacetHolder holder) {

    if (annotation == null) {
        return null;
    }/*from ww  w  .  j a  v  a  2s  .  c  om*/

    if (!Annotations.isString(returnType)) {
        return null;
    }

    final String pattern = annotation.regexPattern();
    if (Strings.isNullOrEmpty(pattern)) {
        return null;
    }

    final String replacement = annotation.regexPatternReplacement();
    final int patternFlags = annotation.regexPatternFlags();

    return new RegExFacetForPropertyAnnotation(pattern, patternFlags, holder, replacement);
}

From source file:com.google.devtools.depan.filesystem.eclipse.FileSystemNodePainter.java

private static final Color getColor(String key) {
    String colorTxt = prefs.getString(key);
    if (Strings.isNullOrEmpty(colorTxt)) {
        return Color.BLACK;
    }//from www  .j  a v a2  s.c o  m

    return Colors.getRgb(colorTxt);
}

From source file:com.enonic.cms.core.search.facet.model.AbstractFacetModel.java

public void validate() {
    if (Strings.isNullOrEmpty(this.name)) {
        throw new FacetQueryException("Facet must specify name");
    }//  www . ja v  a2s  .  co m
}

From source file:com.infinities.keystone4j.KeystonePreconditions.java

public static void requireMatchingId(String id, BaseEntity entity) {
    if (!Strings.isNullOrEmpty(entity.getId()) && !id.equals(entity.getId())) {
        throw new BadRequestException(REQUIRE_MATCHING_ID);

    }/* w  w  w  .j  a va 2 s . c o  m*/
}

From source file:com.infinities.skyport.distributed.impl.hazelcast.hazeltask.Hazeltask.java

public synchronized static HazeltaskInstance newHazeltaskInstance(String topologyName,
        HazelcastInstance hazelcast, PoolConfig poolConfig, ScheduledExecutorService scheduler,
        ServiceProvider serviceProvider) {
    if (Strings.isNullOrEmpty(topologyName)) {
        throw new NullPointerException(topologyName);
    }//w  w  w.j  a  va  2  s.c o  m
    HazeltaskInstance instance = instances.get(topologyName);
    if (instance == null) {
        checkNotNull(hazelcast, "invalid hazelcast");
        checkNotNull(poolConfig, "invalid poolConfig");
        checkNotNull(scheduler, "invalid scheduler");
        checkNotNull(serviceProvider, "invalid service provider");
        instance = new HazeltaskInstance(topologyName, hazelcast, poolConfig, scheduler, serviceProvider);
        if (instances.putIfAbsent(instance.getTopologyName(), instance) != null) {
            throw new IllegalStateException("An instance for the name " + topologyName + " already exists!");
        }
        instance.start();
    }

    return instance;
}

From source file:org.apache.james.core.User.java

public static User fromUsername(String username) {
    Preconditions.checkNotNull(username);
    Preconditions.checkArgument(!Strings.isNullOrEmpty(username));

    List<String> parts = ImmutableList.copyOf(Splitter.on('@').split(username));
    switch (parts.size()) {
    case 1://from w  ww  .  j a v  a  2  s  . com
        return fromLocalPartWithoutDomain(username);
    case 2:
        return fromLocalPartWithDomain(parts.get(0), parts.get(1));
    }
    throw new IllegalArgumentException("The username should not contain multiple domain delimiter.");
}

From source file:org.apache.cloudstack.acl.RoleType.java

public static RoleType fromString(final String name) {
    if (!Strings.isNullOrEmpty(name) && Enums.getIfPresent(RoleType.class, name).isPresent()) {
        return RoleType.valueOf(name);
    }/*  ww w .java 2s.  c  om*/
    throw new IllegalStateException("Illegal RoleType name provided");
}

From source file:com.arto.event.util.StringUtil.java

public static String checkSize(Object obj, int maxSize) throws Exception {
    if (obj == null)
        return "";

    String value = "";
    if (obj instanceof String) {
        value = (String) obj;//from   ww  w.ja  va 2  s  . co  m
    } else {
        value = toJsonString(obj);
    }

    if (Strings.isNullOrEmpty(value) || maxSize <= 0) {
        return value;
    }

    if (value.getBytes("utf-8").length <= maxSize) {
        return value;
    }
    throw new Exception("String size over max size. string:" + value + ", max size:" + maxSize);
}