List of usage examples for com.google.common.base Splitter splitToList
@CheckReturnValue
@Beta
public List<String> splitToList(CharSequence sequence)
From source file:org.corpus_tools.graphannis.console.Console.java
public static void main(String[] args) { if (args.length < 1) { System.err.println("Must give the database directory as argument."); System.exit(-1);//from w ww . j av a 2s.c o m } Console c = new Console(args[0]); try { Splitter cmdArgSplitter = Splitter.on(" ").omitEmptyStrings().trimResults().limit(2); FileHistory history = new FileHistory(new File(".graphannis_history.txt")); ConsoleReader reader = new ConsoleReader(); reader.setHistory(history); reader.setHistoryEnabled(true); reader.setPrompt("graphannis> "); reader.addCompleter( new StringsCompleter("quit", "exit", "count", "find", "subgraph", "list", "relannis")); boolean exit = false; String line; while (!exit && (line = reader.readLine()) != null) { List<String> parsed = cmdArgSplitter.splitToList(line); String cmd = parsed.get(0); String arguments = ""; if (parsed.size() > 1) { arguments = parsed.get(1); } switch (cmd) { case "list": c.list(); break; case "count": c.count(arguments); break; case "find": c.find(arguments); break; case "subgraph": c.subgraph(arguments); break; case "relannis": c.relannis(arguments); break; case "exit": case "quit": System.out.println("Good bye!"); exit = true; break; } } } catch (IOException ex) { Logger.getLogger(Console.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.intel.podm.common.utils.StringRepresentation.java
public static List<String> toList(String stringToSplit, boolean trimResults) { Splitter splitter = Splitter.on(ELEMENT_SEPARATOR); if (trimResults) { splitter = splitter.trimResults(); }// w w w. ja va 2s . c o m return splitter.splitToList(stringToSplit); }
From source file:com.greensopinion.finance.services.transaction.EntityReferences.java
private static ListMultimap<String, String> readEntityReferences() { ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder(); try {// ww w . j a v a2 s . co m BufferedReader reader = new BufferedReader(new InputStreamReader( EntityReferences.class.getResourceAsStream("entity-references.txt"), Charsets.UTF_8)); //$NON-NLS-1$ try { Splitter splitter = Splitter.on(CharMatcher.WHITESPACE).trimResults().omitEmptyStrings(); String line; while ((line = reader.readLine()) != null) { List<String> lineItems = splitter.splitToList(line); checkState(lineItems.size() > 1); for (int x = 1; x < lineItems.size(); ++x) { builder.put(lineItems.get(0), lineItems.get(x)); } } } finally { reader.close(); } } catch (IOException e) { throw Throwables.propagate(e); } return builder.build(); }
From source file:com.b2international.index.compat.Highlighting.java
public static String[] getSuffixes(final String queryExpression, final String label) { final Splitter tokenSplitter = Splitter.on(TextConstants.WHITESPACE_OR_DELIMITER_MATCHER) .omitEmptyStrings();/* w w w . ja v a2 s.c o m*/ final List<String> filterTokens = tokenSplitter.splitToList(queryExpression.toLowerCase()); final boolean spaceAtTheEnd = !queryExpression.isEmpty() && Character.isWhitespace(queryExpression.charAt(queryExpression.length() - 1)); final String lowerCaseLabel = label.toLowerCase(); final Iterable<String> labelTokens = tokenSplitter.split(lowerCaseLabel); final List<String> elementSuffixes = Lists.newArrayList(); for (final String labelToken : labelTokens) { final Iterator<String> itr = filterTokens.iterator(); while (itr.hasNext()) { final String filterToken = itr.next(); if (labelToken.startsWith(filterToken)) { // Last filter token? Also add suffix, unless it is already present in the filter and there's no whitespace at the end of it if (!itr.hasNext() && !filterTokens.contains(labelToken) && !spaceAtTheEnd) { elementSuffixes.add(labelToken.substring(filterToken.length())); } } } // If there's whitespace at the end, add complete word suggestions as well if (shouldSuggest(filterTokens, labelToken) && spaceAtTheEnd) { elementSuffixes.add(labelToken); } } return Iterables.toArray(elementSuffixes, String.class); }
From source file:com.google.devtools.build.lib.analysis.WorkspaceStatusAction.java
/** * Parses the output of the workspace status action. * * <p>The output is a text file with each line representing a workspace status info key. * The key is the part of the line before the first space and should consist of the characters * [A-Z_] (although this is not checked). Everything after the first space is the value. *//* w w w. j ava 2 s. co m*/ public static Map<String, String> parseValues(Path file) throws IOException { HashMap<String, String> result = new HashMap<>(); Splitter lineSplitter = Splitter.on(' ').limit(2); for (String line : Splitter.on('\n').split(new String(FileSystemUtils.readContentAsLatin1(file)))) { List<String> items = lineSplitter.splitToList(line); if (items.size() != 2) { continue; } result.put(items.get(0), items.get(1)); } return ImmutableMap.copyOf(result); }
From source file:org.onos.yangtools.yang.parser.stmt.rfc6020.Utils.java
public static List<String> splitPathToNodeNames(String path) { Splitter keySplitter = Splitter.on(SEPARATOR_NODENAME).omitEmptyStrings().trimResults(); return keySplitter.splitToList(path); }
From source file:org.apache.pulsar.common.net.ServiceURI.java
/** * Create a service uri instance from a {@link URI} instance. * * @param uri {@link URI} instance/* w w w . j a v a2s . co m*/ * @return a service uri instance * @throws NullPointerException if {@code uriStr} is null * @throws IllegalArgumentException if the given string violates RFC 2396 */ public static ServiceURI create(URI uri) { checkNotNull(uri, "service uri instance is null"); String serviceName; final String[] serviceInfos; String scheme = uri.getScheme(); if (null != scheme) { scheme = scheme.toLowerCase(); final String serviceSep = "+"; String[] schemeParts = StringUtils.split(scheme, serviceSep); serviceName = schemeParts[0]; serviceInfos = new String[schemeParts.length - 1]; System.arraycopy(schemeParts, 1, serviceInfos, 0, serviceInfos.length); } else { serviceName = null; serviceInfos = new String[0]; } String userAndHostInformation = uri.getAuthority(); checkArgument(!Strings.isNullOrEmpty(userAndHostInformation), "authority component is missing in service uri : " + uri); String serviceUser; List<String> serviceHosts; int atIndex = userAndHostInformation.indexOf('@'); Splitter splitter = Splitter.on(CharMatcher.anyOf(",;")); if (atIndex > 0) { serviceUser = userAndHostInformation.substring(0, atIndex); serviceHosts = splitter.splitToList(userAndHostInformation.substring(atIndex + 1)); } else { serviceUser = null; serviceHosts = splitter.splitToList(userAndHostInformation); } serviceHosts = serviceHosts.stream().map(host -> validateHostName(serviceName, serviceInfos, host)) .collect(Collectors.toList()); String servicePath = uri.getPath(); checkArgument(null != servicePath, "service path component is missing in service uri : " + uri); return new ServiceURI(serviceName, serviceInfos, serviceUser, serviceHosts.toArray(new String[serviceHosts.size()]), servicePath, uri); }
From source file:org.apache.jackrabbit.oak.query.fulltext.SimpleExcerptProvider.java
public static PropertyValue getExcerpt(PropertyValue value) { Splitter listSplitter = Splitter.on(',').trimResults().omitEmptyStrings(); StringBuilder excerpt = new StringBuilder(EXCERPT_BEGIN); for (String v : listSplitter.splitToList(value.toString())) { excerpt.append(v);/*from w w w .jav a 2 s.c om*/ } excerpt.append(EXCERPT_END); return PropertyValues.newString(excerpt.toString()); }
From source file:org.apache.bookkeeper.common.net.ServiceURI.java
/** * Create a service uri instance from a {@link URI} instance. * * @param uri {@link URI} instance/* ww w.j a v a 2s . c o m*/ * @return a service uri instance * @throws NullPointerException if {@code uriStr} is null * @throws IllegalArgumentException if the given string violates RFC 2396 */ public static ServiceURI create(URI uri) { checkNotNull(uri, "service uri instance is null"); String serviceName; String[] serviceInfos = new String[0]; String scheme = uri.getScheme(); if (null != scheme) { scheme = scheme.toLowerCase(); final String serviceSep; if (scheme.startsWith(SERVICE_DLOG)) { serviceSep = SERVICE_DLOG_SEP; } else { serviceSep = SERVICE_SEP; } String[] schemeParts = StringUtils.split(scheme, serviceSep); serviceName = schemeParts[0]; serviceInfos = new String[schemeParts.length - 1]; System.arraycopy(schemeParts, 1, serviceInfos, 0, serviceInfos.length); } else { serviceName = null; } String userAndHostInformation = uri.getAuthority(); checkArgument(!Strings.isNullOrEmpty(userAndHostInformation), "authority component is missing in service uri : " + uri); String serviceUser; List<String> serviceHosts; int atIndex = userAndHostInformation.indexOf('@'); Splitter splitter = Splitter.on(CharMatcher.anyOf(",;")); if (atIndex > 0) { serviceUser = userAndHostInformation.substring(0, atIndex); serviceHosts = splitter.splitToList(userAndHostInformation.substring(atIndex + 1)); } else { serviceUser = null; serviceHosts = splitter.splitToList(userAndHostInformation); } serviceHosts = serviceHosts.stream().map(host -> validateHostName(serviceName, host)) .collect(Collectors.toList()); String servicePath = uri.getPath(); checkArgument(null != servicePath, "service path component is missing in service uri : " + uri); return new ServiceURI(serviceName, serviceInfos, serviceUser, serviceHosts.toArray(new String[serviceHosts.size()]), servicePath, uri); }
From source file:bear.session.Variables.java
public static DynamicVariable<List<String>> split(final DynamicVariable<? extends CharSequence> str, final Splitter splitter) { return dynamic(new Fun<AbstractContext, List<String>>() { public List<String> apply(AbstractContext $) { return splitter.splitToList($.var(str)); }/* w ww. j a v a 2 s . c o m*/ }).temp(); }