List of usage examples for com.google.common.base Strings nullToEmpty
public static String nullToEmpty(@Nullable String string)
From source file:org.trnltk.model.letter.TurkishSequence.java
/** * Create a {@link TurkishSequence} instance from a string. * <p/>//from w w w . j a v a 2s .c o m * Chars are one by one converted to {@link TurkishChar}s, thus if you are going to clone a {@link TurkishSequence} * it is advised to use the method {@link TurkishSequence#TurkishSequence(TurkishSequence)} * * @param underlyingString String to convert to {@link TurkishSequence} */ public TurkishSequence(String underlyingString) { this.underlyingString = Strings.nullToEmpty(underlyingString); this.count = underlyingString.length(); this.chars = new TurkishChar[this.count]; for (int i = 0; i < underlyingString.length(); i++) { char c = underlyingString.charAt(i); TurkishChar turkishChar = TurkishAlphabet.getChar(c); this.chars[i] = turkishChar; if (turkishChar.getLetter().isVowel()) { if (this.firstVowel == null) this.firstVowel = turkishChar; this.lastVowel = turkishChar; } } }
From source file:org.attribyte.api.pubsub.impl.server.util.SubscriptionRequestRecord.java
public SubscriptionRequestRecord(final Request request, final Response response, final Subscriber subscriber) throws IOException { this.sourceIP = HTTPUtil.getClientIP(request); this.topicURL = request.getParameterValue(ProtocolConstants.SUBSCRIPTION_TOPIC_PARAMETER); this.callbackURL = request.getParameterValue(ProtocolConstants.SUBSCRIPTION_CALLBACK_PARAMETER); this.callbackAuthScheme = request.getParameterValue(ProtocolConstants.SUBSCRIPTION_CALLBACK_AUTH_SCHEME); this.callbackAuthSupplied = !Strings .nullToEmpty(request.getParameterValue(ProtocolConstants.SUBSCRIPTION_CALLBACK_AUTH)).trim() .isEmpty();// w ww .j av a 2 s. c o m this.responseCode = response.getStatusCode(); this.responseBody = response.getBody() != null ? response.getBody().toStringUtf8() : null; this.subscriberId = subscriber != null ? subscriber.getId() : 0L; }
From source file:com.facebook.presto.exception.PartitionAlreadyExistsException.java
/** * Constructor./*from w w w.j a v a 2 s . c o m*/ * @param tableName table name * @param partitionId partition name * @param cause error cause */ public PartitionAlreadyExistsException(final SchemaTableName tableName, final String partitionId, final Throwable cause) { super(StandardErrorCode.ALREADY_EXISTS, String.format("Partition '%s' already exists for table '%s'", Strings.nullToEmpty(partitionId), tableName), cause); }
From source file:org.gbif.ipt.validation.BaseValidator.java
protected boolean isValidEmail(String email) { if (email != null) { try {/* w w w .j a v a 2 s.co m*/ InternetAddress internetAddress = new InternetAddress(email); internetAddress.validate(); return true; } catch (javax.mail.internet.AddressException e) { LOG.debug("Email address was invalid: " + Strings.nullToEmpty(email)); } } return false; }
From source file:org.zanata.magpie.annotation.EnvVariableProducer.java
@Produces @EnvVariable("")/* w ww. ja va 2 s. c o m*/ String findProperty(InjectionPoint ip) { EnvVariable annotation = ip.getAnnotated().getAnnotation(EnvVariable.class); String name = annotation.value(); String found = getEnv(name); if (found == null) { log.warn("Environment variable '{}' is not defined!", name); } return Strings.nullToEmpty(found); }
From source file:org.attribyte.relay.RDBSupplier.java
/** * Called by implementation to initialize pools after construction. * @param props The properties.// ww w. ja v a2 s . c o m * @param logger The logger. * @throws Exception on initialization error. */ protected void initPools(final Properties props, final Logger logger) throws Exception { InitUtil dbProps = new InitUtil("rdb.", props); String credentialsFilename = Strings.nullToEmpty(dbProps.getProperty("credentialsFile")).trim(); final PasswordSource passwordSource; if (!credentialsFilename.isEmpty()) { File credentialsFile = new File(credentialsFilename); if (!credentialsFile.exists()) { throw new Exception( String.format("The 'rdb.credentialsFile', '%s' does not exist", credentialsFilename)); } if (!credentialsFile.canRead()) { throw new Exception( String.format("The 'rdb.credentialsFile', '%s' can't be read", credentialsFilename)); } Properties credentialsProps = new Properties(); credentialsProps.load(new ByteArrayInputStream(Files.toByteArray(credentialsFile))); passwordSource = new PropertiesPasswordSource(credentialsProps); } else { passwordSource = null; } List<ConnectionPool.Initializer> initializers = ConnectionPool.Initializer .fromProperties(dbProps.getProperties(), passwordSource, logger); if (initializers.size() == 0) { throw new Exception("No connection pool found"); } String defaultPoolName = Strings.nullToEmpty(dbProps.getProperty("defaultPoolName")).trim(); if (defaultPoolName.isEmpty()) { ImmutableMap.Builder<String, ConnectionPool> connectionPools = ImmutableMap.builder(); this.defaultConnectionPool = initializers.get(0).createPool(); connectionPools.put(this.defaultConnectionPool.getName(), this.defaultConnectionPool); for (int i = 1; i < initializers.size(); i++) { ConnectionPool curr = initializers.get(i).createPool(); connectionPools.put(curr.getName(), curr); } this.connectionPools = connectionPools.build(); } else { ImmutableMap.Builder<String, ConnectionPool> connectionPools = ImmutableMap.builder(); for (ConnectionPool.Initializer init : initializers) { ConnectionPool pool = init.createPool(); connectionPools.put(pool.getName(), pool); } this.connectionPools = connectionPools.build(); this.defaultConnectionPool = this.connectionPools.get(defaultPoolName); if (this.defaultConnectionPool == null) { throw new Exception( String.format("The default connection pool, '%s', was not configured", defaultPoolName)); } } }
From source file:com.google.api.explorer.client.base.Config.java
/** Get the API key to use for requests from this application. */ public static String getApiKey() { return Strings.nullToEmpty(apiKey); }
From source file:org.apache.beam.sdk.io.aws.s3.S3ResourceId.java
static S3ResourceId fromUri(String uri) { Matcher m = S3_URI.matcher(uri); checkArgument(m.matches(), "Invalid S3 URI: [%s]", uri); checkArgument(m.group("SCHEME").equalsIgnoreCase(SCHEME), "Invalid S3 URI scheme: [%s]", uri); String bucket = m.group("BUCKET"); String key = Strings.nullToEmpty(m.group("KEY")); if (!key.startsWith("/")) { key = "/" + key; }// w w w . j a va2s .c om return fromComponents(bucket, key); }
From source file:com.eucalyptus.auth.policy.ern.ResourceNameSupport.java
@Override public String toString() { return new StringBuilder().append(ARN_PREFIX).append(getService()).append(':') .append(Strings.nullToEmpty(getRegion())).append(':').append(Strings.nullToEmpty(getAccount())) .append(':').append(getType()).append('/').append(getResourceName()).toString(); }
From source file:io.macgyver.plugin.cloud.aws.scanner.AWSScannerService.java
@Override public void run() { registy.getServiceDefinitions().values().forEach(it -> { try {//from w w w . j av a 2 s . com String type = Strings.nullToEmpty(it.getServiceType()); if (type.toLowerCase().equals("aws")) { AWSServiceClient c = registy.get(it.getName()); List<String> regionList = Splitter.on(",").omitEmptyStrings().trimResults() .splitToList(Strings.nullToEmpty(it.getProperty("regions"))); scan(c, regionList.toArray(new String[0])); } } catch (Exception e) { logger.warn("", e); } }); }