/** * Creates and returns a Stream of the words in the given text. Words are a * group of characters separated by one or more white spaces. * * @param text containing zero or more words * @return a Stream of the words in the given text */ public static Stream<String> wordsOf(String text) { requireNonNull(text); return WORDS.splitAsStream(text); }
/** * Creates and returns a Stream of the words in the given text. Words are a * group of characters separated by one or more white spaces. * * @param text containing zero or more words * @return a Stream of the words in the given text */ public static Stream<String> wordsOf(String text) { requireNonNull(text); return WORDS.splitAsStream(text); }
public static String capitalizeEveryWord(final String input) { return Pattern.compile("\\b(?=\\w)").splitAsStream(input) .map(w -> capitalize(w, false)) .collect(Collectors.joining()); }
public static Map<String, Long> countWordsIn(Path path) throws IOException { Stream<String> words = Files.readAllLines(path, defaultCharset()) .stream() .flatMap(line -> SPACES.splitAsStream(line)); return countWords(words); }
private static List<Integer> readSlots(List<String> slotStrings) { List<Integer> slots = new ArrayList<>(); for (String slotString : slotStrings) { if (slotString.startsWith(TOKEN_SLOT_IN_TRANSITION)) { // not interesting continue; } if (slotString.contains("-")) { // slot range Iterator<String> it = DASH_PATTERN.splitAsStream(slotString).iterator(); int from = Integer.parseInt(it.next()); int to = Integer.parseInt(it.next()); for (int slot = from; slot <= to; slot++) { slots.add(slot); } continue; } slots.add(Integer.parseInt(slotString)); } return Collections.unmodifiableList(slots); }
/** * Parse partition lines into Partitions object. * * @param nodes output of CLUSTER NODES * @return the partitions object. */ public static Partitions parse(String nodes) { Partitions result = new Partitions(); try { List<RedisClusterNode> mappedNodes = TOKEN_PATTERN.splitAsStream(nodes).filter(s -> !s.isEmpty()) .map(ClusterPartitionParser::parseNode) .collect(Collectors.toList()); result.addAll(mappedNodes); } catch (Exception e) { throw new RedisException("Cannot parse " + nodes, e); } return result; }
final AtomicInteger col = new AtomicInteger(); final List<String> words = splitter.splitAsStream(text).collect(toList()); for (final String w : words) { final int wordLen = w.length();
final AtomicInteger col = new AtomicInteger(); splitter.splitAsStream(text) .map(w -> w.replace("\t", Formatting.tab())) .forEachOrdered(w -> {
.splitAsStream("a1:a2:a3"); System.out.println("streamFromPattern = " + streamFromPattern.collect(Collectors.joining(","))); // print a1,a2,a3
SPACE.splitAsStream(joined).forEach(word -> {
private static RedisClusterNode parseNode(String nodeInformation) { Iterator<String> iterator = SPACE_PATTERN.splitAsStream(nodeInformation).iterator();
Pattern pattern = Pattern.compile(", "); List<Integer> list = pattern.splitAsStream(ints) .map(Integer::valueOf) .collect(Collectors.toList());
story = Pattern .compile(String.format("(?<=%1$s)|(?=%1$s)", "foo|bar")) .splitAsStream(story) .map(w -> ImmutableMap.of("bar", "foo", "foo", "bar").getOrDefault(w, w)) .collect(Collectors.joining());
public static void initRequest(String request) { ParameterUtil.requestAsText = request; ParameterUtil.request = Pattern .compile("&") .splitAsStream(request) .map(s -> Arrays.copyOf(s.split("="), 2)) .map(o -> new SimpleEntry<String, String>(o[0], o[1] == null ? "" : o[1])) .collect(Collectors.toList()) ; }
public static void initHeader(String header) { ParameterUtil.setHeader( Pattern .compile("\\\\r\\\\n") .splitAsStream(header) .map(s -> Arrays.copyOf(s.split(":"), 2)) .map(o -> new SimpleEntry<String, String>(o[0], o[1] == null ? "" : o[1])) .collect(Collectors.toList()) ); }
public static String capitalizeEveryWord(final String input) { return Pattern.compile("\\b(?=\\w)").splitAsStream(input) .map(w -> capitalize(w, false)) .collect(Collectors.joining()); }
/** * @param query * @return */ protected String toQueryParams(Object query) { if (query == null) return ""; if (query instanceof Map) { Map<String, Object> map = (Map<String, Object>) query; if (map.isEmpty()) return ""; return map.entrySet().stream().map(e -> e.getKey() + "=" + Util.encodeUrlComponent(e.getValue().toString())).collect(Collectors.joining("&")); } else { // We have to encode only the values not the keys return Pattern.compile("&").splitAsStream(query.toString()) .map(KEY_VALUE::matcher) .filter(Matcher::matches) .map(matcher -> matcher.group(1) + matcher.group(2) + Util.encodeUrlComponent(matcher.group(3))) .collect(Collectors.joining("&")); } }
public static void initQueryString(String urlQuery) throws MalformedURLException { URL url = new URL(urlQuery); if ("".equals(urlQuery) || "".equals(url.getHost())) { throw new MalformedURLException("empty URL"); } ConnectionUtil.setUrlByUser(urlQuery); // Parse url and GET query string ParameterUtil.setQueryString(new ArrayList<SimpleEntry<String, String>>()); Matcher regexSearch = Pattern.compile("(.*\\?)(.*)").matcher(urlQuery); if (regexSearch.find()) { ConnectionUtil.setUrlBase(regexSearch.group(1)); if (!"".equals(url.getQuery())) { ParameterUtil.setQueryString( Pattern.compile("&").splitAsStream(regexSearch.group(2)) .map(s -> Arrays.copyOf(s.split("="), 2)) .map(o -> new SimpleEntry<String, String>(o[0], o[1] == null ? "" : o[1])) .collect(Collectors.toList()) ); } } else { ConnectionUtil.setUrlBase(urlQuery); } }
.splitAsStream(tagBlock) .filter(x -> !x.isEmpty()) .map(s -> BLOCK_TAG_PREFIX + s)
public static Map<String, Integer> countJava8(String input) { return Pattern.compile("\\W+") .splitAsStream(input) .collect(Collectors.groupingBy(String::toLowerCase, Collectors.summingInt(s -> 1))); }