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.gerrit.metrics.proc.ProcMetricModule.java

private void buildLabel(MetricMaker metrics) {
    metrics.newConstantMetric("build/label", Strings.nullToEmpty(Version.getVersion()),
            new Description("Version of Gerrit server software"));
}

From source file:io.macgyver.plugin.cloud.aws.scanner.SecurityGroupScanner.java

@Override
public void scan(Region region) {

    AmazonEC2Client client = getAWSServiceClient().createEC2Client(region.getName());

    DescribeSecurityGroupsResult result = client.describeSecurityGroups();

    long now = System.currentTimeMillis();
    GraphNodeGarbageCollector gc = newGarbageCollector().region(region).label("AwsSecurityGroup");
    result.getSecurityGroups().forEach(sg -> {

        ObjectNode g = convertAwsObject(sg, region);

        // non-VPC security groups don't have a VPC
        String vpcId = Strings.nullToEmpty(sg.getVpcId());
        String cypher = "merge (sg:AwsSecurityGroup {aws_account: {a}, aws_region: {r}, aws_vpcId: {vpcId}, aws_groupId: {groupId}}) set sg+={props}, sg.updateTs={now} return sg";

        JsonNode xx = getNeoRxClient().execCypher(cypher, "vpcId", vpcId, "groupId", sg.getGroupId(), "props",
                g, "now", now, "a", getAccountId(), "r", region.getName()).toBlocking().first();

        gc.updateEarliestTimestamp(xx);/*from   ww  w .j a va 2 s. c om*/
        if (!vpcId.isEmpty()) {
            cypher = "match (v:AwsVpc {aws_vpcId: {vpcId}}), (sg:AwsSecurityGroup {aws_groupId:{groupId}, aws_vpcId: {vpcId}}) merge (sg)-[:RESIDES_IN]->(v)";
            getNeoRxClient().execCypher(cypher, "vpcId", vpcId, "groupId", sg.getGroupId());
        }
    });

    gc.invoke();

}

From source file:org.jclouds.virtualbox.util.MachineNameOrIdAndNicSlot.java

public static MachineNameOrIdAndNicSlot fromString(String machineNameOrIdAndNicSlotString) {
    Iterable<String> splittedString = Splitter.on(SEPARATOR).split(machineNameOrIdAndNicSlotString);
    checkState(Iterables.size(splittedString) == 2);
    String machineNameOrId = Strings.nullToEmpty(Iterables.get(splittedString, 0));
    String nicSlotString = Strings.nullToEmpty(Iterables.get(splittedString, 1));
    checkArgument(!nicSlotString.startsWith("+"), "Unparseable slot number: %s", nicSlotString);
    try {/*from w  w  w. ja  v  a2  s  .co  m*/
        long slot = Long.parseLong(nicSlotString);
        checkArgument(isValidSlot(slot), "Slot number out of range: %s", nicSlotString);
        return new MachineNameOrIdAndNicSlot(machineNameOrId, slot);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Unparseable slot number: " + nicSlotString);
    }
}

From source file:com.googlesource.gerrit.plugins.websession.flatfile.Module.java

@Provides
@Singleton/* w ww .  j a v  a 2  s  .c om*/
@CleanupInterval
Long getCleanupInterval(PluginConfigFactory cfg, @PluginName String pluginName) {
    String fromConfig = Strings.nullToEmpty(cfg.getFromGerritConfig(pluginName).getString("cleanupInterval"));
    return HOURS.toMillis(ConfigUtil.getTimeUnit(fromConfig, DEFAULT_CLEANUP_INTERVAL, HOURS));
}

From source file:com.axmor.eclipse.typescript.editor.rename.RenameInputPage.java

@Override
public void createControl(Composite parent) {
    Composite composite = createRootComposite(parent);
    setControl(composite);//www . j  a  va 2 s  .  com
    new Label(composite, SWT.NONE).setText("New name:");
    newName = new Text(composite, SWT.BORDER);
    newName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    newName.setText(Strings.nullToEmpty(info.getOldName()));
    newName.selectAll();
    newName.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            info.setNewName(newName.getText());
            validate();
        }
    });

    validate();
}

From source file:io.druid.query.extraction.LookupExtractionFn.java

@JsonCreator
public LookupExtractionFn(@JsonProperty("lookup") final LookupExtractor lookup,
        @JsonProperty("retainMissingValue") final boolean retainMissingValue,
        @Nullable @JsonProperty("replaceMissingValueWith") final String replaceMissingValueWith,
        @JsonProperty("injective") final boolean injective) {
    super(new Function<String, String>() {
        @Nullable//w  w  w  .ja  v  a  2 s. co m
        @Override
        public String apply(String input) {
            return lookup.apply(Strings.nullToEmpty(input));
        }
    }, retainMissingValue, replaceMissingValueWith, injective);
    this.lookup = lookup;
}

From source file:net.dries007.holoInventory.util.InventoryData.java

public InventoryData(IInventory te, int id) {
    this.id = id;
    this.te = te;
    this.name = Strings.nullToEmpty(te.getName());
    this.type = te.getClass().getCanonicalName();
    if (type == null)
        type = te.getClass().getName();/*w  w  w.j a v a 2 s .  com*/
}

From source file:org.jag.plmxml.service.PlmxmlMapperBean.java

@Override
public Category map(final CategoryPlmxml source, final String definitionLocation) {
    final Category category = new Category(source.getName());
    category.setDescription(Strings.nullToEmpty(source.getDescription()));
    for (final PreferencePlmxml preference : source.getPreferences()) {
        category.add(map(preference, definitionLocation));
    }/*  w w  w .  ja va2 s. c  om*/

    return category;
}

From source file:org.lendingclub.mercator.aws.SecurityGroupScanner.java

@Override
protected void doScan() {

    DescribeSecurityGroupsResult result = getClient().describeSecurityGroups();

    long now = System.currentTimeMillis();
    GraphNodeGarbageCollector gc = newGarbageCollector().bindScannerContext();
    result.getSecurityGroups().forEach(sg -> {

        try {//w ww.  j  a va  2  s . c om

            ObjectNode g = convertAwsObject(sg, getRegion());

            // non-VPC security groups don't have a VPC
            String vpcId = Strings.nullToEmpty(sg.getVpcId());
            String cypher = "merge (sg:AwsSecurityGroup {aws_arn:{arn}}) set sg+={props}, sg.updateTs={now} return sg";

            JsonNode xx = getNeoRxClient()
                    .execCypher(cypher, "arn", g.path(AWS_ARN_ATTRIBUTE).asText(), "props", g, "now", now)
                    .blockingFirst();
            getShadowAttributeRemover().removeTagAttributes("AwsSecurityGroup", g, xx);
            gc.updateEarliestTimestamp(xx);
            if (!vpcId.isEmpty()) {
                cypher = "match (v:AwsVpc {aws_vpcId: {vpcId}}), (sg:AwsSecurityGroup {aws_arn:{sg_arn}}) merge (sg)-[:RESIDES_IN]->(v)";
                getNeoRxClient().execCypher(cypher, "vpcId", vpcId, "sg_arn", g.path("aws_arn").asText());
            }
            incrementEntityCount();
        } catch (RuntimeException e) {
            maybeThrow(e, "problem scanning security groups");
        }
    });

}

From source file:com.skcraft.launcher.model.modpack.Manifest.java

@JsonIgnore
public URL getObjectsUrl() {
    if (Strings.nullToEmpty(getObjectsLocation()) == null) {
        return baseUrl;
    }/*from w  ww.  j  av a  2 s . c om*/

    try {
        return LauncherUtils.concat(baseUrl, Strings.nullToEmpty(getObjectsLocation()) + "/");
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}