List of usage examples for com.google.common.base Splitter onPattern
@CheckReturnValue @GwtIncompatible("java.util.regex") public static Splitter onPattern(String separatorPattern)
From source file:org.hashes.collision.AbstractCollisionGenerator.java
/** * Generates a {@link List} of distinct keys with the same hash code. * <p>/*w ww . jav a 2 s . co m*/ * If <code>forceNew</code> is true, a new {@link List} of collisions is generated, otherwise the prebuilt * collisions are loaded if available * * @param numberOfKeys number of keys to generate * @param forceNew forces the generation of new keys instead of using pre-built * @param monitorFactory progress monitor factory * @return a list of distinct keys with the same hash code */ public List<String> generateCollisions(final int numberOfKeys, final ProgressMonitorFactory monitorFactory, final boolean forceNew) { Preconditions.checkArgument(numberOfKeys > 0, "numberOfKeys"); Preconditions.checkNotNull(monitorFactory, "monitor"); List<String> collisions; if (forceNew) { if (LOG.isInfoEnabled()) { LOG.info("Generating " + numberOfKeys + " keys"); } collisions = this.generateNewCollisions(numberOfKeys, monitorFactory); } else { if (LOG.isInfoEnabled()) { LOG.info("Loading " + numberOfKeys + " keys"); } final Iterator<String> tokens = Splitter.onPattern(PRE_BUILT_REGEX) .split(this.getClass().getSimpleName()).iterator(); if (tokens.hasNext()) { try { final ProgressMonitor monitor = monitorFactory.createProgressMonitor("Loading", null); try { // all files with prebuilt collisions should use UTF-8 encoding. collisions = FileUtils.readLines(tokens.next() + PRE_BUILT_SUFIX, numberOfKeys, Charsets.UTF_8); } finally { monitor.done(); } } catch (final Exception e) { if (LOG.isWarnEnabled()) { LOG.warn("Could not load pre-built keys, generating new keys", e); } collisions = this.generateNewCollisions(numberOfKeys, monitorFactory); } } else { if (LOG.isWarnEnabled()) { LOG.warn("Could not resolve pre-built keys file name, generating new keys"); } collisions = this.generateNewCollisions(numberOfKeys, monitorFactory); } } return collisions; }
From source file:de.bund.bfr.knime.openkrise.common.StationDialog.java
private static List<String> split(String searchString) { List<String> list = new ArrayList<>(); List<String> current = null; for (String s : Splitter.onPattern("\\s").trimResults().omitEmptyStrings() .split(searchString.replace("\"", " \" "))) { if (s.equals("\"")) { if (current != null) { list.add(Joiner.on(" ").join(current)); current = null;// ww w . java 2 s. com } else { current = new ArrayList<>(); } } else { if (current != null) { current.add(s); } else { list.add(s); } } } if (current != null) { list.add(Joiner.on(" ").join(current)); } return list; }
From source file:org.thingsboard.server.msa.DockerComposeExecutor.java
public void invokeDocker() { // bail out early if (!CommandLine.executableExists(DOCKER_EXECUTABLE)) { throw new ContainerLaunchException("Local Docker not found. Is " + DOCKER_EXECUTABLE + " on the PATH?"); }/* ww w . j av a 2 s.c o m*/ final File pwd = composeFiles.get(0).getAbsoluteFile().getParentFile().getAbsoluteFile(); log.info("Local Docker is running command: {}", cmd); final List<String> command = Splitter.onPattern(" ").omitEmptyStrings() .splitToList(DOCKER_EXECUTABLE + " " + cmd); try { new ProcessExecutor().command(command).redirectOutput(Slf4jStream.of(log).asInfo()) .redirectError(Slf4jStream.of(log).asError()).directory(pwd).exitValueNormal() .executeNoTimeout(); log.info("Docker has finished running"); } catch (InvalidExitValueException e) { throw new ContainerLaunchException("Local Docker exited abnormally with code " + e.getExitValue() + " whilst running command: " + cmd); } catch (Exception e) { throw new ContainerLaunchException("Error running local Docker command: " + cmd, e); } }
From source file:org.apache.flex.compiler.internal.definitions.StyleDefinition.java
/** * Sets a list of theme names separated by comma or spaces. * /*from w w w. j a va 2 s .c o m*/ * @param themes Comma-separated or space-separated theme names. */ // TODO Should this do string-splitting? setEnumeration() and setStates() don't. public void setThemes(final String themes) { if (themes == null) { this.themes = new String[0]; } else { final Iterable<String> split = Splitter.onPattern("[,\\s]") // comma or space .trimResults().omitEmptyStrings().split(themes); this.themes = Iterables.toArray(split, String.class); } }
From source file:org.gradle.launcher.daemon.server.DaemonParameters.java
private void configureFrom(Map<?, ?> properties) { Object propertyValue = properties.get(IDLE_TIMEOUT_SYS_PROPERTY); if (propertyValue != null) { try {// w w w .j av a 2 s .c om idleTimeout = Integer.parseInt(propertyValue.toString()); } catch (NumberFormatException e) { throw new GradleException( String.format("Unable to parse %s sys property. The value should be an int but is: %s", IDLE_TIMEOUT_SYS_PROPERTY, propertyValue)); } } propertyValue = properties.get(JVM_ARGS_SYS_PROPERTY); if (propertyValue != null) { setJvmArgs(Lists .newArrayList(Splitter.onPattern("\\s").omitEmptyStrings().split(propertyValue.toString()))); } propertyValue = properties.get(DAEMON_SYS_PROPERTY); if (propertyValue != null) { enabled = propertyValue.toString().equalsIgnoreCase("true"); } }
From source file:org.apache.beam.runners.spark.io.SparkUnboundedSource.java
private static <T> String getSourceName(Source<T> source, int id) { StringBuilder sb = new StringBuilder(); for (String s : Splitter.onPattern("(?=[A-Z])").split(source.getClass().getSimpleName().replace("$", ""))) { String trimmed = s.trim(); if (!trimmed.isEmpty()) { sb.append(trimmed).append(" "); }// w w w .ja v a 2s .c o m } return sb.append("[").append(id).append("]").toString(); }
From source file:fr.obeo.intent.specification.parser.SpecificationParser.java
@Override public void parse(IntentSection intentSection, String descriptionUnitToParse) { // Only parse sections with a title if (intentSection.getTitle() != null) { // Get valid elements StringBuffer validElements = new StringBuffer(); for (String element : Splitter.onPattern("\r?\n").trimResults().omitEmptyStrings() .split(descriptionUnitToParse)) { if (isValidElement(element)) { validElements.append(element + "\n"); }//from w w w. ja va 2 s . c o m } // Parse features parseFeatures(intentSection, validElements); // Parse stories parseStories(intentSection, validElements); // Parse scenarios parseScenarios(intentSection, validElements); } }
From source file:google.registry.tools.CreateLrpTokensCommand.java
@Override public void run() throws Exception { checkArgument((assignee == null) == (assigneesFile != null), "Exactly one of either assignee or filename must be specified."); checkArgument((assigneesFile == null) || (metadata == null), "Metadata cannot be specified along with a filename."); checkArgument((assignee == null) || (metadataColumns == null), "Metadata columns cannot be specified along with an assignee."); final Set<String> validTlds = ImmutableSet.copyOf(Splitter.on(',').split(tlds)); for (String tld : validTlds) { assertTldExists(tld);// ww w.j a va 2 s .c om } LineReader reader = new LineReader((assigneesFile != null) ? Files.newReader(assigneesFile.toFile(), UTF_8) : new StringReader(assignee)); String line = null; do { ImmutableSet.Builder<LrpTokenEntity> tokensToSaveBuilder = new ImmutableSet.Builder<>(); for (String token : generateTokens(BATCH_SIZE)) { line = reader.readLine(); if (!isNullOrEmpty(line)) { ImmutableList<String> values = ImmutableList .copyOf(Splitter.onPattern(COMMA_EXCEPT_WHEN_QUOTED_REGEX) // Results should not be surrounded in double quotes. .trimResults(CharMatcher.is('\"')).split(line)); LrpTokenEntity.Builder tokenBuilder = new LrpTokenEntity.Builder().setAssignee(values.get(0)) .setToken(token).setValidTlds(validTlds); if (metadata != null) { tokenBuilder.setMetadata(metadata); } else if (metadataColumns != null) { ImmutableMap.Builder<String, String> metadataBuilder = ImmutableMap.builder(); for (ImmutableMap.Entry<String, Integer> entry : metadataColumns.entrySet()) { checkArgument(values.size() > entry.getValue(), "Entry for %s does not have a value for %s (index %s)", values.get(0), entry.getKey(), entry.getValue()); metadataBuilder.put(entry.getKey(), values.get(entry.getValue())); } tokenBuilder.setMetadata(metadataBuilder.build()); } tokensToSaveBuilder.add(tokenBuilder.build()); } } final ImmutableSet<LrpTokenEntity> tokensToSave = tokensToSaveBuilder.build(); // Wrap in a retrier to deal with transient 404 errors (thrown as RemoteApiExceptions). retrier.callWithRetry(new Callable<Void>() { @Override public Void call() throws Exception { saveTokens(tokensToSave); return null; } }, RemoteApiException.class); } while (line != null); }
From source file:org.apache.sentry.api.generic.thrift.SentryGenericPolicyProcessor.java
static List<NotificationHandler> createHandlers(Configuration conf) throws SentrySiteConfigurationException { List<NotificationHandler> handlers = Lists.newArrayList(); Iterable<String> notificationHandlers = Splitter.onPattern("[\\s,]").trimResults().omitEmptyStrings() .split(conf.get(PolicyStoreConstants.SENTRY_GENERIC_POLICY_NOTIFICATION, "")); try {//from w w w.ja va 2 s. c o m for (String notificationHandler : notificationHandlers) { handlers.add(createInstance(notificationHandler, conf, NotificationHandler.class)); } } catch (Exception e) { throw new SentrySiteConfigurationException("Create notificationHandlers error: " + e.getMessage(), e); } return handlers; }
From source file:us.eharning.atomun.mnemonic.spi.bip0039.BIP0039MnemonicUtility.java
/** * Get normalized list of split words.// w w w .j a v a 2 s . c o m * * @param mnemonicSequence space-separated list of words to split/normalize. * * @return list of noralized words. */ @Nonnull public static List<String> getNormalizedWordList(@Nonnull CharSequence mnemonicSequence) { /* Normalize after splitting due to wide spaces getting normalized into space+widener */ List<String> mnemonicWordList = Splitter.onPattern(" |\u3000").splitToList(mnemonicSequence); return Lists.transform(mnemonicWordList, new Function<String, String>() { @Nullable @Override public String apply(@Nullable String input) { if (null == input) { return null; } return Normalizer.normalize(input, Normalizer.Form.NFKD); } }); }