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:li.klass.fhem.util.ValueExtractUtil.java

static String extractLeadingNumericText(String text, int digits) {
    if (Strings.isNullOrEmpty(text))
        return "";
    String numericText = new LeadingNumericTextExtractor(text).numericText();

    if (digits > 0) {
        double number = Double.valueOf(numericText);
        double roundFactor = Math.pow(10, digits);
        double rounded = ((int) (number * roundFactor)) / roundFactor;

        return rounded + "";
    } else {/*  w  w  w  .  j  a  v a  2s .  c  o m*/
        return numericText;
    }
}

From source file:org.eclipse.recommenders.utils.rcp.UUIDHelper.java

private static Optional<String> lookupUUIDFromStore() {
    final RecommendersUtilsPlugin plugin = RecommendersUtilsPlugin.getDefault();
    final IPreferenceStore prefStore = plugin.getPreferenceStore();
    final String uuid = prefStore.getString(PreferencesInitalizer.PROP_UUID);
    if (Strings.isNullOrEmpty(uuid)) {
        return Optional.absent();
    }//w ww  .  j a  va2s  . c  o m
    return Optional.fromNullable(uuid);
}

From source file:com.google.api.codegen.util.Name.java

/**
 * Creates a Name from a sequence of lower-underscore strings.
 *
 * @throws IllegalArgumentException if any of the strings contain any characters that are not
 *     lower case or underscores.//ww w .ja v a  2 s .c om
 */
public static Name from(String... pieces) {
    List<NamePiece> namePieces = new ArrayList<>();
    for (String piece : pieces) {
        if (Strings.isNullOrEmpty(piece)) {
            continue;
        }
        validateLowerUnderscore(piece);
        namePieces.add(new NamePiece(piece, CaseFormat.LOWER_UNDERSCORE));
    }
    return new Name(namePieces);
}

From source file:org.apache.druid.common.utils.UUIDUtils.java

/**
 * Generates a universally unique identifier.
 *
 * @param extraData Extra data which often takes the form of debugging information
 *
 * @return A string which is a universally unique id (as determined by java.util.UUID) with extra data. It does not conform to a UUID variant standard.
 */// w w  w  . jav  a2s .c  o  m
public static String generateUuid(String... extraData) {
    String extra = null;
    if (extraData != null && extraData.length > 0) {
        final ArrayList<String> extraStrings = new ArrayList<>(extraData.length);
        for (String extraString : extraData) {
            if (!Strings.isNullOrEmpty(extraString)) {
                extraStrings.add(extraString);
            }
        }
        if (!extraStrings.isEmpty()) {
            extra = Joiner.on(UUID_DELIM).join(extraStrings);
        }
    }
    // We don't use "-" in general, so remove them here.
    final String uuid = StringUtils.removeChar(UUID.randomUUID().toString(), '-');
    return extra == null ? uuid : (extra + UUID_DELIM + uuid);
}

From source file:org.obiba.opal.web.gwt.app.client.fs.FileDtos.java

public static FileDto user(String name) {
    return Strings.isNullOrEmpty(name) ? users() : create("home", name);
}

From source file:org.sonar.server.util.Validation.java

public static void checkMandatorySizeParameter(String value, String paramName, Integer size) {
    checkMandatoryParameter(value, paramName);
    if (!Strings.isNullOrEmpty(value) && value.length() > size) {
        throw new BadRequestException(Validation.IS_TOO_LONG_MESSAGE, paramName, size);
    }/*from  w w  w  . j  a  va  2 s  .co  m*/
}

From source file:org.apache.drill.exec.store.SchemaConfig.java

public static Builder newBuilder(final String userName, final QueryContext queryContext) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(userName), "A valid userName is expected");
    Preconditions.checkNotNull(queryContext, "Non-null QueryContext is expected");
    return new Builder(userName, queryContext);
}

From source file:br.com.tecsinapse.exporter.converter.YearMonthTableCellConverter.java

@Override
public YearMonth apply(String input) {
    return Strings.isNullOrEmpty(input) ? null : YearMonth.parse(input, YYYY_MM);
}

From source file:org.graylog2.grok.GrokPatterns.java

public static GrokPattern fromSummary(GrokPatternSummary grokPatternSummary) {
    final GrokPattern result = new GrokPattern();
    if (!Strings.isNullOrEmpty(grokPatternSummary.id))
        result.id = new ObjectId(grokPatternSummary.id);
    result.name = grokPatternSummary.name;
    result.pattern = grokPatternSummary.pattern;

    return result;
}

From source file:nxminetilities.modules.AdditionalFacades.java

public static void LoadFacades(String facadeIdList) {
    Set<Integer> facadeBlockIds = Sets.newHashSet();
    for (String id : facadeIdList.trim().split("\\s*,\\s*")) {
        try {/*from ww  w.  ja  v a  2 s .c o m*/
            facadeBlockIds.add(Integer.parseInt(id));
        } catch (Exception e) {
            continue;
        }
    }

    // Add nxMinetilities blocks
    if (Minetilities.bColouredStone.blockID != 0) {
        facadeBlockIds.add(Minetilities.bColouredStone.blockID);
    }
    if (Minetilities.bColouredBrick.blockID != 0) {
        facadeBlockIds.add(Minetilities.bColouredBrick.blockID);
    }
    if (Minetilities.bColouredChiselledStone.blockID != 0) {
        facadeBlockIds.add(Minetilities.bColouredChiselledStone.blockID);
    }

    for (int blockId : facadeBlockIds) {
        ItemStack is = new ItemStack(blockId, 1, -1);

        try {
            if (is.getHasSubtypes()) {
                Set<String> names = Sets.newHashSet();
                for (int meta = 0; meta < 15; meta++) {
                    ItemStack metaIs = new ItemStack(blockId, 1, meta);
                    if (!Strings.isNullOrEmpty(metaIs.getItemName()) && names.add(metaIs.getItemName())) {
                        FacadeHelper.addBuildcraftFacade(metaIs);
                        facadeCount++;
                    }
                }
            } else {
                FacadeHelper.addBuildcraftFacade(is);
                facadeCount++;
            }
        } catch (Exception e) {
            Minetilities.nxLog.severe("[AdditionalFacades] ERROR! Exception thrown adding block: " + blockId);
        }
    }

    Minetilities.nxLog.info("[AdditionalFacades] Successfully added " + facadeCount + " facades.");
}