List of usage examples for com.google.common.base Strings emptyToNull
@Nullable public static String emptyToNull(@Nullable String string)
From source file:org.gradle.api.internal.artifacts.dependencies.AbstractExternalModuleDependency.java
public String getVersion() { return Strings.emptyToNull(versionConstraint.getVersion()); }
From source file:com.github.autermann.wps.matlab.description.MatlabProcessDescription.java
public void setVersion(String version) { this.version = Strings.emptyToNull(version); }
From source file:com.google.gerrit.server.project.SetDefaultDashboard.java
@Override public Object apply(DashboardResource resource, Input input) throws AuthException, BadRequestException, ResourceConflictException, Exception { if (input == null) { input = new Input(); // Delete would set input to null. }/*from ww w. ja v a2s.c o m*/ input.id = Strings.emptyToNull(input.id); ProjectControl ctl = resource.getControl(); IdentifiedUser user = (IdentifiedUser) ctl.getCurrentUser(); if (!ctl.isOwner()) { throw new AuthException("not project owner"); } DashboardResource target = null; if (input.id != null) { try { target = dashboards.parse(new ProjectResource(ctl), IdString.fromUrl(input.id)); } catch (ResourceNotFoundException e) { throw new BadRequestException("dashboard " + input.id + " not found"); } } try { MetaDataUpdate md = updateFactory.create(ctl.getProject().getNameKey()); try { ProjectConfig config = ProjectConfig.read(md); Project project = config.getProject(); if (inherited) { project.setDefaultDashboard(input.id); } else { project.setLocalDefaultDashboard(input.id); } String msg = Objects.firstNonNull(Strings.emptyToNull(input.commitMessage), input.id == null ? "Removed default dashboard.\n" : String.format("Changed default dashboard to %s.\n", input.id)); if (!msg.endsWith("\n")) { msg += "\n"; } md.setAuthor(user); md.setMessage(msg); config.commit(md); cache.evict(ctl.getProject()); if (target != null) { DashboardInfo info = get.get().apply(target); info.isDefault = true; return info; } return Response.none(); } finally { md.close(); } } catch (RepositoryNotFoundException notFound) { throw new ResourceNotFoundException(ctl.getProject().getName()); } catch (ConfigInvalidException e) { throw new ResourceConflictException(String.format("invalid project.config: %s", e.getMessage())); } }
From source file:com.greensopinion.swagger.jaxrsgen.model.ApiModel.java
ApiModel(String name, String description, List<String> required, LinkedHashMap<String, Property> properties) { this.name = checkNotNull(name); this.id = name; this.description = Strings.emptyToNull(description); this.required = ImmutableList.copyOf(checkNotNull(required)); this.properties = Maps.newLinkedHashMap(checkNotNull(properties)); }
From source file:org.pentaho.di.core.attributes.metastore.JsonElement.java
@Override public String getId() { if (Strings.isNullOrEmpty(super.getId())) { setId(getName());//w w w.j a va 2 s . c o m } return Strings.emptyToNull(super.getId()); }
From source file:org.killbill.billing.plugin.core.PluginServlet.java
protected LocalDate getParameterAsLocalDate(final String parameterName, final ServletRequest req) { final String parameter = req.getParameter(parameterName); return Strings.emptyToNull(parameter) != null ? DATE_FORMAT.parseLocalDate(parameter) : null; }
From source file:org.gradle.api.internal.artifacts.dependencies.DefaultDependencyConstraint.java
@Override public String getVersion() { return Strings.emptyToNull(versionConstraint.getRequiredVersion()); }
From source file:org.apache.hive.spark.client.SparkSubmitSparkClient.java
@Override protected String getSparkHome() { String sparkHome = Strings.emptyToNull(conf.get(SPARK_HOME_KEY)); if (sparkHome == null) { sparkHome = Strings.emptyToNull(System.getenv(SPARK_HOME_ENV)); }/* w w w . j av a2 s. c o m*/ if (sparkHome == null) { sparkHome = Strings.emptyToNull(System.getProperty(SPARK_HOME_KEY)); } Preconditions.checkNotNull(sparkHome, "Cannot use " + HiveConf.HIVE_SPARK_SUBMIT_CLIENT + " without setting Spark Home"); String master = conf.get("spark.master"); Preconditions.checkArgument(master != null, "spark.master is not defined."); argv = Lists.newLinkedList(); argv.add(new File(sparkHome, "bin/spark-submit").getAbsolutePath()); return sparkHome; }
From source file:com.google.gerrit.server.project.SetParent.java
@Override public String apply(ProjectResource resource, Input input) throws AuthException, BadRequestException, ResourceConflictException, Exception { ProjectControl ctl = resource.getControl(); IdentifiedUser user = (IdentifiedUser) ctl.getCurrentUser(); if (!user.getCapabilities().canAdministrateServer()) { throw new AuthException("not administrator"); }/*from w w w . j a v a 2s. c om*/ try { MetaDataUpdate md = updateFactory.create(resource.getNameKey()); try { ProjectConfig config = ProjectConfig.read(md); Project project = config.getProject(); project.setParentName(Strings.emptyToNull(input.parent)); String msg = Strings.emptyToNull(input.commitMessage); if (msg == null) { msg = String.format("Changed parent to %s.\n", Objects.firstNonNull(project.getParentName(), allProjects.get())); } else if (!msg.endsWith("\n")) { msg += "\n"; } md.setAuthor(user); md.setMessage(msg); config.commit(md); cache.evict(ctl.getProject()); Project.NameKey parentName = project.getParent(allProjects); return parentName != null ? parentName.get() : ""; } 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:io.druid.server.namespace.URIExtractionNamespaceFunctionFactory.java
@Override public Function<String, String> build(URIExtractionNamespace extractionNamespace, final Map<String, String> cache) { return new Function<String, String>() { @Nullable/*from ww w . j av a2 s . c o m*/ @Override public String apply(String input) { if (Strings.isNullOrEmpty(input)) { return null; } return Strings.emptyToNull(cache.get(input)); } }; }