List of usage examples for com.google.common.base Strings emptyToNull
@Nullable public static String emptyToNull(@Nullable String string)
From source file:org.n52.sos.util.Reference.java
public Reference setTitle(String title) { this.title = Optional.fromNullable(Strings.emptyToNull(title)); return this; }
From source file:io.druid.query.extraction.StringFormatExtractionFn.java
@Override public String apply(String value) { if (value == null) { if (nullHandling == NullHandling.RETURNNULL) { return null; }/*from w w w. ja va 2 s.c o m*/ if (nullHandling == NullHandling.EMPTYSTRING) { value = ""; } } return Strings.emptyToNull(String.format(format, value)); }
From source file:org.sonar.server.rule.RubyRuleService.java
/** * Used in SQALE/*from w w w .j a v a2 s .c o m*/ */ public PagedResult<RuleDto> find(Map<String, Object> params) { RuleQuery query = new RuleQuery(); query.setQueryText(Strings.emptyToNull((String) params.get("searchQuery"))); query.setKey(Strings.emptyToNull((String) params.get("key"))); query.setLanguages(RubyUtils.toStrings(params.get("languages"))); query.setRepositories(RubyUtils.toStrings(params.get("repositories"))); query.setSeverities(RubyUtils.toStrings(params.get("severities"))); query.setStatuses(RubyUtils.toEnums(params.get("statuses"), RuleStatus.class)); query.setTags(RubyUtils.toStrings(params.get("tags"))); query.setSortField(RuleIndexDefinition.FIELD_RULE_NAME); String profile = Strings.emptyToNull((String) params.get("profile")); if (profile != null) { query.setQProfileKey(profile); query.setActivation(true); } SearchOptions options = new SearchOptions(); Integer pageSize = RubyUtils.toInteger(params.get("pageSize")); int size = pageSize != null ? pageSize : 50; Integer page = RubyUtils.toInteger(params.get("p")); int pageIndex = page != null ? page : 1; options.setPage(pageIndex, size); SearchIdResult<RuleKey> result = service.search(query, options); List<RuleDto> ruleDtos = loadDtos(result.getIds()); return new PagedResult<>(ruleDtos, PagingResult.create(options.getLimit(), pageIndex, result.getTotal())); }
From source file:fathom.jcache.JCacheModule.java
@Override protected void setup() { // Setup Hazelcast logging System.setProperty("hazelcast.logging.type", "slf4j"); // setup the known cache providers Map<String, String> knownProviders = new HashMap<String, String>() { {// w w w. j a v a 2s . co m put("org.infinispan.jcache.JCachingProvider", "infinispan"); put("org.ehcache.jcache.JCacheCachingProvider", "ehcache"); put("com.hazelcast.cache.HazelcastCachingProvider", "hazelcast"); } }; // collect the the available providers and identify the preferred provider String preferredName = Strings .emptyToNull(getSettings().getString(Settings.Setting.jcache_preferredProvider, null)); CachingProvider preferredProvider = null; List<CachingProvider> providers = new ArrayList<>(); for (CachingProvider provider : Caching.getCachingProviders()) { providers.add(provider); String providerClassName = provider.getClass().getName(); if ((knownProviders.containsKey(providerClassName) && knownProviders.get(providerClassName).equals(preferredName)) || providerClassName.equals(preferredName)) { preferredProvider = provider; } } if (providers.isEmpty()) { log.debug("There are no JCache providers on the classpath."); // XXX JCache provider based on Guava would be really cool // @see https://github.com/ben-manes/caffeine/issues/6 } else { if (preferredProvider == null) { preferredProvider = providers.get(0); } // register the cache service which handles graceful cleanup register(new JCache(getSettings(), preferredProvider)); // optionally configure the JCache provider final String providerClassName = preferredProvider.getClass().getName(); String keyName = knownProviders.get(providerClassName); if (!Strings.isNullOrEmpty(keyName)) { String configFile = Strings .emptyToNull(getSettings().getString(keyName + ".configurationFile", "")); if (Strings.isNullOrEmpty(configFile) || configFile.equalsIgnoreCase("jcache")) { log.debug("Configuring JCache provider '{}' using internal provider defaults", keyName); } else { try { URL configFileUrl = getSettings().getFileUrl(keyName + ".configurationFile", ""); log.debug("Configuring JCache provider '{}' from '{}'", keyName, configFileUrl); preferredProvider.getCacheManager(configFileUrl.toURI(), preferredProvider.getDefaultClassLoader()); } catch (URISyntaxException e) { log.error("Failed to configure " + keyName, e); } } } // Bind the preferred provider bind(CacheManager.class).toInstance(preferredProvider.getCacheManager()); bind(CacheKeyGenerator.class).to(DefaultCacheKeyGenerator.class); bind(CacheResolverFactory.class) .toInstance(new DefaultCacheResolverFactory(preferredProvider.getCacheManager())); bind(new TypeLiteral<CacheContextSource<MethodInvocation>>() { }).to(CacheLookupUtil.class); // install the Guice annotation interceptors CachePutInterceptor cachePutInterceptor = new CachePutInterceptor(); requestInjection(cachePutInterceptor); bindInterceptor(Matchers.annotatedWith(CachePut.class), Matchers.any(), cachePutInterceptor); bindInterceptor(Matchers.any(), Matchers.annotatedWith(CachePut.class), cachePutInterceptor); CacheResultInterceptor cacheResultInterceptor = new CacheResultInterceptor(); requestInjection(cacheResultInterceptor); bindInterceptor(Matchers.annotatedWith(CacheResult.class), Matchers.any(), cacheResultInterceptor); bindInterceptor(Matchers.any(), Matchers.annotatedWith(CacheResult.class), cacheResultInterceptor); CacheRemoveEntryInterceptor cacheRemoveEntryInterceptor = new CacheRemoveEntryInterceptor(); requestInjection(cacheRemoveEntryInterceptor); bindInterceptor(Matchers.annotatedWith(CacheRemove.class), Matchers.any(), cacheRemoveEntryInterceptor); bindInterceptor(Matchers.any(), Matchers.annotatedWith(CacheRemove.class), cacheRemoveEntryInterceptor); CacheRemoveAllInterceptor cacheRemoveAllInterceptor = new CacheRemoveAllInterceptor(); requestInjection(cacheRemoveAllInterceptor); bindInterceptor(Matchers.annotatedWith(CacheRemoveAll.class), Matchers.any(), cacheRemoveAllInterceptor); bindInterceptor(Matchers.any(), Matchers.annotatedWith(CacheRemoveAll.class), cacheRemoveAllInterceptor); } }
From source file:com.example.gcm.GCMDemo.java
protected String getPidfileOrDefault(final Properties props) { return Optional.fromNullable(Strings.emptyToNull(props.getProperty(PROPERTY_PIDFILE))).or(DEFAULT_PIDFILE); }
From source file:org.sonar.server.user.AbstractUserSession.java
public T setLogin(@Nullable String s) { this.login = Strings.emptyToNull(s); return clazz.cast(this); }
From source file:org.gbif.metadata.eml.TaxonomicCoverage.java
/** * Adds new taxon keywords each having only a scientific name. * * @param scientificNames concatenated list of scientific names using a semicolon ; pipe | or new line \n delimiter * * @return the number of newly added taxon keywords */// w w w .j av a 2 s . c o m public int addTaxonKeywords(String scientificNames) { String delimiter = ";"; if (scientificNames.contains("\n")) { delimiter = "\n"; } else if (scientificNames.contains("|")) { delimiter = "|"; } int count = 0; for (String sciname : Splitter.on(delimiter).split(scientificNames)) { sciname = Strings.emptyToNull(sciname.trim()); if (sciname != null) { taxonKeywords.add(new TaxonKeyword(sciname, null, null)); count++; } } return count; }
From source file:com.google.gerrit.server.project.PutDescription.java
@Override public Object apply(ProjectResource resource, Input input) throws AuthException, BadRequestException, ResourceConflictException, ResourceNotFoundException, IOException { if (input == null) { input = new Input(); // Delete would set description to null. }//w w w . j av a 2s . c o m ProjectControl ctl = resource.getControl(); IdentifiedUser user = (IdentifiedUser) ctl.getCurrentUser(); if (!ctl.isOwner()) { throw new AuthException("not project owner"); } try { MetaDataUpdate md = updateFactory.create(resource.getNameKey()); try { ProjectConfig config = ProjectConfig.read(md); Project project = config.getProject(); project.setDescription(Strings.emptyToNull(input.description)); String msg = Objects.firstNonNull(Strings.emptyToNull(input.commitMessage), "Updated description.\n"); if (!msg.endsWith("\n")) { msg += "\n"; } md.setAuthor(user); md.setMessage(msg); config.commit(md); cache.evict(ctl.getProject()); gitMgr.setProjectDescription(resource.getNameKey(), project.getDescription()); return Strings.isNullOrEmpty(project.getDescription()) ? Response.none() : project.getDescription(); } finally { md.close(); } } catch (RepositoryNotFoundException notFound) { throw new ResourceNotFoundException(resource.getName()); } catch (ConfigInvalidException e) { throw new ResourceConflictException(String.format("invalid project.config: %s", e.getMessage())); } }
From source file:org.n52.shetland.ogc.ows.OwsCapabilities.java
public void setVersion(String version) { this.version = Objects.requireNonNull(Strings.emptyToNull(version)); }
From source file:org.killbill.billing.invoice.notification.EmailInvoiceNotifier.java
@Override public void notify(final Account account, final Invoice invoice, final TenantContext context) throws InvoiceApiException { if (Strings.emptyToNull(account.getEmail()) == null) { throw new InvoiceApiException( new IllegalArgumentException("Email for account " + account.getId() + " not specified"), ErrorCode.EMAIL_SENDING_FAILED); }// ww w . j a v a 2s . c om final InternalTenantContext internalTenantContext = internalCallContextFactory .createInternalTenantContext(account.getId(), context); final List<String> to = new ArrayList<String>(); to.add(account.getEmail()); final List<AccountEmail> accountEmailList = accountApi.getEmails(account.getId(), internalTenantContext); final List<String> cc = new ArrayList<String>(); for (final AccountEmail email : accountEmailList) { cc.add(email.getEmail()); } // Check if this account has the MANUAL_PAY system tag boolean manualPay = false; final List<Tag> accountTags = tagUserApi.getTags(account.getId(), ObjectType.ACCOUNT, internalTenantContext); for (final Tag tag : accountTags) { if (ControlTagType.MANUAL_PAY.getId().equals(tag.getTagDefinitionId())) { manualPay = true; break; } } final HtmlInvoice htmlInvoice; try { htmlInvoice = generator.generateInvoice(account, invoice, manualPay, internalTenantContext); } catch (final IOException e) { throw new InvoiceApiException(e, ErrorCode.EMAIL_SENDING_FAILED); } // take localized subject, or the configured one if the localized one is not available String subject = htmlInvoice.getSubject(); if (subject == null) { subject = config.getInvoiceEmailSubject(); } final EmailSender sender = new DefaultEmailSender(config); try { sender.sendHTMLEmail(to, cc, subject, htmlInvoice.getBody()); } catch (final EmailApiException e) { throw new InvoiceApiException(e, ErrorCode.EMAIL_SENDING_FAILED); } catch (final IOException e) { throw new InvoiceApiException(e, ErrorCode.EMAIL_SENDING_FAILED); } }