List of usage examples for com.google.common.base Strings nullToEmpty
public static String nullToEmpty(@Nullable String string)
From source file:io.sarl.eclipse.launching.sreproviding.StandardProjectSREProvider.java
/** * @param project - the project./*ww w.j a va 2 s. c om*/ */ public StandardProjectSREProvider(IProject project) { boolean tmpSpecific = false; boolean tmpUseSystem = false; String tmpSRE = null; if (project != null) { try { QualifiedName propertyName = RuntimeEnvironmentPropertyPage .qualify(RuntimeEnvironmentPropertyPage.PROPERTY_NAME_HAS_PROJECT_SPECIFIC); tmpSpecific = Boolean.parseBoolean(Objects.firstNonNull(project.getPersistentProperty(propertyName), Boolean.FALSE.toString())); if (tmpSpecific) { propertyName = RuntimeEnvironmentPropertyPage .qualify(RuntimeEnvironmentPropertyPage.PROPERTY_NAME_USE_SYSTEM_WIDE_SRE); tmpUseSystem = Boolean.parseBoolean(Objects .firstNonNull(project.getPersistentProperty(propertyName), Boolean.FALSE.toString())); if (!tmpUseSystem) { propertyName = RuntimeEnvironmentPropertyPage .qualify(RuntimeEnvironmentPropertyPage.PROPERTY_NAME_SRE_INSTALL_ID); tmpSRE = Strings.nullToEmpty(project.getPersistentProperty(propertyName)); } } } catch (CoreException e) { SARLEclipsePlugin.getDefault().log(e); } } this.projectSpecificConfiguration = tmpSpecific; this.projectUseSystemSRE = tmpUseSystem; this.projectSRE = tmpSRE; }
From source file:org.dllearner.utilities.MapUtils.java
/** * Return map in TSV format.//www . j a v a 2s.com * @param map the map * @param keyHeader header for key column * @param valueHeader header for value column * @param <K> * @param <V> * * @return TSV formatted String */ public static <K, V> String asTSV(Map<K, V> map, String keyHeader, String valueHeader) { return Strings.nullToEmpty(keyHeader) + "\t" + Strings.nullToEmpty(valueHeader) + "\n" + Joiner.on("\n").withKeyValueSeparator("\t").join(map); }
From source file:io.druid.query.filter.InDimFilter.java
@JsonCreator public InDimFilter(@JsonProperty("dimension") String dimension, @JsonProperty("values") List<String> values, @JsonProperty("extractionFn") ExtractionFn extractionFn) { Preconditions.checkNotNull(dimension, "dimension can not be null"); Preconditions.checkArgument(values != null && !values.isEmpty(), "values can not be null or empty"); this.values = ImmutableSortedSet.copyOf(Iterables.transform(values, new Function<String, String>() { @Override//from w w w. j a va2 s . c om public String apply(String input) { return Strings.nullToEmpty(input); } })); this.dimension = dimension; this.extractionFn = extractionFn; this.longPredicateSupplier = getLongPredicateSupplier(); }
From source file:io.druid.server.emitter.EmitterModule.java
@Override public void configure(Binder binder) { String emitterType = props.getProperty(EMITTER_PROPERTY, ""); binder.install(new NoopEmitterModule()); binder.install(new LogEmitterModule()); binder.install(new HttpEmitterModule()); binder.install(new ParametrizedUriEmitterModule()); binder.install(new ComposingEmitterModule()); binder.bind(Emitter.class).toProvider(new EmitterProvider(emitterType)).in(LazySingleton.class); MapBinder<String, String> extraServiceDimensions = MapBinder.newMapBinder(binder, String.class, String.class, ExtraServiceDimensions.class); String version = getClass().getPackage().getImplementationVersion(); extraServiceDimensions.addBinding("version").toInstance(Strings.nullToEmpty(version)); // Version is null during `mvn test`. }
From source file:uk.ac.stfc.isis.ibex.configserver.displaying.DisplayConfiguration.java
/** * Returns the name of the configuration. * * @return the name */ public String name() { return Strings.nullToEmpty(name); }
From source file:org.apache.sentry.tests.e2e.hive.hiveserver.ExternalHiveServer.java
@Override public synchronized void shutdown() throws Exception { if (process != null) { process.destroy();//from www . ja v a 2s. co m process = null; String pid = Strings.nullToEmpty(Files.readFirstLine(new File(logDir, "hs2.pid"), Charsets.UTF_8)) .trim(); if (!pid.isEmpty()) { LOGGER.info("Killing " + pid); Process killCommand = Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", "kill " + pid }); // TODO this isn't strictly correct but kill won't output much data String error = read(killCommand.getErrorStream()); String output = read(killCommand.getInputStream()); LOGGER.info("Kill exit code " + killCommand.waitFor() + ", output = '" + output + "', error = '" + error + "'"); } } }
From source file:org.mitre.oauth2.service.impl.BlacklistAwareRedirectResolver.java
@Override protected boolean redirectMatches(String requestedRedirect, String redirectUri) { if (isStrictMatch()) { // we're doing a strict string match for all clients return Strings.nullToEmpty(requestedRedirect).equals(redirectUri); } else {//from w w w.j ava 2s . co m // otherwise do the prefix-match from the library return super.redirectMatches(requestedRedirect, redirectUri); } }
From source file:org.gbif.refine.datasets.ebd.ShoreBirdCensus.java
/** * Iterates over original source file and does the following: * i) cleans it (e.g. converting dates to ISO format, matching scientific names to GBIF Backbone Taxonomy) * ii) augments it (e.g. adds occurrenceID, higher taxonomy columns, etc) * iii) transforms it into star format (two files events.txt list of unique sampling events and occurrence.txt a * list of all observations from all sampling events) * * @param output directory to write files to * * @throws IOException if method fails/*from w w w . ja v a 2s . c om*/ */ public static void processShoreBirdCensus(File output) throws IOException { // load the original source file to process InputStream fis = ShoreBirdCensus.class.getResourceAsStream("/datasets/ebd/ShoreBirdCensus_1993.csv"); // create an iterator on the file CSVReader reader = CSVReaderFactory.build(fis, "Latin1", ";", '"', 1); // get header row for the new event and occurrence files that this method will output String[] header = getHeader(); // sampling events file Writer writerEvents = FileUtils.startEventsFile(output, header); // observations file Writer writerOccs = FileUtils.startOccurrencesFile(output, header); // to capture all unique eventIDs Set<String> events = Sets.newHashSet(); ClosableReportingIterator<String[]> iter = null; int line = 0; try { iter = reader.iterator(); while (iter.hasNext()) { line++; String[] record = iter.next(); if (record == null || record.length == 0) { continue; } // create new augmented record String[] modifiedRecord = Arrays.copyOf(record, header.length); // unique eventID String eventID = Strings.nullToEmpty(modifiedRecord[0]); // unique occurrenceID (institutionCode:datasetID:sequentialID) modifiedRecord[25] = "EBD-CSIC:SP_SI001346_ShoreBirdCensus:" + eventID + ":" + String.valueOf(line); // add static values modifiedRecord[24] = "EBD-CSIC"; modifiedRecord[26] = "http://creativecommons.org/licenses/by/4.0/legalcode"; modifiedRecord[27] = "Event"; modifiedRecord[28] = "HumanObservation"; modifiedRecord[38] = "square_kilometre"; modifiedRecord[30] = "individuals"; modifiedRecord[31] = "es"; modifiedRecord[32] = "SP_SI001346_ShoreBirdCensus"; modifiedRecord[33] = "0"; modifiedRecord[34] = "5"; modifiedRecord[35] = "Band census"; modifiedRecord[39] = "Spain"; modifiedRecord[40] = "ES"; modifiedRecord[41] = "Huelva"; modifiedRecord[42] = "Parque Nacional de Doana"; // convert date (column #1) into ISO format String d = modifiedRecord[1]; DateFormat df = new SimpleDateFormat("dd-MMM-yy", new Locale("es", "ES")); Date date = df.parse(d); modifiedRecord[1] = Constants.ISO_DF.format(date); // create eventTime (column #11) String startTime = record[6]; String endTime = record[7]; if (!Strings.isNullOrEmpty(startTime) && !Strings.isNullOrEmpty(endTime) && !startTime.equals("-") && !endTime.equals("-")) { modifiedRecord[6] = startTime + "+01"; modifiedRecord[7] = endTime + "+01"; modifiedRecord[12] = startTime + "+01/" + endTime + "+01"; } // create dynamicProperties (column #12) JSONObject jo = new JSONObject(); if (!Strings.isNullOrEmpty(modifiedRecord[8]) && !modifiedRecord[8].equals("-")) { jo.put("cloudiness", modifiedRecord[8]); } if (!Strings.isNullOrEmpty(modifiedRecord[9]) && !modifiedRecord[9].equals("-")) { jo.put("wind speed", modifiedRecord[9]); } if (!Strings.isNullOrEmpty(modifiedRecord[10]) && !modifiedRecord[10].equals("-")) { jo.put("wind direction", modifiedRecord[10]); } if (!Strings.isNullOrEmpty(modifiedRecord[11]) && !modifiedRecord[11].equals("-")) { jo.put("waves", modifiedRecord[11]); } if (jo.toString().length() > 5) { modifiedRecord[13] = jo.toString(); } // add higher taxonomy String name = modifiedRecord[3]; NameUsageMatch match = MATCHING_SERVICE.match(name, Rank.SPECIES, null, false, false); if (match.getMatchType().equals(NameUsageMatch.MatchType.EXACT)) { modifiedRecord[14] = match.getKingdom(); modifiedRecord[15] = match.getPhylum(); modifiedRecord[16] = match.getClazz(); modifiedRecord[17] = match.getOrder(); modifiedRecord[18] = match.getFamily(); modifiedRecord[19] = match.getGenus(); // specificEpithet if (match.getSpecies() != null) { String[] parts = match.getSpecies().split(" "); if (parts.length == 2) { modifiedRecord[20] = parts[1]; } } modifiedRecord[21] = match.getScientificName(); modifiedRecord[22] = "species"; modifiedRecord[23] = match.getStatus().toString(); } else if (name.equals("Sterna sp.")) { LOG.error("Handling special case for Sterna sp."); modifiedRecord[19] = "Sterna"; modifiedRecord[21] = "Sterna sp."; } else { LOG.error("No exact match for: " + name); } // depending on locationID, set WKT representation and sampleSizeValue of area being sampled // also create one sampling event per location sampled String locationID = modifiedRecord[2]; if (locationID.equalsIgnoreCase("cama")) { modifiedRecord[29] = "POLYGON((-6.529167 36.981904, -6.470398 36.981904, -6.470398 36.931576, -6.529167 36.931576, -6.529167 36.981904))"; modifiedRecord[37] = "4"; modifiedRecord[0] = modifiedRecord[0] + "-CAMA"; } else if (locationID.equalsIgnoreCase("zaca")) { modifiedRecord[29] = "POLYGON((-6.470398 36.931576, -6.429026 36.931576, -6.429026 36.873193, -6.470398 36.873193, -6.470398 36.931576))"; modifiedRecord[37] = "2.1"; modifiedRecord[0] = modifiedRecord[0] + "-ZACA"; } else if (locationID.equalsIgnoreCase("maza")) { modifiedRecord[29] = "POLYGON((-6.429026 36.873193, -6.346964 36.873193, -6.346964 36.804956, -6.429026 36.804956, -6.429026 36.873193))"; modifiedRecord[37] = "2.4"; modifiedRecord[0] = modifiedRecord[0] + "-MAZA"; } else { LOG.error("Line " + line + " has no location!!"); } // occurrenceStatus (present vs absent) modifiedRecord[36] = TermUtils.getOccurrenceStatus(Integer.valueOf(modifiedRecord[4])).toString() .toLowerCase(); // always output line to new occurrences file String row = FileUtils.tabRow(modifiedRecord); writerOccs.write(row); // only output line to events file if event hasn't been included yet if (!events.contains(eventID)) { writerEvents.write(row); events.add(eventID); } } LOG.info("Iterated over " + line + " rows."); LOG.info("Found " + events.size() + " unique events."); } catch (Exception e) { // some error validating this file, report LOG.error("Exception caught while iterating over file", e); } finally { if (iter != null) { iter.close(); } reader.close(); writerEvents.close(); writerOccs.close(); } }
From source file:org.solovyev.android.calculator.history.History.java
@Nullable static List<HistoryState> convertOldHistory(@NonNull String xml) throws Exception { final OldHistory history = OldHistory.fromXml(xml); if (history == null) { // strange, history seems to be broken. Avoid clearing the preference return null; }//from ww w .j a v a 2 s . co m final List<HistoryState> states = new ArrayList<>(); for (OldHistoryState state : history.getItems()) { final OldEditorHistoryState oldEditor = state.getEditorState(); final OldDisplayHistoryState oldDisplay = state.getDisplayState(); final String editorText = oldEditor.getText(); final EditorState editor = EditorState.create(Strings.nullToEmpty(editorText), oldEditor.getCursorPosition()); final DisplayState display = DisplayState.createValid(oldDisplay.getJsclOperation(), null, Strings.nullToEmpty(oldDisplay.getEditorState().getText()), Calculator.NO_SEQUENCE); states.add(HistoryState.builder(editor, display).withTime(state.getTime()) .withComment(state.getComment()).build()); } return states; }
From source file:org.ftccommunity.ftcxtensible.robot.ExtensibleTelemetry.java
public Item data(String tag, String message) { checkArgument(!Strings.isNullOrEmpty(message), "Your message shouldn't be empty."); tag = Strings.nullToEmpty(tag); return delegate.addData(tag, message); // lastModificationTime = System.nanoTime(); // //parent.addData(tag, message); // dataCache.add(new TelemetryItem(tag.equals(EMPTY) ? EMPTY : tag.toUpperCase(Locale.US) + SPACE, message)); }