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.streamsets.pipeline.lib.jdbc.JdbcUtil.java

public static boolean isDataError(String connectionString, SQLException ex) {
    String sqlState = Strings.nullToEmpty(ex.getSQLState());
    String errorCode = String.valueOf(ex.getErrorCode());
    if (sqlState.equals(MYSQL_GENERAL_ERROR) && connectionString.contains(":mysql")) {
        return MYSQL_DATA_ERROR_ERROR_CODES.containsKey(errorCode);
    } else if (sqlState.length() >= 2 && STANDARD_DATA_ERROR_SQLSTATES.containsKey(sqlState.substring(0, 2))) {
        return true;
    }//ww  w . ja  v  a2 s  . com
    return false;
}

From source file:net.oneandone.maven.plugins.cycles.CyclesMojo.java

@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
    ComponentAnalyzer componentAnalyzer = new ComponentAnalyzer(classDir, Strings.nullToEmpty(namePrefix),
            shorten, writeDotFiles, packageDepth, showClassDeps);

    try {/*ww w  .  j  av a2  s .com*/
        getLog().info(componentAnalyzer.analyze());
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:com.zimbra.doc.soap.XmlAttributeDescription.java

public String getValueRepresentation() {
    return (valueDescription == null) ? "" : Strings.nullToEmpty(valueDescription.getRepresentation());
}

From source file:com.bodybuilding.turbine.discovery.Ec2InstanceMapper.java

/**
 * Maps a EC2 Instance to a Turbine instance.
 * @param clusterName name of the cluster for this instance
 * @param ec2Instance EC2 instance model
 * @return Turbine instance// w w w  .j a v a  2s . com
 */
public Instance createTurbineInstance(String clusterName,
        com.amazonaws.services.ec2.model.Instance ec2Instance) {
    String hostField = DynamicPropertyFactory.getInstance()
            .getStringProperty("ec2.hostField." + clusterName, null).get();
    if (Strings.isNullOrEmpty(hostField)) {
        hostField = DEFAULT_HOST_FIELD.get();
    }

    hostField = Strings.nullToEmpty(hostField);

    String host;
    if (hostField.equalsIgnoreCase("private_dns")) {
        host = ec2Instance.getPrivateDnsName();
    } else if (hostField.equalsIgnoreCase("private_ip")) {
        host = ec2Instance.getPrivateIpAddress();
    } else if (hostField.equalsIgnoreCase("public_dns")) {
        host = ec2Instance.getPublicDnsName();
    } else if (hostField.equalsIgnoreCase("public_ip")) {
        host = ec2Instance.getPublicIpAddress();
    } else {
        log.warn(
                "{} is not a valid value for property {} it should be one of "
                        + "[private_dns, private_ip, public_dns, public_ip]. Falling back to private_ip",
                hostField, "ec2.hostField");
        host = ec2Instance.getPrivateIpAddress();
    }

    return new Instance(host, clusterName, ec2Instance.getState().getName().equals("running"));
}

From source file:org.jclouds.ec2.xml.TagSetHandler.java

@Override
public void endElement(String uri, String localName, String qName) {
    if (qName.equals("item")) {
        inItem = false;//from w  ww  . java2 s  .  c o  m
        if (key != null) {
            result.put(key, Strings.nullToEmpty(value));
        }
    }
    if (inItem) {
        if (qName.equals("key")) {
            key = currentOrNull(currentText);
        } else if (qName.equals("value")) {
            value = currentOrNull(currentText);
        }
    }
}

From source file:org.activityinfo.server.util.locale.LocaleProvider.java

private String languageFromHeader() {
    String[] acceptLanguages = Strings.nullToEmpty(req.get().getHeader("Accept-Language")).split(",");

    for (String lang : acceptLanguages) {
        if (lang.startsWith("en")) {
            return "en";
        } else if (lang.startsWith("fr")) {
            return "fr";
        }//w w w . j  a  va  2s .co  m
    }
    return null;
}

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

public String getLastName() {
    return Strings.nullToEmpty(lastName);
}

From source file:com.htmlhifive.pitalium.core.selenium.PtlWebDriverFactory.java

/**
 * ??{@link PtlWebDriverFactory}?????/*from  w w  w.j a  v a 2  s  .  com*/
 * 
 * @param capabilities Capability??
 * @return {@link PtlWebDriverFactory}?
 */
public static PtlWebDriverFactory getInstance(PtlCapabilities capabilities) {
    PtlTestConfig config = PtlTestConfig.getInstance();
    EnvironmentConfig environmentConfig = config.getEnvironment();
    TestAppConfig testAppConfig = config.getTestAppConfig();

    String browserName = Strings.nullToEmpty(capabilities.getBrowserName()).toLowerCase(Locale.ENGLISH);

    // IE
    if ("internet explorer".equals(browserName)) {
        String version = Strings.nullToEmpty(capabilities.getVersion());
        if (version.startsWith("7")) {
            return new PtlInternetExplorer7DriverFactory(environmentConfig, testAppConfig, capabilities);
        }
        if (version.startsWith("8")) {
            return new PtlInternetExplorer8DriverFactory(environmentConfig, testAppConfig, capabilities);
        }

        return new PtlInternetExplorerDriverFactory(environmentConfig, testAppConfig, capabilities);
    }

    // Edge
    if ("microsoftedge".equals(browserName)) {
        return new PtlEdgeDriverFactory(environmentConfig, testAppConfig, capabilities);
    }

    // Android
    if (capabilities.getPlatform() == Platform.ANDROID) {
        // Selendroid (Android 2.3+)
        String automationName = (String) capabilities.getCapability("automationName");
        if (automationName != null && "selendroid".equalsIgnoreCase(automationName)) {
            return new PtlSelendroidDriverFactory(environmentConfig, testAppConfig, capabilities);
        }

        // Default (Android 4.2+)
        return new PtlAndroidDriverFactory(environmentConfig, testAppConfig, capabilities);
    }

    // Chrome
    if ("chrome".equals(browserName)) {
        return new PtlChromeWebDriverFactory(environmentConfig, testAppConfig, capabilities);
    }

    // Safari
    if ("safari".equals(browserName)) {
        // MacOSX
        if (capabilities.getPlatform() == Platform.MAC) {
            return new PtlSafariDriverFactory(environmentConfig, testAppConfig, capabilities);
        }

        String deviceName = capabilities.getDeviceName();
        if (Strings.isNullOrEmpty(deviceName)) {
            throw new TestRuntimeException("\"deviceName\" is required for iOS devices");
        }
        if (deviceName.contains("iPad")) {
            return new PtlIPadDriverFactory(environmentConfig, testAppConfig, capabilities);
        }
        if (deviceName.contains("iPhone")) {
            return new PtlIPhoneDriverFactory(environmentConfig, testAppConfig, capabilities);
        }

        throw new TestRuntimeException("Unknown deviceName \"" + deviceName + "\"");
    }

    // Other
    return new PtlFirefoxWebDriverFactory(environmentConfig, testAppConfig, capabilities);
}

From source file:de.m0ep.canvas.AbstractEndpoint.java

@Override
public String getParentEndpointPath() {
    return Strings.nullToEmpty(parentEndpointPath);
}

From source file:org.mitre.oauth2.service.impl.DefaultClientUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String clientId) throws UsernameNotFoundException {

    ClientDetails client = clientDetailsService.loadClientByClientId(clientId);

    if (client != null) {

        String password = Strings.nullToEmpty(client.getClientSecret());
        boolean enabled = true;
        boolean accountNonExpired = true;
        boolean credentialsNonExpired = true;
        boolean accountNonLocked = true;
        Collection<GrantedAuthority> authorities = client.getAuthorities();
        if (authorities == null || authorities.isEmpty()) {
            // automatically inject ROLE_CLIENT if none exists ...
            // TODO: this should probably happen on the client service side instead to keep it in the real data model
            authorities = new ArrayList<GrantedAuthority>();
            GrantedAuthority roleClient = new SimpleGrantedAuthority("ROLE_CLIENT");
            authorities.add(roleClient);
        }/*from ww  w .  jav  a 2 s.  co m*/

        return new User(clientId, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked,
                authorities);
    } else {
        throw new UsernameNotFoundException("Client not found: " + clientId);
    }

}