public Pattern(@NotNull java.util.regex.Pattern pattern) { this(pattern.asPredicate()); }
private static final Predicate<String> IS_NOT_SPACES_ONLY = Pattern.compile("^\\s*$").asPredicate().negate(); public static String implode(String delimiter, String... data) { return Arrays.stream(data) .filter(IS_NOT_SPACES_ONLY) .collect(Collectors.joining(delimiter)); }
/** * Compile a list of regex patterns and collect them as Predicates. * @param patterns List of regex patterns to be compiled * @return a List of Predicate created by compiling the regex patterns */ public static List<Predicate<String>> compilePatternsToPredicates(List<String> patterns) { return patterns.stream().map(pattern -> compile(pattern).asPredicate()).collect(Collectors.toList()); } }
private boolean checkIf(Document doc, String param, String value) { final Pattern pattern = Pattern.compile(value); return doc.get(param) .map(Object::toString) .filter(pattern.asPredicate()) .isPresent(); }
@Override public List<String> listHosts(final String namePatternFilter) { Preconditions.checkNotNull(namePatternFilter, "namePatternFilter"); final Predicate<String> matchesPattern = Pattern.compile(namePatternFilter).asPredicate(); return listHosts().stream() .filter(matchesPattern) .collect(Collectors.toList()); }
/** * Get the filtered, authorized, sorted log files for a port. */ @VisibleForTesting List<File> logsForPort(String user, File portDir) { try { List<File> workerLogs = directoryCleaner.getFilesForDir(portDir).stream() .filter(file -> WORKER_LOG_FILENAME_PATTERN.asPredicate().test(file.getName())) .collect(toList()); return workerLogs.stream() .filter(log -> resourceAuthorizer.isUserAllowedToAccessFile(user, WorkerLogs.getTopologyPortWorkerLog(log))) .sorted((f1, f2) -> (int) (f2.lastModified() - f1.lastModified())) .collect(toList()); } catch (IOException e) { throw new RuntimeException(e); } }
private void testMapFilter(Map<String, String> testMap, List<String> patterns) { List<Predicate<String>> paramsFilter = patterns.stream().map(pattern -> compile(pattern).asPredicate()).collect(Collectors.toList()); filterMapkeys(testMap, paramsFilter); }
/** * Asserts that a sequence of the message of the actual {@code Throwable} matches with the given regular expression (see {@link java.util.regex.Matcher#find()}). * The Pattern used under the hood enables the {@link Pattern#DOTALL} mode. * * @param info contains information about the assertion. * @param actual the given {@code Throwable}. * @param regex the regular expression expected to be found in the actual {@code Throwable}'s message. * @throws AssertionError if the actual {@code Throwable} is {@code null}. * @throws AssertionError if the message of the actual {@code Throwable} doesn't contain any sequence matching with the given regular expression * @throws NullPointerException if the regex is null */ public void assertHasMessageFindingMatch(AssertionInfo info, Throwable actual, String regex) { checkNotNull(regex, "regex must not be null"); assertNotNull(info, actual); Objects.instance().assertNotNull(info, actual.getMessage(), "exception message of actual"); if (Pattern.compile(regex, Pattern.DOTALL).asPredicate().test(actual.getMessage())) return; throw failures.failure(info, shouldHaveMessageFindingMatchRegex(actual, regex)); }
private static boolean isMatch(String regex, String field) { try { Pattern p = PatternCache.INSTANCE.getPattern(regex); if (p == null) { return false; } return p.asPredicate().test(field); } catch(PatternSyntaxException pse) { return false; } }
@ReadOperation public EnvironmentDescriptor environment(@Nullable String pattern) { if (StringUtils.hasText(pattern)) { return getEnvironmentDescriptor(Pattern.compile(pattern).asPredicate()); } return getEnvironmentDescriptor((name) -> true); }
public RegexMatchPredicate(TimeSeriesMetricExpression expr, String regex) { match_ = Pattern.compile(regex).asPredicate(); expr_ = expr; regex_ = regex; }
try(Stream<String> lines=Files.lines(pathToYourFile)) { ChunkSpliterator.toChunks( lines, Pattern.compile("^\\Q$$$$\\E$").asPredicate(), false) /* chain your stream operations, e.g. .forEach(s -> { s.forEach(System.out::print); System.out.println(); }) */; }
public RegexMatch(@NonNull String regex, @NonNull Optional<IdentifierMatch> successor) { this.regex = regex; this.match = Pattern.compile(regex).asPredicate(); this.successor = successor; }
private List<String> getFiles(File dir) { return Arrays.stream(dir.list()) .filter(filePattern.asPredicate()) .sorted(String::compareTo) .collect(Collectors.toList()); } private List<String> getFilesReversed(File dir) {
/** * */ protected void configureIsReconnectErrorCode() { String regex = StringUtils.trimToEmpty(getReconnectionErrorCodes()); if (regex.isEmpty()) { isReconnectErrorCode = e -> false; } else { isReconnectErrorCode = Pattern.compile(regex).asPredicate(); } } }
private boolean requiredAttributeFound(final String attributeName, final Map<String, Object> principalAttributes, final Map<String, Set<String>> requiredAttributes) { val values = requiredAttributes.get(attributeName); val availableValues = CollectionUtils.toCollection(principalAttributes.get(attributeName)); val pattern = RegexUtils.concatenate(values, this.caseInsensitive); LOGGER.debug("Checking [{}] against [{}] with pattern [{}] for attribute [{}]", values, availableValues, pattern, attributeName); if (pattern != RegexUtils.MATCH_NOTHING_PATTERN) { return availableValues.stream().map(Object::toString).anyMatch(pattern.asPredicate()); } return availableValues.stream().anyMatch(values::contains); } }
private Collection<Requirement> parseSingleFile(final ReqDeclTagConfig declTagConfig, final Path resourcePath) throws IOException { try (final Stream<String> lines = Files.lines(resourcePath, StandardCharsets.UTF_8)) { final Set<Requirement> declaredRequirements = new HashSet<>(); final Predicate<String> lineContainsRequirementPredicate = Pattern.compile(declTagConfig.getCompleteRegex()).asPredicate(); lines.parallel().filter(lineContainsRequirementPredicate).forEach(line -> declaredRequirements.addAll(getRequirementsFromString(declTagConfig, line))); return declaredRequirements; } }
public ItemGroup(String name, int uid, String regex, CommandSender author) { this.name = name; this.uid = uid; this.regex = regex; this.setAuthor(author instanceof Player ? ((Player) author).getUniqueId().toString() : plugin.cfg.defaultAuthor); if (!Strings.isNullOrEmpty(regex)) { Pattern p = Pattern.compile(regex); setItems(ItemManager.itemNames().stream().filter(p.asPredicate()).map(ItemManager::getItemByName).collect(Collectors.toSet())); setItemUids(items.stream().map(RPGItem::getUid).collect(Collectors.toSet())); } }
TextArea ta = new TextArea(); final Pattern binary = Pattern.compile("^[01]*$"); final Predicate<String> tester = binary.asPredicate(); ta.setTextFormatter(new TextFormatter<>(change -> { if (!tester.test(change.getControlNewText())) { return null; } return change; }));
@Override public boolean doTest(Mail mail) throws MessagingException, IOException { return Stream .concat(getMessageSubjects(mail), getMessageBodies(mail.getMessage())) .anyMatch(pattern.asPredicate()); }