public static List<Integer> primeFactors(int number) { List<Integer> fs = new ArrayList<>(); IntStream.rangeClosed(2, number / 2).filter(P31::isPrime).forEach(f -> { int n = number; while (n % f == 0) { n = n / f; fs.add(f); } }); return fs; } }
Set<Integer> chars = new HashSet<>(); String s = /* Your lowercase string */; s.length > 25 && s.chars() .filter(i -> i >= 'a' && i <= 'z') //only alphabet .filter(chars::add) //add to our tracking set if we reach this point .filter(i -> chars.size() == 26) //filter the 26th letter found .findAny().isPresent(); //if the 26th is found, return
@CheckForNull private static String removeCharZeros(@Nullable String str) { if (str == null || str.isEmpty()) { return str; } return str.codePoints() .filter(c -> c != "\u0000".codePointAt(0)) .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) .toString(); } }
void addBlock(TextBlock textBlock) { Boolean[] newBlock = new Boolean[] {false}; IntStream.rangeClosed(textBlock.getStart(), textBlock.getEnd()) .filter(changedLines::contains) .forEach(line -> { lineCounts.add(line); newBlock[0] = true; }); if (newBlock[0]) { blockCounts++; } }
@VisibleForTesting List<Page> getBufferedPages() { return IntStream.range(0, currentPageCount) .filter(i -> pageReferences.get(i) != null) .mapToObj(i -> pageReferences.get(i).getPage()) .collect(toImmutableList()); }
@Override public long estimateEncodedKeyComponentSize(int[] key) { // string length is being accounted for each time they are referenced, based on dimension handler interface, // even though they are stored just once. It may overestimate the size by a bit, but we wanted to leave // more buffer to be safe long estimatedSize = key.length * Integer.BYTES; estimatedSize += Arrays.stream(key) .filter(element -> dimLookup.getValue(element) != null) .mapToLong(element -> dimLookup.getValue(element).length() * Character.BYTES) .sum(); return estimatedSize; }
private static Optional<Changeset> getLatestChangeset(Component component, ScmInfo scmInfo, DefaultIssue issue) { Optional<Changeset> mostRecentChangeset = IssueLocations.allLinesFor(issue, component.getUuid()) .filter(scmInfo::hasChangesetForLine) .mapToObj(scmInfo::getChangesetForLine) .max(Comparator.comparingLong(Changeset::getDate)); if (mostRecentChangeset.isPresent()) { return mostRecentChangeset; } return Optional.of(scmInfo.getLatestChangeset()); }
public static long phi(int m) { return IntStream.rangeClosed(1, m).filter(r -> P38.coprime(r, m)).count(); } }
MergingRowIterator(List<TransformableRowIterator> iterators) { iterators.forEach(closer::register); originalIterators = new TransformableRowIterator[iterators.size()]; pQueue = IntStream .range(0, iterators.size()) .filter(indexNum -> iterators.get(indexNum).moveToNext()) .mapToObj(indexNum -> { TransformableRowIterator rowIterator = iterators.get(indexNum); // Can call rowIterator.getPointer() only here, after moveToNext() returned true on the filter() step rowIterator.getPointer().setIndexNum(indexNum); originalIterators[indexNum] = rowIterator; return rowIterator; }) .toArray(RowIterator[]::new); equalToChild = new boolean[pQueue.length]; heapify(); initEqualToChildStates(); }
private boolean isProbablyType(String name) { Symbol typeSymbol = FindIdentifiers.findIdent(name, state, KindSelector.TYP); return typeSymbol instanceof TypeSymbol || name.chars().filter(c -> c == '.').count() >= 3 || name.contains("#"); }
@DataProvider public static Object[][] illegalDatasetIdLengths() { return IntStream.range(1, UUID_DATASET_ID_LENGTH + new Random().nextInt(5)) .filter(i -> i != UUID_DATASET_ID_LENGTH) .filter(i -> i != NOT_UUID_DATASET_ID_LENGTH) .filter(i -> i != DEPRECATED_SERVER_ID_LENGTH) .mapToObj(i -> new Object[] {i}) .toArray(Object[][]::new); }
static <T> List<T> without(List<T> list, Collection<Integer> indexes) { Set<Integer> indexesSet = ImmutableSet.copyOf(indexes); return IntStream.range(0, list.size()) .filter(index -> !indexesSet.contains(index)) .mapToObj(list::get) .collect(toImmutableList()); }
@Benchmark public long java8_1() { // Using Java8 (case 2) return testString.codePoints().filter(ch -> ch == '.').count(); }
@Benchmark public long java8() { // Using Java8 return testString.chars().filter(ch -> ch =='.').count(); }
@Benchmark public long java8_1() { // Using Java8 (case 2) return testString.codePoints().filter(ch -> ch == '.').count(); }
@Benchmark public long java8() { // Using Java8 return testString.chars().filter(ch -> ch =='.').count(); }
@DataProvider public static Object[][] illegalDatabaseIdLengths() { return IntStream.range(1, 8 + new Random().nextInt(5)) .filter(i -> i != DATABASE_ID_LENGTH) .mapToObj(i -> new Object[] {i}) .toArray(Object[][]::new); }
/** * Find the index of valueIndices which is {@link IndexedInts} returned from {@link #getValueSelector()#getRow()} * corresponding to the {@link #subColumnName}. * * @return index for valueIndices if found. -1 otherwise. */ private int findValueIndicesIndexForSubColumn() { final DimensionSelector keySelector = getKeySelector(); final DimensionSelector valueSelector = getValueSelector(); final IndexedInts keyIndices = keySelector.getRow(); final IndexedInts valueIndices = valueSelector.getRow(); final int limit = Math.min(keyIndices.size(), valueIndices.size()); return IntStream .range(0, limit) .filter(i -> subColumnName.equals(keySelector.lookupName(keyIndices.get(i)))) // subColumnName is never null .findAny() .orElse(-1); }
/** */ private static int keyInDifferentPartition(Ignite ignite, String cacheName, int key) { Affinity<Object> affinity = ignite.affinity(cacheName); return IntStream.iterate(key + 1, i -> i + 1) .filter(i -> affinity.partition(i) != affinity.partition(key)) .findFirst().getAsInt(); } }