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

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

Introduction

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

Prototype

public static String nullToEmpty(@Nullable String string) 

Source Link

Document

Returns the given string if it is non-null; the empty string otherwise.

Usage

From source file:com.google.api.codegen.discovery.Document.java

/**
 * Returns a document constructed from root.
 *
 * @param root the root node to parse.//  w ww .  j a  va  2 s  .  c  o  m
 * @return a document.
 */
public static Document from(DiscoveryNode root) {
    AuthType authType;
    DiscoveryNode scopesNode = root.getObject("auth").getObject("oauth2").getObject("scopes");

    ImmutableList.Builder<String> authScopes = new Builder<>();
    if (scopesNode.isEmpty()) {
        authType = AuthType.API_KEY;
    } else {
        authScopes.addAll(scopesNode.getFieldNames());
        if (scopesNode.has(CLOUD_PLATFORM_SCOPE)) {
            authType = AuthType.ADC;
        } else {
            authType = AuthType.OAUTH_3L;
        }
    }
    String canonicalName = root.getString("canonicalName");
    String description = root.getString("description");
    String id = root.getString("id");
    Map<String, Schema> schemas = parseSchemas(root);
    List<Method> methods = parseMethods(root);
    Collections.sort(methods); // Ensure methods are ordered alphabetically by their ID.
    String ownerDomain = root.getString("ownerDomain");
    String name = root.getString("name");
    if (canonicalName.isEmpty()) {
        canonicalName = name;
    }
    Map<String, List<Method>> resources = parseResources(root);
    String revision = root.getString("revision");
    String rootUrl = root.getString("rootUrl");
    String servicePath = root.getString("servicePath");
    String title = root.getString("title");
    String version = root.getString("version");
    boolean versionModule = root.getBoolean("version_module");

    String baseUrl = root.has("baseUrl") ? root.getString("baseUrl")
            : (rootUrl + Strings.nullToEmpty(root.getString("basePath")));

    Document thisDocument = new AutoValue_Document("", // authInstructionsUrl (only intended to be overridden).
            authScopes.build(), authType, baseUrl, canonicalName, description, "", // discoveryDocUrl (only intended to be overridden).
            id, methods, name, ownerDomain, resources, revision, rootUrl, schemas, servicePath, title, version,
            versionModule);

    for (Schema schema : schemas.values()) {
        schema.setParent(thisDocument);
    }
    for (Method method : methods) {
        method.setParent(thisDocument);
    }
    for (List<Method> resourceMethods : resources.values()) {
        for (Method method : resourceMethods) {
            method.setParent(thisDocument);
        }
    }

    return thisDocument;
}

From source file:fr.da2i.lup1.entity.formation.Member.java

public String getSiret() {
    return Strings.nullToEmpty(siret);
}

From source file:com.notifier.desktop.update.impl.UpdateManagerImpl.java

public Version getLatestVersion() throws IOException {
    try {/*w  w w  .  ja  va2  s.c o m*/
        System.setProperty("java.net.useSystemProxies", Boolean.TRUE.toString());
        Parser parser = new Parser(TAGS_URI.toString());
        NodeList list = parser.parse(new TagNameFilter("li"));
        Version currentLatestVersion = null;
        for (int i = 0; i < list.size(); i++) {
            String value = Strings.nullToEmpty(list.elementAt(i).getFirstChild().getFirstChild().getText());
            if (value.startsWith(Application.ARTIFACT_ID)) {
                int endIndex = value.endsWith("/") ? value.length() - 1 : value.length();
                String versionString = value.substring(Application.ARTIFACT_ID.length() + 1, endIndex);
                Version version = Version.parse(versionString);
                if (currentLatestVersion == null || version.compareTo(currentLatestVersion) > 0) {
                    currentLatestVersion = version;
                }
            }
        }
        latestVersion = currentLatestVersion;
        return currentLatestVersion;
    } catch (ParserException e) {
        throw new IOException("Could not parse tags page", e);
    }
}

From source file:org.sosy_lab.cpachecker.cfa.types.c.CFunctionType.java

@Override
public String toString() {
    return toASTString(Strings.nullToEmpty(getName()), Functions.toStringFunction());
}

From source file:net.monofraps.gradlebukkit.extensions.Bukkit.java

public String getChannel() {
    return Strings.nullToEmpty(channel);
}

From source file:org.activityinfo.ui.client.component.formdesigner.header.HeaderPresenter.java

public void show() {
    headerPanel.getLabel()//from w w  w  .  j a  va2  s. c om
            .setHTML(SafeHtmlUtils.fromString(Strings.nullToEmpty(formDesigner.getFormClass().getLabel())));
    headerPanel.getDescription().setHTML(
            SafeHtmlUtils.fromString(Strings.nullToEmpty(formDesigner.getFormClass().getDescription())));
}

From source file:org.sonar.plugins.scm.tfs.TfsConfiguration.java

public String password() {
    return Strings.nullToEmpty(settings.getString(PASSWORD_PROPERTY_KEY));
}

From source file:de.bund.bfr.knime.ui.StringTextArea.java

public void setValue(String value) {
    getDocument().removeDocumentListener(documentListener);
    setText(Strings.nullToEmpty(value));
    getDocument().addDocumentListener(documentListener);
    textChanged();//from  w  ww .  j  a va 2 s  .  c  o m
}

From source file:com.kegare.caveworld.plugin.mceconomy.ShopProductManager.java

public boolean addShopProduct(ShopProduct product) {
    boolean flag = product == null || product.getProductItem() == null;
    String item = flag ? null : GameData.getItemRegistry().getNameForObject(product.getProductItem().getItem());
    int stack = flag ? -1 : product.getProductItem().stackSize;
    int damage = flag ? -1 : product.getProductItem().getItemDamage();
    int cost = flag ? -1 : product.getcost();

    String name = Integer.toString(getItemProductSize());

    if (flag && !MCEconomyPlugin.shopCfg.hasCategory(name)) {
        return false;
    }//from w  w w.j  a va  2s .c om

    String category = "shop";
    Property prop;
    List<String> propOrder = Lists.newArrayList();

    prop = MCEconomyPlugin.shopCfg.get(name, "item", "");
    prop.setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName())
            .setConfigEntryClass(Config.selectItemEntryClass);
    prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip");
    if (!Strings.isNullOrEmpty(item))
        prop.set(item);
    propOrder.add(prop.getName());
    item = prop.getString();
    if (!GameData.getItemRegistry().containsKey(Strings.nullToEmpty(item)))
        return false;
    prop = MCEconomyPlugin.shopCfg.get(name, "itemDamage", 0);
    prop.setMinValue(0).setMaxValue(Short.MAX_VALUE)
            .setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName());
    prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip");
    if (damage >= 0)
        prop.set(MathHelper.clamp_int(damage, Integer.parseInt(prop.getMinValue()),
                Integer.parseInt(prop.getMaxValue())));
    propOrder.add(prop.getName());
    damage = MathHelper.clamp_int(prop.getInt(), Integer.parseInt(prop.getMinValue()),
            Integer.parseInt(prop.getMaxValue()));
    prop = MCEconomyPlugin.shopCfg.get(name, "stackSize", 1);
    prop.setMinValue(0).setMaxValue(64).setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName());
    prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip");
    if (stack >= 0)
        prop.set(MathHelper.clamp_int(stack, Integer.parseInt(prop.getMinValue()),
                Integer.parseInt(prop.getMaxValue())));
    propOrder.add(prop.getName());
    stack = MathHelper.clamp_int(prop.getInt(), Integer.parseInt(prop.getMinValue()),
            Integer.parseInt(prop.getMaxValue()));
    prop = MCEconomyPlugin.shopCfg.get(name, "productCost", 10);
    prop.setMinValue(0).setMaxValue(MCEconomyPlugin.Player_MP_MAX)
            .setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName());
    prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip");
    if (cost >= 0)
        prop.set(MathHelper.clamp_int(cost, Integer.parseInt(prop.getMinValue()),
                Integer.parseInt(prop.getMaxValue())));
    propOrder.add(prop.getName());
    cost = MathHelper.clamp_int(prop.getInt(), Integer.parseInt(prop.getMinValue()),
            Integer.parseInt(prop.getMaxValue()));

    MCEconomyPlugin.shopCfg.setCategoryPropertyOrder(name, propOrder);

    if (flag) {
        product = new ShopProduct(new ItemStack(GameData.getItemRegistry().getObject(item), stack, damage),
                cost);
    }

    return SHOP_PRODUCTS.addIfAbsent(product);
}

From source file:com.zimbra.cs.mailbox.Document.java

public String getCreator() {
    return Strings.nullToEmpty(creator);
}