List of usage examples for com.google.common.base Strings emptyToNull
@Nullable public static String emptyToNull(@Nullable String string)
From source file:com.reprezen.swagedit.assist.StyledCompletionProposal.java
@Override public Point getSelection(IDocument document) { int offset = replacementOffset; if (Strings.emptyToNull(prefix) != null) { if (replacementString.startsWith(prefix)) { offset = replacementOffset - prefix.length(); } else if (replacementString.contains(prefix)) { offset = replacementOffset - prefix.length(); }/*from w w w . jav a 2 s . c o m*/ } int cursorPosition = offset + replacementString.length(); return new Point(cursorPosition, 0); }
From source file:io.druid.query.dimension.LookupDimensionSpec.java
@JsonCreator public LookupDimensionSpec(@JsonProperty("dimension") String dimension, @JsonProperty("outputName") String outputName, @JsonProperty("lookup") LookupExtractor lookup, @JsonProperty("retainMissingValue") boolean retainMissingValue, @JsonProperty("replaceMissingValueWith") String replaceMissingValueWith, @JsonProperty("name") String name, @JacksonInject LookupReferencesManager lookupReferencesManager, @JsonProperty("optimize") Boolean optimize) { this.retainMissingValue = retainMissingValue; this.optimize = optimize == null ? true : optimize; this.replaceMissingValueWith = Strings.emptyToNull(replaceMissingValueWith); this.dimension = Preconditions.checkNotNull(dimension, "dimension can not be Null"); this.outputName = Preconditions.checkNotNull(outputName, "outputName can not be Null"); this.lookupReferencesManager = lookupReferencesManager; this.name = name; this.lookup = lookup; Preconditions.checkArgument(Strings.isNullOrEmpty(name) ^ (lookup == null), "name [%s] and lookup [%s] are mutually exclusive please provide either a name or a lookup", name, lookup);//from w w w. j a va 2s .c o m if (!Strings.isNullOrEmpty(name)) { Preconditions.checkNotNull(this.lookupReferencesManager, "The system is not configured to allow for lookups, please read about configuring a lookup manager in the docs"); } }
From source file:co.mitro.core.servlets.EditSecretContent.java
static void setEncryptedDataForSVS(MitroRequestContext context, Map<Integer, SecretContent> groupIdToEncryptedData, DBServerVisibleSecret svs, EmptyClientData allowEmptyClientData) throws MitroServletException, SQLException { // find all the group secrets for these groups. TODO: optimize. for (DBGroupSecret gs : svs.getGroupSecrets()) { int groupId = gs.getGroup().getId(); SecretContent newContent = groupIdToEncryptedData.get(groupId); if (newContent == null) { throw new MitroServletException("group:" + groupId + " was omitted for secret:" + svs.getId()); }/* ww w . ja va 2 s .c o m*/ if (allowEmptyClientData == EmptyClientData.DISALLOW_EMPTY_CLIENT_DATA) { Preconditions.checkNotNull(Strings.emptyToNull(newContent.encryptedClientData)); } if (!Strings.isNullOrEmpty(newContent.encryptedClientData)) { gs.setClientVisibleDataEncrypted(newContent.encryptedClientData); } if (!Strings.isNullOrEmpty(newContent.encryptedCriticalData)) { gs.setCriticalDataEncrypted(newContent.encryptedCriticalData); } context.manager.groupSecretDao.update(gs); groupIdToEncryptedData.remove(groupId); } if (!groupIdToEncryptedData.isEmpty()) { throw new MitroServletException("secret: " + svs.getId() + " is not visible to groups:" + Joiner.on(",").join(groupIdToEncryptedData.keySet())); } }
From source file:io.druid.query.filter.StringValueMatcherColumnSelectorStrategy.java
@Override public ValueGetter makeValueGetter(final DimensionSelector selector) { if (selector.getValueCardinality() == 0) { return NULL_VALUE_GETTER; } else {//from w w w. j a va 2 s . co m return new ValueGetter() { @Override public String[] get() { final IndexedInts row = selector.getRow(); final int size = row.size(); if (size == 0) { return NULL_VALUE; } else { String[] values = new String[size]; for (int i = 0; i < size; ++i) { values[i] = Strings.emptyToNull(selector.lookupName(row.get(i))); } return values; } } }; } }
From source file:org.gradle.api.publish.ivy.internal.artifact.AbstractIvyArtifact.java
@Nullable @Override public String getConf() { return Strings.emptyToNull(conf != null ? conf : getDefaultConf()); }
From source file:com.nestedbird.modules.ratelimiter.RateLimiterAspect.java
/** * retrieves the key from the limit annotation data, or uses the name of the method * * @param joinPoint the join point// w ww. j a va 2s .c om * @param limit the limit annotation data * @return the methods identifier */ private String getOrCreate(final JoinPoint joinPoint, final RateLimit limit) { return Optional.ofNullable(Strings.emptyToNull(limit.key())) .orElseGet(() -> JoinPointToStringHelper.toString(joinPoint)); }
From source file:io.macgyver.cli.Command.java
protected Optional<String> getToken() { return Optional.ofNullable(Strings.emptyToNull(getConfig().path("token").asText(null))); }
From source file:com.haulmont.cuba.web.gui.components.WebAbstractTextField.java
@Override public <V> V getValue() { String value = super.getValue(); if (isTrimming()) { value = StringUtils.trim(value); }// ww w .j a v a 2 s . com value = Strings.emptyToNull(value); Datatype datatype = getActualDatatype(); if (value != null && datatype != null) { try { return (V) datatype.parse(value, locale); } catch (ParseException e) { Logger log = LoggerFactory.getLogger(WebAbstractTextField.class); log.debug("Unable to parse value of component {}\n{}", getId(), e.getMessage()); return null; } } else { return (V) value; } }
From source file:com.facebook.buck.intellij.ideabuck.config.BuckSettingsProvider.java
private Optional<String> optionalFromNullableOrEmptyString(String s) { return Optional.ofNullable(Strings.emptyToNull(s)); }
From source file:org.glowroot.common2.repo.util.MetricService.java
@Nullable Number getMetricValue(String agentRollupId, MetricCondition metricCondition, long startTime, long endTime) throws Exception { String metric = metricCondition.getMetric(); if (metric.equals("transaction:x-percentile")) { return getTransactionDurationPercentile(agentRollupId, metricCondition.getTransactionType(), Strings.emptyToNull(metricCondition.getTransactionName()), metricCondition.getPercentile().getValue(), startTime, endTime); } else if (metric.equals("transaction:average")) { return getTransactionAverage(agentRollupId, metricCondition.getTransactionType(), Strings.emptyToNull(metricCondition.getTransactionName()), startTime, endTime); } else if (metric.equals("transaction:count")) { return getTransactionCount(agentRollupId, metricCondition.getTransactionType(), Strings.emptyToNull(metricCondition.getTransactionName()), startTime, endTime); } else if (metric.equals("error:rate")) { return getErrorRate(agentRollupId, metricCondition.getTransactionType(), Strings.emptyToNull(metricCondition.getTransactionName()), startTime, endTime); } else if (metric.equals("error:count")) { return getErrorCount(agentRollupId, metricCondition.getTransactionType(), Strings.emptyToNull(metricCondition.getTransactionName()), metricCondition.getErrorMessageFilter(), startTime, endTime); } else if (metric.startsWith("gauge:")) { return getGaugeValue(agentRollupId, metric.substring("gauge:".length()), startTime, endTime); } else {/*from www . jav a2 s . c o m*/ throw new IllegalStateException("Unexpected metric: " + metric); } }