List of usage examples for com.google.common.base Strings isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable String string)
From source file:com.netflix.metacat.connector.hive.util.PartitionUtil.java
/** * Retrieves the partition values from the partition name. This method also validates the partition keys to that * of the table.//from w w w . j a v a2s. com * * @param tableQName table name * @param table table * @param partName partition name * @return list of partition values */ public static List<String> getPartValuesFromPartName(final QualifiedName tableQName, final Table table, final String partName) { if (Strings.isNullOrEmpty(partName)) { throw new InvalidMetaException(tableQName, partName, null); } final LinkedHashMap<String, String> partSpec = new LinkedHashMap<>(); Warehouse.makeSpecFromName(partSpec, new Path(partName)); final List<String> values = new ArrayList<>(); for (FieldSchema field : table.getPartitionKeys()) { final String key = field.getName(); final String val = partSpec.get(key); if (val == null) { throw new InvalidMetaException(tableQName, partName, null); } values.add(val); } return values; }
From source file:org.apache.isis.core.metamodel.facets.object.value.vsp.ValueSemanticsProviderUtil.java
public static String semanticsProviderNameFromConfiguration(final Class<?> type, final IsisConfiguration configuration) { final String key = SEMANTICS_PROVIDER_NAME_KEY_PREFIX + type.getCanonicalName() + SEMANTICS_PROVIDER_NAME_KEY_SUFFIX; final String semanticsProviderName = configuration.getString(key); return !Strings.isNullOrEmpty(semanticsProviderName) ? semanticsProviderName : null; }
From source file:org.zanata.rest.oauth.OAuthUtil.java
public static Optional<String> getAccessTokenFromHeader(HttpServletRequest request) { OAuthAccessResourceRequest oauthRequest = null; if (!Strings.isNullOrEmpty(request.getHeader(OAuth.HeaderType.AUTHORIZATION))) { try {//w w w . j av a2 s. com // Make the OAuth Request out of this request and validate it // Specify where you expect OAuth access token (request header, body or query string) oauthRequest = new OAuthAccessResourceRequest(request, ParameterStyle.HEADER); return Optional.of(oauthRequest.getAccessToken()); } catch (OAuthSystemException | OAuthProblemException e) { throw new RuntimeException(e); } } log.debug("no Authorization header"); return Optional.empty(); }
From source file:io.macgyver.core.okhttp3.SoftPropertyConfig.java
public static Optional<Integer> safeIntValue(Properties p, String key) { if (p == null || key == null) { return Optional.empty(); }/*from ww w .j av a 2s . co m*/ String val = p.getProperty(key); try { if (Strings.isNullOrEmpty(val)) { return Optional.empty(); } Integer x = Integer.parseInt(val.trim()); return Optional.of(x); } catch (RuntimeException e) { logger.warn("could not parse {} as int", val); } return Optional.empty(); }
From source file:com.google.firebase.internal.FirebaseScheduledExecutor.java
private static ThreadFactory decorateThreadFactory(ThreadFactory threadFactory, String name, Thread.UncaughtExceptionHandler handler) { checkArgument(!Strings.isNullOrEmpty(name)); ThreadFactoryBuilder builder = new ThreadFactoryBuilder().setThreadFactory(threadFactory) .setNameFormat(name).setDaemon(true); if (handler != null) { builder.setUncaughtExceptionHandler(handler); }//from www. j av a2 s .co m return builder.build(); }
From source file:org.haiku.haikudepotserver.dataobjects.Pkg.java
public static Optional<Pkg> tryGetByName(ObjectContext context, String name) { Preconditions.checkArgument(null != context, "a context must be provided to lookup a package"); Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "a name must be provided to get a package"); return Optional.ofNullable(ObjectSelect.query(Pkg.class).where(NAME.eq(name)).sharedCache() .cacheGroup(HaikuDepot.CacheGroup.PKG.name()).selectOne(context)); }
From source file:io.sarl.m2e.M2EUtilities.java
/** Maven version parser. * * @param version - the version string./*from ww w.j av a 2s .com*/ * @return the version. */ public static Version parseMavenVersion(String version) { if (Strings.isNullOrEmpty(version)) { return new Version(0, 0, 0); } // Detect the snapshot boolean isSnapshot; String coreVersion; Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(version); if (matcher.matches()) { coreVersion = matcher.group(1); isSnapshot = true; } else { matcher = SNAPSHOT_VERSION_PATTERN.matcher(version); if (matcher.matches()) { coreVersion = matcher.group(1); isSnapshot = true; } else { coreVersion = version; isSnapshot = false; } } // Parse the numbers String[] parts = coreVersion.split("[.]"); //$NON-NLS-1$ int[] numbers = new int[] { 0, 0, 0 }; for (int i = 0; i < numbers.length && i < parts.length; ++i) { try { int value = Integer.parseInt(parts[i]); numbers[i] = value; } catch (Exception exception) { // Force the exit of the loop since a number cannot be find. i = numbers.length; } } // Reply if (isSnapshot) { return new Version(numbers[0], numbers[1], numbers[2], SNAPSHOT_QUALIFIER); } return new Version(numbers[0], numbers[1], numbers[2]); }
From source file:com.google.idea.blaze.java.sync.JavaLanguageLevelHelper.java
private static LanguageLevel getLanguageLevelFromToolchain(BlazeProjectData blazeProjectData, LanguageLevel defaultLanguageLevel) { BlazeJavaSyncData blazeJavaSyncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class); if (blazeJavaSyncData != null) { String sourceVersion = blazeJavaSyncData.importResult.sourceVersion; if (!Strings.isNullOrEmpty(sourceVersion)) { switch (sourceVersion) { case "6": return LanguageLevel.JDK_1_6; case "7": return LanguageLevel.JDK_1_7; case "8": return LanguageLevel.JDK_1_8; case "9": return LanguageLevel.JDK_1_9; }/*from ww w.j a v a2 s .co m*/ } } return defaultLanguageLevel; }
From source file:org.obiba.mica.dataset.rest.entity.rql.RQLCriterionOpalConverter.java
private String getQuery(String field) { String query = function + "(" + field; if (Strings.isNullOrEmpty(value)) query = query + ")"; else// w w w. j a v a 2 s .c om query = query + ",(" + value + "))"; return not ? "not(" + query + ")" : query; }
From source file:com.marvinformatics.manifestvalidatorplugin.oo.AbsentRule.java
@Override public Optional<String> validate(String value, JarFile jar) { if (Strings.isNullOrEmpty(value)) return Optional.of("Expected to be absent"); return Optional.empty(); }