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.obiba.mica.core.domain.AttributeKey.java

public static String getMapKey(String name, @Nullable String namespace) {
    return Strings.isNullOrEmpty(namespace) ? name : namespace + "__" + name;
}

From source file:uapi.helper.StringHelper.java

public static String makeString(String str, Object... args) {
    if (Strings.isNullOrEmpty(str)) {
        return str;
    }//w  ww. j  a va2  s.  com
    StringBuilder buffer = new StringBuilder();
    boolean foundVarStart = false;
    int idxVar = 0;
    int tmpIdx = -1;
    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        if (c == VAR_START) {
            foundVarStart = true;
        } else if (c == VAR_END) {
            if (foundVarStart) {
                if (tmpIdx != -1) {
                    idxVar = tmpIdx;
                }
                if (args.length <= idxVar) {
                    throw new IllegalArgumentException("The argument index is more than argument count - " + str
                            + "," + CollectionHelper.asString(args));
                }
                buffer.append(args[idxVar]);
                foundVarStart = false;
                idxVar++;
                tmpIdx = -1;
            } else {
                buffer.append(c);
            }
        } else {
            if (foundVarStart) {
                if (c >= '0' && c <= '9') {
                    if (tmpIdx == -1) {
                        tmpIdx = 0;
                    }
                    tmpIdx = tmpIdx * 10 + Character.getNumericValue(c);
                } else {
                    buffer.append(VAR_START);
                    if (tmpIdx != -1) {
                        buffer.append(tmpIdx);
                        tmpIdx = -1;
                    } else {
                        buffer.append(c);
                    }
                    foundVarStart = false;
                }
            } else {
                buffer.append(c);
            }
        }
    }
    return buffer.toString();
}

From source file:org.xacml4j.v30.types.RFC822NameExp.java

public static RFC822NameExp of(String v) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(v));
    return new RFC822NameExp(RFC822Name.parse(v));
}

From source file:org.glowroot.agent.BaseDir.java

public static File getBaseDir(@Nullable String baseDirPath, @Nullable File glowrootJarFile) {
    if (glowrootJarFile == null) {
        // this is only for test support
        checkNotNull(baseDirPath, "Property base.dir is required when no glowroot jar file");
        return new File(baseDirPath);
    }/*from  ww  w.j av a  2 s. com*/
    // empty check to support parameterized script, e.g. -Dglowroot.base.dir=${somevar}
    if (Strings.isNullOrEmpty(baseDirPath)) {
        return getDefaultBaseDir(glowrootJarFile);
    }
    File baseDir = new File(baseDirPath);
    if (!baseDir.isAbsolute()) {
        return getRelativeBaseDir(baseDirPath, glowrootJarFile);
    }
    return getAbsoluteBaseDir(baseDir);
}

From source file:br.cic.unb.chord.util.ReflectionUtil.java

public static Object newInstance(String clazz) {
    checkState(!Strings.isNullOrEmpty(clazz));

    try {/*from www  .java  2 s . c o m*/
        return Class.forName(clazz).newInstance();
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
}

From source file:de.dominikschadow.duke.encounters.enums.Likelihood.java

public static Likelihood fromString(String value) {
    if (!Strings.isNullOrEmpty(value)) {
        for (Likelihood l : Likelihood.values()) {
            if (value.equals(l.toString())) {
                return l;
            }/* www  . ja  va2s  .  c o  m*/
        }
    }

    throw new IllegalArgumentException("No enum found for " + value);
}

From source file:org.onehippo.cms7.essentials.dashboard.utils.PayloadUtils.java

public static List<String> extractValueList(final String value) {
    if (Strings.isNullOrEmpty(value)) {
        return Collections.emptyList();
    }/*w w  w  . j av  a 2s .  c o  m*/
    final Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults();
    final Iterable<String> iterable = splitter.split(value);
    return Lists.newArrayList(iterable);
}

From source file:org.apache.isis.schema.utils.jaxbadapters.JodaDateTimeStringAdapter.java

public static DateTime parse(final String date) {
    return !Strings.isNullOrEmpty(date) ? formatter.parseDateTime(date) : null;
}

From source file:local.laer.app.newgenerator.ExtensionBuilder.java

public static String defaultExtension(TileSection section) {
    String headlineExt = (section.getHeadline() == null) ? "nohead" : null;
    String contentExt = (section.getContent() == null) ? "notext" : null;
    String resourceExt = Optional.ofNullable(section.getResources()).map(Map::keySet)
            .map(set -> String.join("-", set)).orElse(null);

    String ext = Lists.newArrayList(headlineExt, contentExt, resourceExt).stream().filter(e -> e != null)
            .collect(Collectors.joining("-"));

    if (Strings.isNullOrEmpty(ext)) {
        return "normal";
    } else {/* www . ja  v a 2 s. c o  m*/
        return ext;
    }
}

From source file:net.minecraftforge.fml.common.versioning.VersionParser.java

public static ArtifactVersion parseVersionReference(String labelledRef) {
    if (Strings.isNullOrEmpty(labelledRef)) {
        throw new RuntimeException(String.format("Empty reference %s", labelledRef));
    }//from  ww w  .  jav  a  2 s. c o  m
    List<String> parts = Lists.newArrayList(SEPARATOR.split(labelledRef));
    if (parts.size() > 2) {
        throw new RuntimeException(String.format("Invalid versioned reference %s", labelledRef));
    }
    if (parts.size() == 1) {
        return new DefaultArtifactVersion(parts.get(0), true);
    }
    return new DefaultArtifactVersion(parts.get(0), parseRange(parts.get(1)));
}