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.gbif.api.vocabulary.NamePart.java

/**
 * Case insensitive lookup of a NamePart by its name that does not throw an exception but returns null
 * for a not found NamePart.// ww  w  .  j  a  v  a  2  s .  c  o  m
 *
 * @param namePart case insensitive name of name part
 *
 * @return the matching NamePart or null
 */
public static NamePart fromString(String namePart) {
    if (!Strings.isNullOrEmpty(namePart)) {
        try {
            return valueOf(namePart.toUpperCase().trim());
        } catch (IllegalArgumentException e) {
            // swallow
        }
    }
    return null;
}

From source file:org.retrostore.util.NumUtil.java

/**
 * Parses a long value from a string./*w  w w  .  j  a  v a 2s . c  om*/
 *
 * @param longStr the long value as a string.
 * @return The long value, or absent if the string could not be parsed.
 */
public static Optional<Long> parseLong(String longStr) {
    if (Strings.isNullOrEmpty(longStr)) {
        return Optional.empty();
    }
    try {
        return Optional.of(Long.parseLong(longStr));
    } catch (NumberFormatException ex) {
        LOG.log(Level.SEVERE, "Cannot parse integer", ex);
        return Optional.empty();
    }
}

From source file:org.apache.sqoop.connector.kite.configuration.ConfigUtil.java

/**
 * Returns a dataset uri, including the filesystem location part, if it is
 * provided separated,//  w  w w. j  a va 2 s.  c o  m
 */
public static String buildDatasetUri(String authority, String uri) {
    if (!Strings.isNullOrEmpty(authority) && !uri.contains("://")) {
        URIBuilder builder = new URIBuilder(uri);

        String[] parts = authority.split(":");
        if (parts.length > 0) {
            builder.with("auth:host", parts[0]);
        }
        if (parts.length > 1) {
            builder.with("auth:port", parts[1]);
        }

        return builder.build().toString().replaceFirst("view:", "dataset:");
    }

    return uri;
}

From source file:com.palantir.lock.AtlasCellLockDescriptor.java

/** Returns a {@code LockDescriptor} instance for the given table, row, and column. */
public static LockDescriptor of(String tableName, byte[] rowName, byte[] colName) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(tableName));
    Preconditions.checkNotNull(rowName);
    Preconditions.checkNotNull(colName);
    byte[] tableBytes = tableName.getBytes();
    byte[] bytes = new byte[tableBytes.length + 1 + rowName.length + 1 + colName.length];
    System.arraycopy(tableBytes, 0, bytes, 0, tableBytes.length);
    System.arraycopy(rowName, 0, bytes, tableBytes.length + 1, rowName.length);
    System.arraycopy(colName, 0, bytes, tableBytes.length + 1 + rowName.length + 1, colName.length);
    return new LockDescriptor(bytes);
}

From source file:com.test.config.ConfigurationFactory.java

/**
 * Loads configuration object by file/*from  www  .ja v a2s .c o  m*/
 *
 * @return Returns configuration objects
 */
public static Config load() {
    if (Strings.isNullOrEmpty(System.getProperty("config"))) {
        throw new RuntimeException("Configuration file path is empty. "
                + "Please specify the file path with using -Dconfig=[PATH]");
    }

    com.typesafe.config.Config config = ConfigFactory.parseFile(new File(System.getProperty("config")));

    return ConfigBeanFactory.create(config, Config.class);
}

From source file:com.demonwav.mcdev.platform.MinecraftModuleType.java

public static void addOption(@NotNull Module module, @NotNull String option) {
    String currentOption = module.getOptionValue(OPTION);
    if (Strings.isNullOrEmpty(currentOption)) {
        currentOption = option;//from   w  w w  . j  av a  2s  . co m
    } else {
        if (!currentOption.contains(option)) {
            currentOption += "," + option;
        }
    }
    module.setOption(OPTION, currentOption);
    final MinecraftModule minecraftModule = MinecraftModule.getInstance(module);
    if (minecraftModule != null) {
        final PlatformType[] types = cleanOption(module);
        minecraftModule.updateModules(types);
    }
}

From source file:net.mad.ads.db.enums.ExpirationResolution.java

public static ExpirationResolution forName(String name) {
    if (Strings.isNullOrEmpty(name)) {
        return NONE;
    }//  w w  w .  j a v a  2s.  c  om

    for (ExpirationResolution res : values()) {
        if (res.getName().equalsIgnoreCase(name)) {
            return res;
        }
    }

    return NONE;
}

From source file:preparing.DataReader.java

public static String readLicense(String filePath) {
    StringBuilder res = new StringBuilder();

    try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
        while (reader.ready()) {
            res.append(reader.readLine() + " ");
        }//from w  w  w. j a  va 2s . co  m
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

    if (Strings.isNullOrEmpty(res.toString()) || !res.toString().matches("^.*[A-Za-z]+.*$")) {
        return null;
    }
    return res.toString();
}

From source file:ru.runa.wfe.var.format.FormatCommons.java

private static VariableFormat create(String className, UserType userType) {
    if (userType != null) {
        return new UserTypeFormat(userType);
    }//from  www.j  a v a2  s .c om
    if (Strings.isNullOrEmpty(className)) {
        className = StringFormat.class.getName();
    }
    VariableFormat format = ClassLoaderUtil.instantiate(className);
    if (format instanceof VariableFormatContainer) {
        // see
        // ru.runa.wfe.var.VariableDefinition.initComponentUserTypes(IUserTypeLoader)
    }
    return format;
}

From source file:com.palantir.lock.StringLockDescriptor.java

/** Returns a {@code LockDescriptor} instance for the given lock ID. */
public static LockDescriptor of(String lockId) {
    Preconditions.checkNotNull(lockId);/*from ww w  .  jav a  2s. c o  m*/
    Preconditions.checkArgument(!Strings.isNullOrEmpty(lockId));
    return new LockDescriptor(lockId.getBytes(Charsets.UTF_8));
}