List of usage examples for com.google.common.base Strings nullToEmpty
public static String nullToEmpty(@Nullable String string)
From source file:org.sonar.api.issue.internal.FieldDiffs.java
public static FieldDiffs parse(@Nullable String s) { FieldDiffs diffs = new FieldDiffs(); if (!Strings.isNullOrEmpty(s)) { Iterable<String> fields = FIELDS_SPLITTER.split(s); for (String field : fields) { String[] keyValues = field.split("="); if (keyValues.length == 2) { String[] values = keyValues[1].split("\\|"); String oldValue = ""; String newValue = ""; if (values.length > 0) { oldValue = Strings.nullToEmpty(values[0]); }/*from w w w .ja v a 2 s . c om*/ if (values.length > 1) { newValue = Strings.nullToEmpty(values[1]); } diffs.setDiff(keyValues[0], oldValue, newValue); } } } return diffs; }
From source file:org.apache.mahout.text.SequenceFilesFromLuceneStorageMapper.java
@Override protected void map(Text key, NullWritable text, Context context) throws IOException, InterruptedException { int docId = Integer.valueOf(key.toString()); DocumentStoredFieldVisitor storedFieldVisitor = l2sConf.getStoredFieldVisitor(); segmentReader.document(docId, storedFieldVisitor); Document document = storedFieldVisitor.getDocument(); List<String> fields = l2sConf.getFields(); Text theKey = new Text(Strings.nullToEmpty(document.get(l2sConf.getIdField()))); Text theValue = new Text(); LuceneSeqFileHelper.populateValues(document, theValue, fields); //if they are both empty, don't write if (isBlank(theKey.toString()) && isBlank(theValue.toString())) { context.getCounter(DataStatus.EMPTY_BOTH).increment(1); return;/*from w w w . java2s. c om*/ } if (isBlank(theKey.toString())) { context.getCounter(DataStatus.EMPTY_KEY).increment(1); } else if (isBlank(theValue.toString())) { context.getCounter(DataStatus.EMPTY_VALUE).increment(1); } context.write(theKey, theValue); }
From source file:org.gradle.api.publish.ivy.internal.artifact.AbstractIvyArtifact.java
@Override public void setClassifier(@Nullable String classifier) { this.classifier = Strings.nullToEmpty(classifier); }
From source file:com.google.devtools.treeshaker.TreeShaker.java
private Parser createParser(Options options) throws IOException { Parser parser = Parser.newParser(j2objcOptions); parser.addSourcepathEntries(j2objcOptions.fileUtil().getSourcePathEntries()); parser.addClasspathEntries(Strings.nullToEmpty(options.getBootclasspath())); parser.addClasspathEntries(j2objcOptions.fileUtil().getClassPathEntries()); return parser; }
From source file:ec.tss.tsproviders.utils.DataFormat.java
/** * Creates a DataFormat from an optional locale, an optional date pattern * and an optional number pattern.// ww w . j a va 2s .co m * * @param locale an optional locale * @param datePattern an optional date pattern * @param numberPattern an optional number pattern * @see Locale * @see SimpleDateFormat * @see DecimalFormat */ public DataFormat(@Nullable Locale locale, @Nullable String datePattern, @Nullable String numberPattern) { this.locale = locale; this.datePattern = Strings.nullToEmpty(datePattern); this.numberPattern = Strings.nullToEmpty(numberPattern); }
From source file:fr.da2i.lup1.entity.formation.Member.java
public String getPhone() { return Strings.nullToEmpty(phone); }
From source file:org.apache.gobblin.source.extractor.filebased.FileBasedSource.java
/** * Initialize the logger.// ww w. ja v a2 s.com * * @param state Source state */ protected void initLogger(SourceState state) { StringBuilder sb = new StringBuilder(); sb.append("["); sb.append(Strings.nullToEmpty(state.getProp(ConfigurationKeys.SOURCE_ENTITY))); sb.append("]"); MDC.put("sourceInfo", sb.toString()); }
From source file:com.google.api.codegen.config.PackagingConfig.java
private static PackagingConfig createFromString(String yamlContents) { Yaml yaml = new Yaml(); @SuppressWarnings("unchecked") Map<String, Object> configMap = (Map<String, Object>) yaml.load(yamlContents); Builder builder = newBuilder().apiName((String) configMap.get("api_name")) .apiVersion(Strings.nullToEmpty((String) configMap.get("api_version"))) .organizationName((String) configMap.get("organization_name")) .protoPackageDependencies(getProtoDeps(configMap, "proto_deps")) .releaseLevel(Configs.parseReleaseLevel((String) configMap.get("release_level"))) .artifactType(PackagingArtifactType.of((String) configMap.get("artifact_type"))) .protoPath((String) configMap.get("proto_path")); if (configMap.containsKey("test_proto_deps")) { builder.protoPackageTestDependencies(getProtoDeps(configMap, "test_proto_deps")); } else if (configMap.containsKey("proto_test_deps")) { // TODO delete this branch once artman always passes in test_proto_deps builder.protoPackageTestDependencies(getProtoDeps(configMap, "proto_test_deps")); }//from www .ja va2s. com return builder.build(); }
From source file:com.attribyte.essem.util.Util.java
/** * Gets an integer parameter from the request with a default value. * @param request The request./* w w w . j av a 2 s .c om*/ * @param name The parameter name. * @param defaultValue The default value. * @return The parameter or default value. */ public static final int getParameter(final HttpServletRequest request, final String name, final int defaultValue) { String strVal = Strings.nullToEmpty(request.getParameter(name)).trim(); if (strVal.length() == 0) return defaultValue; try { return Integer.parseInt(strVal); } catch (NumberFormatException nfe) { return defaultValue; } }
From source file:com.atoito.jeauty.FileProcessor.java
private boolean support(String filePath) { return Strings.nullToEmpty(filePath).endsWith(".java"); }