List of usage examples for com.google.common.base Strings nullToEmpty
public static String nullToEmpty(@Nullable String string)
From source file:com.github.vbauer.yta.service.fraction.impl.TranslationApiImpl.java
/** * {@inheritDoc}/* www . j av a2 s . c om*/ */ @Nonnull @Override public Translation translate(@Nullable final String text, @Nonnull final Direction direction, @Nullable final TextFormat format) { final Map<String, Object> params = ImmutableMap.<String, Object>builder() .put(ATTR_TEXT, Strings.nullToEmpty(text)).put(ATTR_LANG, direction.toString()) .put(ATTR_FORMAT, TextFormat.getOrDefault(format).code()).build(); final TranslationInfo data = callMethod(TranslationInfo.class, METHOD_DETECT, params); ApiStatus.check(data.code()); return Preconditions.checkNotNull(TranslationConverter.INSTANCE.convert(data)); }
From source file:org.jclouds.vcloud.director.testng.FormatApiResultsListener.java
private String getTest(ITestResult res) { return Strings.nullToEmpty(res.getName()); }
From source file:com.google.devtools.build.lib.bazel.repository.downloader.HttpDownloader.java
/** Validates native repository rule attributes and calls the other download method. */ public Path download(Rule rule, Path outputDirectory, EventHandler eventHandler, Map<String, String> clientEnv) throws RepositoryFunctionException, InterruptedException { WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(rule); List<URL> urls = new ArrayList<>(); String sha256;/*from w w w. j a va 2 s .com*/ String type; try { String urlString = Strings.nullToEmpty(mapper.get("url", Type.STRING)); if (!urlString.isEmpty()) { try { URL url = new URL(urlString); if (!HttpUtils.isUrlSupportedByDownloader(url)) { throw new EvalException(rule.getAttributeLocation("url"), "Unsupported protocol: " + url.getProtocol()); } urls.add(url); } catch (MalformedURLException e) { throw new EvalException(rule.getAttributeLocation("url"), e.toString()); } } List<String> urlStrings = MoreObjects.firstNonNull(mapper.get("urls", Type.STRING_LIST), ImmutableList.<String>of()); if (!urlStrings.isEmpty()) { if (!urls.isEmpty()) { throw new EvalException(rule.getAttributeLocation("url"), "Don't set url if urls is set"); } try { for (String urlString2 : urlStrings) { URL url = new URL(urlString2); if (!HttpUtils.isUrlSupportedByDownloader(url)) { throw new EvalException(rule.getAttributeLocation("urls"), "Unsupported protocol: " + url.getProtocol()); } urls.add(url); } } catch (MalformedURLException e) { throw new EvalException(rule.getAttributeLocation("urls"), e.toString()); } } if (urls.isEmpty()) { throw new EvalException(rule.getLocation(), "urls attribute not set"); } sha256 = Strings.nullToEmpty(mapper.get("sha256", Type.STRING)); if (!sha256.isEmpty() && !RepositoryCache.KeyType.SHA256.isValid(sha256)) { throw new EvalException(rule.getAttributeLocation("sha256"), "Invalid SHA256 checksum"); } type = Strings.nullToEmpty(mapper.get("type", Type.STRING)); } catch (EvalException e) { throw new RepositoryFunctionException(e, Transience.PERSISTENT); } try { return download(urls, sha256, Optional.of(type), outputDirectory, eventHandler, clientEnv); } catch (IOException e) { throw new RepositoryFunctionException(e, Transience.TRANSIENT); } }
From source file:org.sosy_lab.solver.mathsat5.Mathsat5AbstractProver.java
private void handleSolverExceptionInUnsatCheck(IllegalStateException e) throws SolverException { String msg = Strings.nullToEmpty(e.getMessage()); if (msg.contains("too many iterations") || msg.contains("impossible to build a suitable congruence graph!") || msg.contains("can't produce proofs") || msg.equals("msat_solve returned \"unknown\": unsupported")) { // This is not a bug in CPAchecker, but a problem of MathSAT which happens during interpolation throw new SolverException(e.getMessage(), e); }// w ww . java 2 s . com }
From source file:com.zimbra.cs.mime.MimeHandler.java
public String getContentType() { return Strings.nullToEmpty(contentType); }
From source file:fr.xebia.cocktail.Cocktail.java
public String getInstructionsAsHtml() { return Strings.nullToEmpty(instructions).replace("\n", "<br />\n"); }
From source file:com.reprezen.swagedit.json.references.JsonReferenceFactory.java
protected JsonReference doCreate(String value, Object source) { String notNull = Strings.nullToEmpty(value); URI uri;//from w w w .j a v a 2 s. com try { uri = URI.create(notNull); } catch (NullPointerException | IllegalArgumentException e) { // try to encode illegal characters, e.g. curly braces try { uri = URI.create(URLUtils.encodeURL(notNull)); } catch (NullPointerException | IllegalArgumentException e2) { return new JsonReference(null, null, false, false, false, source); } } String fragment = uri.getFragment(); JsonPointer pointer = null; try { pointer = JsonPointer.compile(Strings.emptyToNull(fragment)); } catch (IllegalArgumentException e) { // let the pointer be null } uri = uri.normalize(); boolean absolute = uri.isAbsolute(); boolean local = !absolute && uri.getPath().isEmpty(); // should warn when using curly braces boolean warnings = notNull.contains("{") || uri.toString().contains("}"); return new JsonReference(uri, pointer, absolute, local, warnings, source); }
From source file:org.gradle.api.publish.maven.internal.publisher.AbstractMavenPublisher.java
private void addPomAndArtifacts(MavenPublishAction publishAction, MavenNormalizedPublication publication) { MavenArtifact pomArtifact = publication.getPomArtifact(); publishAction.setPomArtifact(pomArtifact.getFile()); MavenArtifact mainArtifact = publication.getMainArtifact(); if (mainArtifact != null) { publishAction.setMainArtifact(mainArtifact.getFile()); }//from w ww . j a v a 2 s .co m for (MavenArtifact artifact : publication.getAllArtifacts()) { if (artifact == mainArtifact || artifact == pomArtifact) { continue; } publishAction.addAdditionalArtifact(artifact.getFile(), Strings.nullToEmpty(artifact.getExtension()), Strings.nullToEmpty(artifact.getClassifier())); } }
From source file:com.google.gerrit.server.account.PutAgreement.java
@Override public Response<String> apply(AccountResource resource, AgreementInput input) throws IOException, OrmException, RestApiException { if (!agreementsEnabled) { throw new MethodNotAllowedException("contributor agreements disabled"); }//w ww.ja v a 2s .c om if (self.get() != resource.getUser()) { throw new AuthException("not allowed to enter contributor agreement"); } String agreementName = Strings.nullToEmpty(input.name); ContributorAgreement ca = projectCache.getAllProjects().getConfig().getContributorAgreement(agreementName); if (ca == null) { throw new UnprocessableEntityException("contributor agreement not found"); } if (ca.getAutoVerify() == null) { throw new BadRequestException("cannot enter a non-autoVerify agreement"); } AccountGroup.UUID uuid = ca.getAutoVerify().getUUID(); if (uuid == null) { throw new ResourceConflictException("autoverify group uuid not found"); } AccountGroup group = groupCache.get(uuid); if (group == null) { throw new ResourceConflictException("autoverify group not found"); } Account account = self.get().getAccount(); addMembers.addMembers(group.getId(), ImmutableList.of(account.getId())); agreementSignup.fire(account, agreementName); return Response.ok(agreementName); }
From source file:org.sonatype.nexus.extender.modules.NexusBundleModule.java
public NexusBundleModule(final Bundle bundle, final MutableBeanLocator locator, final Map<?, ?> nexusProperties, final ServletContextModule servletContextModule, final List<AbstractInterceptorModule> interceptorModules, final List<TypeConverterSupport> converterModules, final LifecycleModule lifecycleModule) { super(bundle, locator); this.nexusProperties = nexusProperties; this.servletContextModule = servletContextModule; this.interceptorModules = interceptorModules; this.converterModules = converterModules; this.lifecycleModule = lifecycleModule; imports = Strings.nullToEmpty(bundle.getHeaders().get(Constants.IMPORT_PACKAGE)); }