List of usage examples for com.google.common.base Strings isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable String string)
From source file:qa.qcri.nadeef.web.sql.SQLUtil.java
public static boolean isValidTableName(String s) { boolean isGood = true; if (!Strings.isNullOrEmpty(s)) { Pattern pattern = Pattern.compile("\\w+"); Matcher matcher = pattern.matcher(s); if (!matcher.find()) isGood = false;/*from w w w.j av a 2s . co m*/ } return isGood; }
From source file:org.apache.kylin.cube.cuboid.CuboidModeEnum.java
public static CuboidModeEnum getByModeName(String modeName) { if (Strings.isNullOrEmpty(modeName)) { return null; }/*from ww w .j av a 2 s.c o m*/ for (CuboidModeEnum mode : CuboidModeEnum.values()) { if (mode.modeName.equals(modeName.toUpperCase())) { return mode; } } return null; }
From source file:com.google.devtools.build.lib.util.UserUtils.java
/** * Returns the originating user for this build from the command-line or the environment. *//* w w w.ja v a 2 s. co m*/ public static String getOriginatingUser(String originatingUser) { if (!Strings.isNullOrEmpty(originatingUser)) { return originatingUser; } return UserUtils.getUserName(); }
From source file:org.onos.yangtools.util.PropertyUtils.java
/** * Obtains the given property from the System properties and returns as an int. If the property * is not found the specified default value is returned. If the property value can't be parsed * to an int, a warning is logged and the default value is returned. * * @param propName the name of the property to get * @param defaultValue the default value * @return the System property as an int or the <code>defaultValue</code> if not found. *///from w ww . j a v a2 s . c o m public static int getIntSystemProperty(String propName, int defaultValue) { int propValue = defaultValue; String strValue = System.getProperty(propName); if (!Strings.isNullOrEmpty(strValue) && !strValue.trim().isEmpty()) { try { propValue = Integer.parseInt(strValue); } catch (NumberFormatException e) { LOG.warn("Cannot parse value {} for system property {}, using default {}", strValue, propName, defaultValue); } } return propValue; }
From source file:org.haiku.haikudepotserver.support.web.NaturalLanguageWebHelper.java
/** * <p>This will look at parameters on the supplied request and will return a natural language. It will * resort to English language if no other language is able to be derived.</p> *//*from ww w .jav a2s .c om*/ public static NaturalLanguage deriveNaturalLanguage(ObjectContext context, HttpServletRequest request) { Preconditions.checkNotNull(context); if (null != request) { String naturalLanguageCode = request.getParameter(WebConstants.KEY_NATURALLANGUAGECODE); if (!Strings.isNullOrEmpty(naturalLanguageCode)) { Optional<NaturalLanguage> naturalLanguageOptional = NaturalLanguage.getByCode(context, naturalLanguageCode); if (naturalLanguageOptional.isPresent()) { return naturalLanguageOptional.get(); } else { LOGGER.info("the natural language '{}' was specified, but was not able to be found", naturalLanguageCode); } } // see if we can deduce it from the locale. Locale locale = request.getLocale(); if (null != locale) { Iterator<String> langI = Splitter.on(Pattern.compile("[-_]")).split(locale.toLanguageTag()) .iterator(); if (langI.hasNext()) { Optional<NaturalLanguage> naturalLanguageOptional = NaturalLanguage.getByCode(context, langI.next()); if (naturalLanguageOptional.isPresent() && naturalLanguageOptional.get().getIsPopular()) { return naturalLanguageOptional.get(); } } } } return NaturalLanguage.getByCode(context, NaturalLanguage.CODE_ENGLISH).get(); }
From source file:org.apache.bookkeeper.tools.framework.CliCommandGroup.java
@SuppressWarnings("unchecked") private static <GlobalFlagsT extends CliFlags> CliSpec<GlobalFlagsT> updateSpec(CliSpec<GlobalFlagsT> spec) { CliSpec<GlobalFlagsT> newSpec; if (Strings.isNullOrEmpty(spec.usage())) { newSpec = CliSpec.newBuilder(spec) .withUsage(String.format("%s %s [command] [command options]", spec.parent(), spec.name())) .withFlags(null).build(); } else {/*w w w. ja va 2 s .c om*/ newSpec = CliSpec.newBuilder(spec).withFlags(null).build(); } String path = newSpec.parent() + " " + newSpec.name(); for (Command<GlobalFlagsT> cmd : newSpec.commands()) { if (cmd instanceof CliCommand) { CliCommand<GlobalFlagsT, GlobalFlagsT> cliCmd = (CliCommand<GlobalFlagsT, GlobalFlagsT>) cmd; cliCmd.setParent(path); } } return newSpec; }
From source file:org.apache.isis.schema.utils.jaxbadapters.JodaLocalDateTimeStringAdapter.java
public static LocalDateTime parse(final String date) { if (Strings.isNullOrEmpty(date)) { return null; }//w w w.j a v a 2s. c o m return formatter.parseLocalDateTime(date); }
From source file:com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategyFactory.java
/** * ? ./*from ww w . jav a 2s . com*/ * * @param jobShardingStrategyClassName ?? * @return */ public static JobShardingStrategy getStrategy(final String jobShardingStrategyClassName) { if (Strings.isNullOrEmpty(jobShardingStrategyClassName)) { return new AverageAllocationJobShardingStrategy(); } try { Class<?> jobShardingStrategyClass = Class.forName(jobShardingStrategyClassName); if (!JobShardingStrategy.class.isAssignableFrom(jobShardingStrategyClass)) { throw new JobConfigurationException("Class '%s' is not job strategy class", jobShardingStrategyClassName); } return (JobShardingStrategy) jobShardingStrategyClass.newInstance(); } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException ex) { throw new JobConfigurationException( "Sharding strategy class '%s' config error, message details are '%s'", jobShardingStrategyClassName, ex.getMessage()); } }
From source file:org.artifactory.descriptor.repo.vcs.VcsUrlBuilder.java
/** * Formats single resource download URL based on * VcsGitProvider url definition// w w w. j a v a 2 s. c o m * * @param provider * @param user * @param repository * @param file * @param branch * * @return formatted url */ public static String resourceDownloadUrl(VcsGitProvider provider, String user, String repository, String file, String branch) { if (!Strings.isNullOrEmpty(provider.getResourceDownloadUrl())) { String[] values = new String[] { user, repository, file, branch }; return MessageFormat.format(provider.getResourceDownloadUrl(), values); } return null; }
From source file:io.appform.nautilus.funnel.utils.PathUtils.java
public static List<String> normalise(final List<String> inputPath) { List<String> path = new ArrayList<>(inputPath); //Remove self loops for (int i = 1; i < path.size(); i++) { if (Objects.equals(path.get(i), path.get(i - 1))) { path.set(i, null);//from w ww. j av a 2 s . c om } } List<String> dedupList = path.parallelStream().filter(listItem -> !Strings.isNullOrEmpty(listItem)) .collect(Collectors.toCollection(ArrayList::new)); //Sequence can't be greater than half of the path int seqSize = dedupList.size() / 2; while (seqSize >= 2) { //Can't have smaller repetitions //The algo marks the duplicate bits as true BitSet bitSet = new BitSet(dedupList.size()); //System.out.println("SEQ SIZE: " + seqSize); for (int i = 0; i < dedupList.size() - seqSize; i++) { //Create the sequence to search for final List<String> subList = dedupList.subList(i, i + seqSize); boolean duplicateSeqFound = true; //System.out.println("CHECKING: " + Joiner.on("->").join(subList)); if (dedupList.size() < i + 2 * seqSize) { //System.out.println("SKIPPING"); continue; } for (int j = i + seqSize, k = 0; k < subList.size(); j++, k++) { if (!subList.get(k).equals(dedupList.get(j))) { //There is a non-duplicate bit //Useless to go further with this sequence duplicateSeqFound = false; break; } } if (duplicateSeqFound) { //Set the bits bitSet.set(i, i + seqSize); List<String> tmpList = Lists.newArrayListWithCapacity(dedupList.size() - seqSize); for (int ii = 0; ii < dedupList.size(); ii++) { if (!bitSet.get(ii)) { //Add not new path only if bit is not set tmpList.add(dedupList.get(ii)); } } //Next loop will use the compressed path dedupList = tmpList; //System.out.println("DUPL: " + Joiner.on("->").join(subList)); //System.out.println("NORM PATH: " + Joiner.on("->").join(dedupList)); break; } } seqSize = (bitSet.isEmpty()) //If no duplicate was found in this iteration ? seqSize - 1 //Try with a smaller sequence : dedupList.size() / 2; //Deduplicate the modified path } return dedupList; }