List of usage examples for com.google.common.base Strings isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable String string)
From source file:com.axelor.apps.tool.net.URLService.java
/** * Test la validit d'une url.//from w w w . j a va 2 s .c o m * * @param url * L'URL tester. * * @return */ public static String notExist(String url) { if (Strings.isNullOrEmpty(url)) { return I18n.get(IExceptionMessage.URL_SERVICE_1); } try { URL fileURL = new URL(url); fileURL.openConnection().connect(); return null; } catch (java.net.MalformedURLException ex) { ex.printStackTrace(); return String.format(I18n.get(IExceptionMessage.URL_SERVICE_2), url); } catch (java.io.IOException ex) { ex.printStackTrace(); return String.format(I18n.get(IExceptionMessage.URL_SERVICE_3), url); } }
From source file:org.apache.cloudstack.acl.Rule.java
private static boolean validate(final String rule) { if (Strings.isNullOrEmpty(rule) || !ALLOWED_PATTERN.matcher(rule).matches()) { throw new InvalidParameterValueException( "Only API names and wildcards are allowed, invalid rule provided: " + rule); }/*from ww w.j a v a 2 s. com*/ return true; }
From source file:br.com.tecsinapse.exporter.converter.LocalDateTableCellConverter.java
@Override public LocalDate apply(String input) { return Strings.isNullOrEmpty(input) ? null : LocalDateTime.parse(input).toLocalDate(); }
From source file:org.apache.cloudstack.cloudian.client.CloudianUtils.java
/** * Generates RFC-2104 compliant HMAC signature * @param data// ww w.j a va 2s. co m * @param key * @return returns the generated signature or null on error */ public static String generateHMACSignature(final String data, final String key) { if (Strings.isNullOrEmpty(data) || Strings.isNullOrEmpty(key)) { return null; } try { final SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM); final Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM); mac.init(signingKey); byte[] rawHmac = mac.doFinal(data.getBytes()); return Base64.encodeBase64String(rawHmac); } catch (final Exception e) { LOG.error("Failed to generate HMAC signature from provided data and key, due to: ", e); } return null; }
From source file:com.facebook.buck.util.trace.uploader.launcher.UploaderLauncher.java
/** Upload chrome trace in background process which runs even after current process dies. */ public static void uploadInBackground(BuildId buildId, Path traceFilePath, String traceFileKind, URI traceUploadUri, Path logFile, CompressionType compressionType) { LOG.debug("Uploading build trace in the background. Upload will log to %s", logFile); String buckClasspath = BuckClasspath.getBuckClasspathFromEnvVarOrNull(); if (Strings.isNullOrEmpty(buckClasspath)) { LOG.error(BuckClasspath.ENV_VAR_NAME + " env var is not set. Will not upload the trace file."); return;/*from w ww . j a v a 2 s. c om*/ } try { String[] args = { "java", "-cp", buckClasspath, "com.facebook.buck.util.trace.uploader.Main", "--buildId", buildId.toString(), "--traceFilePath", traceFilePath.toString(), "--traceFileKind", traceFileKind, "--baseUrl", traceUploadUri.toString(), "--log", logFile.toString(), "--compressionType", compressionType.name(), }; Runtime.getRuntime().exec(args); } catch (IOException e) { LOG.error(e, e.getMessage()); } }
From source file:com.github.jcustenborder.kafka.connect.utils.AssertSchema.java
public static void assertSchema(final Schema expected, final Schema actual, String message) { final String prefix = Strings.isNullOrEmpty(message) ? "" : message + ": "; if (null == expected) { assertNull(actual, prefix + "actual should not be null."); return;//w ww . j a va2s . co m } assertNotNull(expected, prefix + "expected schema should not be null."); assertNotNull(actual, prefix + "actual schema should not be null."); assertEquals(expected.name(), actual.name(), prefix + "schema.name() should match."); assertEquals(expected.type(), actual.type(), prefix + "schema.type() should match."); assertEquals(expected.defaultValue(), actual.defaultValue(), prefix + "schema.defaultValue() should match."); assertEquals(expected.isOptional(), actual.isOptional(), prefix + "schema.isOptional() should match."); assertEquals(expected.doc(), actual.doc(), prefix + "schema.doc() should match."); assertEquals(expected.version(), actual.version(), prefix + "schema.version() should match."); assertMap(expected.parameters(), actual.parameters(), prefix + "schema.parameters() should match."); if (null != expected.defaultValue()) { assertNotNull(actual.defaultValue(), "actual.defaultValue() should not be null."); Class<?> expectedType = null; switch (expected.type()) { case INT8: expectedType = Byte.class; break; case INT16: expectedType = Short.class; break; case INT32: expectedType = Integer.class; break; case INT64: expectedType = Long.class; break; case FLOAT32: expectedType = Float.class; break; case FLOAT64: expectedType = Float.class; break; default: break; } if (null != expectedType) { assertTrue(actual.defaultValue().getClass().isAssignableFrom(expectedType), String.format("actual.defaultValue() should be a %s", expectedType.getSimpleName())); } } switch (expected.type()) { case ARRAY: assertSchema(expected.valueSchema(), actual.valueSchema(), message + "valueSchema does not match."); break; case MAP: assertSchema(expected.keySchema(), actual.keySchema(), message + "keySchema does not match."); assertSchema(expected.valueSchema(), actual.valueSchema(), message + "valueSchema does not match."); break; case STRUCT: List<Field> expectedFields = expected.fields(); List<Field> actualFields = actual.fields(); assertEquals(expectedFields.size(), actualFields.size(), prefix + "Number of fields do not match."); for (int i = 0; i < expectedFields.size(); i++) { Field expectedField = expectedFields.get(i); Field actualField = actualFields.get(i); assertField(expectedField, actualField, "index " + i); } break; } }
From source file:org.haiku.haikudepotserver.dataobjects.PkgVersionLocalization.java
public static Optional<PkgVersionLocalization> getForPkgVersionAndNaturalLanguageCode(ObjectContext context, PkgVersion pkgVersion, final String naturalLanguageCode) { Preconditions.checkArgument(null != context, "the context must be supplied"); Preconditions.checkArgument(null != pkgVersion, "the pkg version must be supplied"); Preconditions.checkArgument(!Strings.isNullOrEmpty(naturalLanguageCode), "the natural language code is required"); return getForPkgVersion(context, pkgVersion).stream() .filter(pvl -> pvl.getNaturalLanguage().getCode().equals(naturalLanguageCode)) .collect(SingleCollector.optional()); }
From source file:org.zanata.client.commands.QualifiedSrcDocName.java
public static QualifiedSrcDocName from(String qualifiedName) { String extension = FilenameUtils.getExtension(qualifiedName); Preconditions.checkArgument(!Strings.isNullOrEmpty(extension), "expect a qualified document name (with extension)"); return new QualifiedSrcDocName(qualifiedName); }
From source file:uk.co.bubblebearapps.motionaiclient.view.customsetters.ImageViewSetters.java
@BindingAdapter(value = { "imageUrl", "cornerRadius" }, requireAll = false) public static void setImageUrl(final ImageView imageView, String url, final float cornerRadius) { if (Strings.isNullOrEmpty(url)) { imageView.setImageBitmap(null);//from ww w . ja va 2s . c om } else if (url.endsWith("gif")) { Glide.with(imageView.getContext()).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(imageView); } else { if (cornerRadius > 0) { Glide.with(imageView.getContext()).load(url).asBitmap().into(new BitmapImageViewTarget(imageView) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory .create(imageView.getContext().getResources(), resource); circularBitmapDrawable.setCornerRadius(cornerRadius); imageView.setImageDrawable(circularBitmapDrawable); } }); } else { Glide.with(imageView.getContext()).load(url).into(imageView); } } }
From source file:com.google.gerrit.acceptance.ConfigAnnotationParser.java
private static void parseAnnotation(Config cfg, GerritConfig c) { ArrayList<String> l = Lists.newArrayList(splitter.split(c.name())); if (l.size() == 2) { if (!Strings.isNullOrEmpty(c.value())) { cfg.setString(l.get(0), null, l.get(1), c.value()); } else {//from ww w . j a v a 2 s. co m String[] values = c.values(); cfg.setStringList(l.get(0), null, l.get(1), Arrays.asList(values)); } } else if (l.size() == 3) { if (!Strings.isNullOrEmpty(c.value())) { cfg.setString(l.get(0), l.get(1), l.get(2), c.value()); } else { cfg.setStringList(l.get(0), l.get(1), l.get(2), Arrays.asList(c.values())); } } else { throw new IllegalArgumentException( "GerritConfig.name must be of the format section.subsection.name or section.name"); } }