List of usage examples for com.google.common.base Strings isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable String string)
From source file:com.github.jcustenborder.kafka.connect.cdc.ChangeAssertions.java
static void assertMap(Map<String, ?> expected, Map<String, ?> actual, String message) { if (null == expected && null == actual) { return;/*ww w . j a va 2 s. c om*/ } String prefix = Strings.isNullOrEmpty(message) ? "" : message + ": "; assertNotNull(expected, prefix + "expected cannot be null"); assertNotNull(actual, prefix + "actual cannot be null"); MapDifference<String, ?> mapDifference = Maps.difference(expected, actual); assertTrue(mapDifference.areEqual(), new MapDifferenceSupplier(mapDifference, prefix)); }
From source file:qa.qcri.nadeef.web.rest.SourceAction.java
public static void setup(SQLDialect dialect) { Tracer tracer = Tracer.getTracer(SourceAction.class); get("/:project/data/source", (request, response) -> { JsonObject json = new JsonObject(); JsonArray result = new JsonArray(); String project = request.params("project"); if (Strings.isNullOrEmpty(project)) throw new IllegalArgumentException("Input is not valid."); DBConfig dbConfig = new DBConfig(NadeefConfiguration.getDbConfig()); dbConfig.switchDatabase(project); try {/*from ww w . j av a 2 s .c o m*/ List<String> tables = DBMetaDataTool.getTables(dbConfig); for (String tableName : tables) if (!tableName.equalsIgnoreCase("AUDIT") && !tableName.equalsIgnoreCase("VIOLATION") && !tableName.equalsIgnoreCase("RULE") && !tableName.equalsIgnoreCase("RULETYPE") && !tableName.equalsIgnoreCase("REPAIR") && !tableName.equalsIgnoreCase("PROJECT") && tableName.toUpperCase().startsWith(TABLE_PREFIX)) result.add(new JsonPrimitive(tableName)); json.add("data", result); return json; } catch (Exception ex) { tracer.err("Exception", ex); throw new RuntimeException(ex); } }); }
From source file:org.elasticsearch.plugin.readonlyrest.utils.BasicAuthUtils.java
public static String getBasicAuthUser(Map<String, String> headers) { String authHeader = extractAuthFromHeader(headers.get("Authorization")); if (!Strings.isNullOrEmpty(authHeader)) { try {// w w w.j ava 2s . co m String[] splitted = new String(Base64.getDecoder().decode(authHeader)).split(":"); return splitted.length > 0 ? splitted[0] : null; } catch (IllegalArgumentException e) { e.printStackTrace(); } } return null; }
From source file:br.com.tecsinapse.exporter.converter.LocalDateTimeTableCellConverter.java
@Override public LocalDateTime apply(String input) { return Strings.isNullOrEmpty(input) ? null : LocalDateTime.parse(input); }
From source file:io.opencensus.contrib.agent.Resources.java
/** * Returns a resource of the given name as a temporary file. * * @param resourceName name of the resource * @return a temporary {@link File} containing a copy of the resource * @throws FileNotFoundException if no resource of the given name is found * @throws IOException if an I/O error occurs *//*w w w.j a v a 2s . co m*/ static File getResourceAsTempFile(String resourceName) throws IOException { checkArgument(!Strings.isNullOrEmpty(resourceName), "resourceName"); File file = File.createTempFile(resourceName, ".tmp"); try (OutputStream os = new FileOutputStream(file)) { getResourceAsTempFile(resourceName, file, os); return file; } }
From source file:org.glowroot.common.util.Throwables.java
public static String getBestMessage(Throwable t) { Throwable rootCause;/*from www.j a va 2 s . c o m*/ try { rootCause = com.google.common.base.Throwables.getRootCause(t); } catch (IllegalArgumentException e) { // guava's Throwables throws IllegalArgumentException if there is a loop in the causal // chain (since guava 23.0) logger.warn(e.getMessage(), e); return t.toString(); } // using Throwable.toString() to include the exception class name // because sometimes hard to know what message means without this context // e.g. java.net.UnknownHostException: google.com String message = rootCause.toString(); if (Strings.isNullOrEmpty(message)) { // unlikely, but just in case return rootCause.getClass().getName(); } else { return message; } }
From source file:org.zalando.crypto.Decrypters.java
public static List<Decrypter> findByPrefix(List<Decrypter> decrypters, String prefix) { Preconditions.checkNotNull(decrypters, "'Decrypter's-list should not be null"); Preconditions.checkArgument(!Strings.isNullOrEmpty(prefix), "'prefix' should never be null or empty."); return Lists.newArrayList(Iterables.filter(decrypters, Predicates.and(new PrefixedDecrypterPredicate(), new PrefixPredicate(prefix)))); }
From source file:org.shaf.shell.util.ViewUtils.java
/** * Returns a progress bar.//from ww w.ja va 2 s . co m * * @param progress * the progress indicator. * @return the progress bar. */ public static final String bar(final Progress progress) { int percent = (int) (100 * progress.getValue()); int len = (int) (PROGRESS_BAR_LENGTH * progress.getValue()); StringBuilder bar = new StringBuilder(); bar.append('['); bar.append(Strings.repeat("=", len)); bar.append(Strings.repeat(" ", 20 - len)); bar.append(Strings.repeat(" ", 3 - String.valueOf(percent).length())); bar.append(String.valueOf(percent) + "%"); bar.append(']'); bar.append(((Strings.isNullOrEmpty(progress.getMessage())) ? "" : " : " + progress.getMessage())); return bar.toString(); }
From source file:org.zanata.client.commands.DocNameWithExt.java
public static DocNameWithExt from(String filename) { String extension = FilenameUtils.getExtension(filename); Preconditions.checkArgument(!Strings.isNullOrEmpty(extension), "expected a full filename (with extension)"); return new DocNameWithExt(filename); }
From source file:org.akraievoy.base.Parse.java
@Nullable public static Byte oneByte(@Nullable String value, @Nullable Byte defaultVal) { if (Strings.isNullOrEmpty(value)) { return defaultVal; }/*from w w w .ja va2 s . c om*/ try { return Byte.parseByte(value); } catch (NumberFormatException e) { return defaultVal; } }