List of usage examples for com.google.common.base Strings isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable String string)
From source file:org.onosproject.xosclient.api.VtnServiceId.java
/** * Returns the VtnServiceId with value./*from www. j a v a2s . c o m*/ * * @param id service id * @return CordServiceId */ public static VtnServiceId of(String id) { checkArgument(!Strings.isNullOrEmpty(id), "VTN service ID cannot be null"); return new VtnServiceId(id); }
From source file:org.jboss.hal.core.expression.Expression.java
public static Expression of(String value) { if (!Strings.isNullOrEmpty(value) && value.trim().length() != 0) { if (value.contains(EXPRESSION_START) && value.indexOf(EXPRESSION_END) > 1) { int init = value.indexOf(EXPRESSION_START); int end = value.indexOf(EXPRESSION_END); String token = value.substring(init + 2, end); String prefix = null; String suffix = null; if (init > 0) { prefix = value.substring(0, init); }// ww w. j a v a 2 s .co m if (end < value.length() - 1) { suffix = value.substring(end + 1); } int idx = token.indexOf(":"); String defaultValue = null; if (idx != -1) { defaultValue = token.substring(idx + 1, token.length()); token = token.substring(0, idx); } return new Expression(prefix, token, defaultValue, suffix); } else { throw new IllegalArgumentException( "Illegal expression \"" + value + "\": Please use the pattern ${key[:default-value]}"); } } throw new IllegalArgumentException("Empty expression: Please use the pattern ${key[:default-value]}"); }
From source file:com.edgar.jdbc.codegen.CodeGenUtil.java
public static boolean checkIfSourceCodeExists(String rootFolderPath, String packageName) throws Exception { boolean exists = false; String path = ""; if (!Strings.isNullOrEmpty(packageName)) { path = CharMatcher.anyOf(".").replaceFrom(packageName, "/"); if (!Strings.isNullOrEmpty(rootFolderPath)) { path = rootFolderPath + "/" + path; }//from ww w. j a v a 2s . co m logger.info("Checking if dir structure:{} exists", path); File file = new File(path); if (file.exists() && file.list().length > 0) { logger.debug("Found package structure:{} with {} files", path, file.list().length); exists = true; } else { logger.info("Package structure does not exist:" + path); exists = false; } } return exists; }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.PropertyChangeHandler.java
public static void handle(String property) { if (Strings.isNullOrEmpty(property)) { return;//from w w w .j a va 2s . co m } if (property.equals(MMXConfigKeys.MAX_XMPP_RATE)) { int rate = MMXConfiguration.getConfiguration().getInt(MMXConfigKeys.MAX_XMPP_RATE, MMXServerConstants.DEFAULT_MAX_XMPP_RATE); RateLimiterService.updateRates(MMXServerConstants.XMPP_RATE_TYPE, rate); } else if (property.equals(MMXConfigKeys.MAX_HTTP_RATE)) { int rate = MMXConfiguration.getConfiguration().getInt(MMXConfigKeys.MAX_HTTP_RATE, MMXServerConstants.DEFAULT_MAX_HTTP_RATE); RateLimiterService.updateRates(MMXServerConstants.HTTP_RATE_TYPE, rate); } else if (MMXConfigKeys.EXT_SERVICE_EVENT_GEO_SECRET.equals(property)) { // update the secret for geo component // TODO add proper Rest API to configure components try { String secret = MMXConfiguration.getConfiguration() .getString(MMXConfigKeys.EXT_SERVICE_EVENT_GEO_SECRET); if (secret != null && secret.length() > 0) { ExternalComponentManager.setDefaultSecret(secret); } } catch (ModificationNotAllowedException e) { LOGGER.warn("failed to update secret for components.", e); } } else if (MMXConfigKeys.EXT_SERVICE_PORT.equals(property)) { // update the secret for geo component // TODO add proper Rest API to configure components try { String port = MMXConfiguration.getConfiguration().getString(MMXConfigKeys.EXT_SERVICE_PORT); if (port != null && port.length() > 0) { ExternalComponentManager.setServicePort(Integer.parseInt(port)); XMPPServer.getInstance().getConnectionManager().enableComponentListener(true); } } catch (ModificationNotAllowedException e) { LOGGER.warn("failed to update port for components.", e); } } else if (MMXConfigKeys.EXT_SERVICE_ENABLED.equals(property)) { // enable or disable external component service boolean enabled = MMXConfiguration.getConfiguration().getBoolean(MMXConfigKeys.EXT_SERVICE_ENABLED, false); XMPPServer.getInstance().getConnectionManager().enableComponentListener(enabled); } }
From source file:com.google.cloud.hadoop.util.ConfigurationUtil.java
/** * Gets value for the given key or throws if value is not found. *//*from w ww .j a va 2 s . c o m*/ public static String getMandatoryConfig(Configuration config, String key) throws IOException { String value = config.get(key); if (Strings.isNullOrEmpty(value)) { throw new IOException("Must supply a value for configuration setting: " + key); } return value; }
From source file:org.glowroot.agent.GlowrootDir.java
public static File getGlowrootDir(@Nullable File glowrootJarFile) { String testDirPath = System.getProperty("glowroot.test.dir"); if (!Strings.isNullOrEmpty(testDirPath)) { return new File(testDirPath); }/*w ww . jav a2 s .c o m*/ if (glowrootJarFile == null) { throw new IllegalStateException( "Property glowroot.test.dir is required when running" + " tests with no glowroot jar file"); } File glowrootDir = glowrootJarFile.getParentFile(); if (glowrootDir == null) { // the file does not name a parent, so it must be current dir return new File("."); } return glowrootDir; }
From source file:com.github.jcustenborder.kafka.connect.cdc.KafkaAssert.java
public static void assertField(final Field expected, final Field actual, String message) { String prefix = Strings.isNullOrEmpty(message) ? "" : message + ": "; if (null == expected) { assertNull(actual, prefix + "actual should be null."); return;//www .ja v a2 s.c o m } assertEquals(expected.name(), actual.name(), prefix + "name does not match"); assertEquals(expected.index(), actual.index(), prefix + "name does not match"); assertSchema(expected.schema(), actual.schema(), prefix + "schema does not match"); }
From source file:org.eclipse.buildship.core.util.collections.CollectionsUtils.java
/** * Splits the given string for each space that is found. * * @param string the string to split, can be null * @return the split string with each segment being an element of the returned list, never null *///from ww w .j a va2 s. c o m public static ImmutableList<String> splitBySpace(String string) { return Strings.isNullOrEmpty(string) ? ImmutableList.<String>of() : ImmutableList.copyOf(Splitter.on(SPACE).omitEmptyStrings().splitToList(string)); }
From source file:com.google.cloud.hadoop.gcsio.GoogleCloudStorageExceptions.java
/** * Creates FileNotFoundException with suitable message for a GCS bucket or object. *//*from ww w . j a va 2 s . co m*/ public static FileNotFoundException getFileNotFoundException(String bucketName, String objectName) { Preconditions.checkArgument(!Strings.isNullOrEmpty(bucketName), "bucketName must not be null or empty"); if (objectName == null) { objectName = ""; } return new FileNotFoundException(String.format("Item not found: %s/%s", bucketName, objectName)); }
From source file:com.google.devtools.moe.client.InvalidProject.java
public static void assertNotEmpty(String str, String message) throws InvalidProject { assertFalse(Strings.isNullOrEmpty(str), message); }