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

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

Introduction

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

Prototype

@Nullable
public static String emptyToNull(@Nullable String string) 

Source Link

Document

Returns the given string if it is nonempty; null otherwise.

Usage

From source file:com.salesforce.jprotoc.ProtoTypeMap.java

/**
 * Returns an instance of {@link ProtoTypeMap} based on the given {@link DescriptorProtos.FileDescriptorProto}
 * instances.// ww w .ja  va2 s  .com
 *
 * @param fileDescriptorProtos the full collection of files descriptors from the code generator request
 */
public static ProtoTypeMap of(@Nonnull Collection<DescriptorProtos.FileDescriptorProto> fileDescriptorProtos) {
    Preconditions.checkNotNull(fileDescriptorProtos, "fileDescriptorProtos");
    Preconditions.checkArgument(!fileDescriptorProtos.isEmpty(), "fileDescriptorProtos.isEmpty()");

    final ImmutableMap.Builder<String, String> types = ImmutableMap.builder();

    for (final DescriptorProtos.FileDescriptorProto fileDescriptor : fileDescriptorProtos) {
        final DescriptorProtos.FileOptions fileOptions = fileDescriptor.getOptions();

        final String protoPackage = fileDescriptor.hasPackage() ? "." + fileDescriptor.getPackage() : "";
        final String javaPackage = Strings.emptyToNull(
                fileOptions.hasJavaPackage() ? fileOptions.getJavaPackage() : fileDescriptor.getPackage());
        final String enclosingClassName = fileOptions.getJavaMultipleFiles() ? null
                : getJavaOuterClassname(fileDescriptor, fileOptions);

        fileDescriptor.getEnumTypeList().forEach(e -> types.put(protoPackage + "." + e.getName(),
                toJavaTypeName(e.getName(), enclosingClassName, javaPackage)));

        fileDescriptor.getMessageTypeList().forEach(m -> types.put(protoPackage + "." + m.getName(),
                toJavaTypeName(m.getName(), enclosingClassName, javaPackage)));
    }

    return new ProtoTypeMap(types.build());
}

From source file:com.google.gitiles.doc.IframeNode.java

IframeNode(String src, String height, String width, String border) {
    this.src = src;
    this.height = Strings.emptyToNull(height);
    this.width = Strings.emptyToNull(width);
    this.border = !"0".equals(border);
}

From source file:org.obm.sync.utils.DisplayNameUtils.java

public static String getDisplayName(String commonName, String firstName, String lastName) {
    if (!Strings.isNullOrEmpty(commonName)) {
        return commonName;
    } else {/*from   w  w  w  .  j a v  a  2  s  . c  o m*/
        return Joiner.on(' ').skipNulls().join(Strings.emptyToNull(firstName), Strings.emptyToNull(lastName));
    }
}

From source file:com.google.gerrit.pgm.init.AllProjectsNameOnInitProvider.java

@Inject
AllProjectsNameOnInitProvider(Section.Factory sections) {
    String n = sections.get("gerrit", null).get("allProjects");
    name = Objects.firstNonNull(Strings.emptyToNull(n), AllProjectsNameProvider.DEFAULT);
}

From source file:com.google.gerrit.pgm.init.api.AllProjectsNameOnInitProvider.java

@Inject
AllProjectsNameOnInitProvider(Section.Factory sections) {
    String n = sections.get("gerrit", null).get("allProjects");
    name = MoreObjects.firstNonNull(Strings.emptyToNull(n), AllProjectsNameProvider.DEFAULT);
}

From source file:org.apache.isis.core.metamodel.facets.actions.layout.NotContributedFacetForLayoutProperties.java

private static Contributed contributing(final Properties properties) {
    if (properties == null) {
        return null;
    }// w w w  .  j av  a  2s .  c  o  m
    String contributing = Strings.emptyToNull(properties.getProperty("contributing"));
    if (contributing == null) {
        // alternate key
        contributing = Strings.emptyToNull(properties.getProperty("contributed"));
    }
    return contributing != null ? Contributed.valueOf(contributing) : null;
}

From source file:org.n52.shetland.ogc.ows.OwsDomainMetadata.java

public OwsDomainMetadata(URI reference, String value) {
    this.reference = reference;
    this.value = Strings.emptyToNull(value);
}

From source file:org.jboss.hal.client.logging.LogConfiguration.java

private static void setLevels(java.util.logging.Logger l) {
    Level level = null;//from   ww w  . j  a  v a 2  s.c  o m
    String levelParam = Window.Location.getParameter("logLevel");

    if (Strings.emptyToNull(levelParam) != null) {
        String safeLevelParam = levelParam.toUpperCase();
        if (KNOWN_LEVELS.containsKey(safeLevelParam)) {
            level = KNOWN_LEVELS.get(safeLevelParam);
        } else {
            console.error(
                    "Unable to parse log level '" + levelParam + "'. " + "Fall back to " + DEFAULT_LEVEL + ".");
        }
    } else {
        DefaultLevel defaultLevel = GWT.create(DefaultLevel.class);
        level = defaultLevel.getLevel();
    }
    if (level == null) {
        level = DEFAULT_LEVEL;
    }

    l.setLevel(level);
}

From source file:com.google.gerrit.pgm.init.AllUsersNameOnInitProvider.java

@Inject
AllUsersNameOnInitProvider(Section.Factory sections) {
    String n = sections.get("gerrit", null).get("allUsers");
    name = MoreObjects.firstNonNull(Strings.emptyToNull(n), AllUsersNameProvider.DEFAULT);
}

From source file:com.clank.launcher.auth.Account.java

/**
 * Set the account's stored password, that may be stored to disk.
 *
 * @param password the password//from w  w w  .  j av  a  2s.  c o  m
 */
public void setPassword(String password) {
    if (password != null && password.isEmpty()) {
        password = null;
    }
    this.password = Strings.emptyToNull(password);
}