private boolean isPrime(int number) { return IntStream.range(2, number) .allMatch(x -> (number % x) != 0); } // END parallel_functional
private boolean isPrime(int number) { return IntStream.range(2, number) .allMatch(x -> (number % x) != 0); } // END functional
public PageChannelSelector(int... channels) { checkArgument(IntStream.of(channels).allMatch(channel -> channel >= 0), "channels must be positive"); this.channels = requireNonNull(channels, "channels is null").clone(); }
public static boolean isNumeric(final String input) { if (input == null || input.isEmpty()) { return false; } return IntStream.range(0, input.length()) .allMatch(i -> Character.isDigit(input.charAt(i))); }
private boolean strictlyContainsWhitespaces(CharSequence actual) { return actual.chars().allMatch(Character::isWhitespace); }
@Override public Boolean execute() { try (final IntStream stream = buildPrevious()) { return stream.allMatch(predicate); } } }
public static boolean isNumeric(String dateTimeStr) { if (dateTimeStr != null) { return dateTimeStr.chars().allMatch(Character::isDigit); } return false; }
/** * Add a single object into the script context. * * @param key the name in the context this object is to stored under. * @param bean the object to be stored in the script context. */ public void addBean(String key, Object bean) { if (!key.isEmpty() && Character.isJavaIdentifierStart(key.charAt(0)) && key.chars().skip(1).allMatch(Character::isJavaIdentifierPart)) { beans.put(key, bean); } }
default boolean allMatch(IntPipeline pipeline, IntPredicate predicate) { requireNonNull(pipeline); requireNonNull(predicate); return optimize(pipeline).getAsIntStream().allMatch(predicate); }
@Override public boolean allMatch(IntPredicate predicate) { return finallyClose(() -> stream().allMatch(predicate)); }
private static boolean isErrorUriValid(String errorUri) { return errorUri == null || errorUri.chars().allMatch(c -> c == 0x21 || withinTheRangeOf(c, 0x23, 0x5B) || withinTheRangeOf(c, 0x5D, 0x7E)); }
private static boolean isDescriptionValid(String description) { return description == null || description.chars().allMatch(c -> withinTheRangeOf(c, 0x20, 0x21) || withinTheRangeOf(c, 0x23, 0x5B) || withinTheRangeOf(c, 0x5D, 0x7E)); }
private static boolean isErrorCodeValid(String errorCode) { return errorCode.chars().allMatch(c -> withinTheRangeOf(c, 0x20, 0x21) || withinTheRangeOf(c, 0x23, 0x5B) || withinTheRangeOf(c, 0x5D, 0x7E)); }
private static boolean validateScope(String scope) { return scope == null || scope.chars().allMatch(c -> withinTheRangeOf(c, 0x21, 0x21) || withinTheRangeOf(c, 0x23, 0x5B) || withinTheRangeOf(c, 0x5D, 0x7E)); }
private static boolean isScopeValid(String scope) { return scope == null || scope.chars().allMatch(c -> withinTheRangeOf(c, 0x20, 0x21) || withinTheRangeOf(c, 0x23, 0x5B) || withinTheRangeOf(c, 0x5D, 0x7E)); }
@Test public void shouldAddPatternToExcludeLinesWithWrongOrder() throws Exception { Path filePath = getResource("file-with-double-regexp-wrong-order.txt"); fileMetadata.readMetadata(Files.newInputStream(filePath), UTF_8, filePath.toString(), regexpScanner); assertThat(IntStream.rangeClosed(1, 24).noneMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(25, 35).allMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); }
@Test public void shouldAddPatternToExcludeSeveralLineRanges() throws Exception { Path filePath = getResource("file-with-double-regexp-twice.txt"); fileMetadata.readMetadata(Files.newInputStream(filePath), UTF_8, filePath.toString(), regexpScanner); assertThat(javaFile.isIgnoreAllIssues()).isFalse(); assertThat(IntStream.rangeClosed(1, 20).noneMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(21, 25).allMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(26, 28).noneMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(29, 33).allMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); }
@Test public void shouldAddPatternToExcludeLinesWithMess() throws Exception { Path filePath = getResource("file-with-double-regexp-mess.txt"); fileMetadata.readMetadata(Files.newInputStream(filePath), UTF_8, filePath.toString(), regexpScanner); assertThat(IntStream.rangeClosed(1, 20).noneMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(21, 29).allMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(30, 37).noneMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); }
@Test public void shouldAddPatternToExcludeLinesTillTheEnd() throws Exception { Path filePath = getResource("file-with-double-regexp-unfinished.txt"); fileMetadata.readMetadata(Files.newInputStream(filePath), UTF_8, filePath.toString(), regexpScanner); assertThat(javaFile.isIgnoreAllIssues()).isFalse(); assertThat(IntStream.rangeClosed(1, 20).noneMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(21, 34).allMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); }
@Test public void shouldExcludeLines() throws Exception { Path filePath = getResource("file-with-double-regexp.txt"); fileMetadata.readMetadata(Files.newInputStream(filePath), UTF_8, filePath.toString(), regexpScanner); assertThat(javaFile.isIgnoreAllIssues()).isFalse(); assertThat(IntStream.rangeClosed(1, 20).noneMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(21, 25).allMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(26, 34).noneMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); }