List of usage examples for com.google.common.base Strings emptyToNull
@Nullable public static String emptyToNull(@Nullable String string)
From source file:org.ambraproject.wombat.feed.CommentFeedView.java
private static String formatUserName(Individualprofile userProfile) { String givenNames = Strings.emptyToNull(userProfile.getFirstname()); String surname = Strings.emptyToNull(userProfile.getLastname()); return (givenNames == null && surname == null) ? userProfile.getDisplayname() : Stream.of(givenNames, surname).filter(Objects::nonNull).collect(Collectors.joining(" ")); }
From source file:org.n52.shetland.ogc.ows.OwsRequestMethod.java
public OwsRequestMethod(URI href, Collection<OwsDomain> constraints, String httpMethod, URI role, URI arcrole, String title, Show show, Actuate actuate) { super(href, role, arcrole, title, show, actuate); this.httpMethod = Objects.requireNonNull(Strings.emptyToNull(httpMethod)); this.constraints = CollectionHelper.newSortedSet(constraints); }
From source file:org.n52.sos.util.Reference.java
public Reference setType(String type) { this.type = Optional.fromNullable(Strings.emptyToNull(type)); return this; }
From source file:com.google.devtools.kythe.extractors.jvm.JvmExtractor.java
/** * Returns a JVM {@link CompilationDescription} for the {@code .jar}/{@code .class} file paths * specified by the given {@link Options}. *///www .jav a 2 s.c om public static CompilationDescription extract(Options options) throws IOException, ExtractionException { CompilationUnit.Builder compilation = CompilationUnit.newBuilder() .setVName(VName.newBuilder().setLanguage(JvmGraph.JVM_LANGUAGE)); FileVNames fileVNames; if (options.vnamesConfigFile != null) { fileVNames = FileVNames.fromFile(options.vnamesConfigFile); } else { fileVNames = FileVNames.staticCorpus(options.defaultCorpus); } String buildTarget; if ((buildTarget = Strings.emptyToNull(options.buildTarget)) != null) { compilation.addDetails(Any.newBuilder().setTypeUrl(BUILD_DETAILS_URL) .setValue(BuildDetails.newBuilder().setBuildTarget(buildTarget).build().toByteString())); } Function<String, String> relativizer = ExtractorUtils.makeRelativizer(options.rootDirectory); List<FileData> fileContents = new ArrayList<>(); List<String> classFiles = new ArrayList<>(); JarDetails.Builder jarDetails = JarDetails.newBuilder(); for (Path path : options.jarOrClassFiles) { compilation.addArgument(path.toString()); compilation.addSourceFile(path.toString()); if (path.toString().endsWith(JAR_FILE_EXT)) { VName jarVName = ExtractorUtils.lookupVName(fileVNames, relativizer, path.toString()); int jarIndex = jarDetails.getJarCount(); JarDetails.Jar.Builder jar = jarDetails.addJarBuilder().setVName(jarVName); List<FileData> jarContents = new ArrayList<>(); for (FileData file : extractClassFiles(path)) { jarContents.add(file); } fileContents.addAll(jarContents); Any jarEntryDetails = Any.newBuilder().setTypeUrl(JAR_ENTRY_DETAILS_URL) .setValue(JarEntryDetails.newBuilder().setJarContainer(jarIndex).build().toByteString()) .build(); compilation.addAllRequiredInput(ExtractorUtils.toFileInputs(fileVNames, relativizer, jarContents) .stream().map(i -> i.toBuilder().addDetails(jarEntryDetails).build()) .collect(Collectors.toList())); } else { classFiles.add(path.toString()); } } List<FileData> classFilesData = ExtractorUtils.processRequiredInputs(classFiles); compilation.addAllRequiredInput(ExtractorUtils.toFileInputs(fileVNames, relativizer, classFilesData)); fileContents.addAll(classFilesData); if (jarDetails.getJarCount() > 0) { compilation.addDetails( Any.newBuilder().setTypeUrl(JAR_DETAILS_URL).setValue(jarDetails.build().toByteString())); } if (compilation.getRequiredInputCount() > options.maxRequiredInputs) { throw new ExtractionException(String.format("number of required inputs (%d) exceeded maximum (%d)", compilation.getRequiredInputCount(), options.maxRequiredInputs), false); } long totalFileSize = 0; for (FileData data : fileContents) { totalFileSize += data.getContent().size(); } if (totalFileSize > options.maxTotalFileSize) { throw new ExtractionException(String.format("total size of inputs (%d) exceeded maximum (%d)", totalFileSize, options.maxTotalFileSize), false); } return new CompilationDescription(compilation.build(), fileContents); }
From source file:eu.interedition.text.Name.java
public Name(QName name) { final String nsStr = Strings.emptyToNull(name.getNamespaceURI()); this.namespace = (nsStr == null ? null : URI.create(nsStr)); this.localName = name.getLocalPart(); }
From source file:fathom.realm.redis.RedisRealm.java
@Override public void setup(Config config) { super.setup(config); redisUrl = Strings.emptyToNull(config.getString("url")); Preconditions.checkNotNull(redisUrl, "Url must be specified!"); if (config.hasPath("password")) { redisPassword = Strings.emptyToNull(config.getString("password")); }/*w ww . j a v a 2 s .co m*/ passwordMapping = "${username}:password"; if (config.hasPath("passwordMapping")) { passwordMapping = Strings.emptyToNull(config.getString("passwordMapping")); } Preconditions.checkNotNull(passwordMapping, "You must specify 'passwordMapping'"); if (config.hasPath("nameMapping")) { nameMapping = Strings.emptyToNull(config.getString("nameMapping")); } if (config.hasPath("emailMapping")) { emailMapping = Strings.emptyToNull(config.getString("emailMapping")); } if (config.hasPath("roleMapping")) { roleMapping = Strings.emptyToNull(config.getString("roleMapping")); } if (config.hasPath("permissionMapping")) { permissionMapping = Strings.emptyToNull(config.getString("permissionMapping")); } if (config.hasPath("startScript")) { startScript = Strings.emptyToNull(config.getString("startScript")); } if (config.hasPath("stopScript")) { stopScript = Strings.emptyToNull(config.getString("stopScript")); } }
From source file:com.reprezen.swagedit.assist.StyledCompletionProposal.java
@Override public void apply(IDocument document) { int length = 0; int offset = replacementOffset; String text = replacementString; if (Strings.emptyToNull(prefix) != null) { if (replacementString.startsWith(prefix)) { text = replacementString.substring(prefix.length()); } else if (replacementString.contains(prefix)) { offset = replacementOffset - prefix.length(); length = prefix.length();/*from w ww.j a v a 2 s . c om*/ } } try { document.replace(offset, length, text); } catch (BadLocationException x) { // ignore } }
From source file:com.google.idea.blaze.java.run.producers.BlazeJUnitTestFilterFlags.java
@Nullable public static String testFilterForClassesAndMethods(MultiMap<PsiClass, PsiMethod> methodsPerClass, JUnitVersion version) {/*from w w w . j a v a2 s .c o m*/ StringBuilder output = new StringBuilder(); for (Entry<PsiClass, Collection<PsiMethod>> entry : methodsPerClass.entrySet()) { String filter = testFilterForClassAndMethods(entry.getKey(), version, entry.getValue()); if (filter != null) { output.append(filter); } } return Strings.emptyToNull(output.toString()); }
From source file:org.jclouds.ec2.xml.TagHandler.java
/** * {@inheritDoc}/* w w w .ja v a 2 s. c o m*/ */ @Override public void endElement(String uri, String name, String qName) throws SAXException { if (equalsOrSuffix(qName, "resourceId")) { builder.resourceId(currentOrNull(currentText)); } else if (equalsOrSuffix(qName, "resourceType")) { builder.resourceType(currentOrNull(currentText)); } else if (equalsOrSuffix(qName, "key")) { builder.key(currentOrNull(currentText)); } else if (equalsOrSuffix(qName, "value")) { // empty is same as not present builder.value(Strings.emptyToNull(currentOrNull(currentText))); } currentText = new StringBuilder(); }
From source file:org.n52.shetland.w3c.xlink.Reference.java
public Reference setArcrole(String arcrole) { this.arcrole = Optional.ofNullable(Strings.emptyToNull(arcrole)); return this; }