use of java.util.function.BiPredicate in project jabref by JabRef.
the class CiteKeyBasedFileFinder method findFilesByExtension.
/**
* Returns a list of all files in the given directories which have one of the given extension.
*/
public Set<Path> findFilesByExtension(List<Path> directories, List<String> extensions) {
Objects.requireNonNull(extensions, "Extensions must not be null!");
BiPredicate<Path, BasicFileAttributes> isFileWithCorrectExtension = (path, attributes) -> !Files.isDirectory(path) && extensions.contains(FileHelper.getFileExtension(path).orElse(""));
Set<Path> result = new HashSet<>();
for (Path directory : directories) {
try (Stream<Path> files = Files.find(directory, Integer.MAX_VALUE, isFileWithCorrectExtension)) {
result.addAll(files.collect(Collectors.toSet()));
} catch (IOException e) {
LOGGER.error("Problem in finding files", e);
}
}
return result;
}
use of java.util.function.BiPredicate in project unipop by unipop-graph.
the class JdbcPredicatesTranslator method handleConnectiveP.
private Condition handleConnectiveP(String key, ConnectiveP predicate) {
List<P> predicates = predicate.getPredicates();
List<Condition> queries = predicates.stream().map(p -> {
if (p instanceof ConnectiveP)
return handleConnectiveP(key, (ConnectiveP) p);
Object pValue = p.getValue();
BiPredicate pBiPredicate = p.getBiPredicate();
return predicateToQuery(key, pValue, pBiPredicate);
}).collect(Collectors.toList());
Condition condition = queries.get(0);
if (predicate instanceof AndP) {
for (int i = 1; i < queries.size(); i++) {
condition = condition.and(queries.get(i));
}
} else if (predicate instanceof OrP) {
for (int i = 1; i < queries.size(); i++) {
condition = condition.or(queries.get(i));
}
} else
throw new IllegalArgumentException("Connective predicate not supported by unipop");
return condition;
}
use of java.util.function.BiPredicate in project sqlg by pietermartin.
the class ReplacedStep method addIdHasContainers.
private void addIdHasContainers(SchemaTableTree schemaTableTree1, List<Multimap<BiPredicate, RecordId>> biPredicateRecordIds) {
if (biPredicateRecordIds != null) {
for (Multimap<BiPredicate, RecordId> biPredicateRecordId : biPredicateRecordIds) {
for (BiPredicate biPredicate : biPredicateRecordId.keySet()) {
Collection<RecordId> recordIds = biPredicateRecordId.get(biPredicate);
HasContainer idHasContainer;
// id hasContainers are only optimized for BaseStrategy.SUPPORTED_ID_BI_PREDICATE within, without, eq, neq
if (biPredicate == Contains.without || biPredicate == Contains.within) {
idHasContainer = new HasContainer(T.id.getAccessor(), P.test(biPredicate, recordIds));
schemaTableTree1.getHasContainers().add(idHasContainer);
} else {
Preconditions.checkState(biPredicate == Compare.eq || biPredicate == Compare.neq);
for (RecordId recordId : recordIds) {
idHasContainer = new HasContainer(T.id.getAccessor(), P.test(biPredicate, recordId));
schemaTableTree1.getHasContainers().add(idHasContainer);
}
}
}
}
}
}
use of java.util.function.BiPredicate in project sqlg by pietermartin.
the class ReplacedStep method collectSchemaTableTrees.
private void collectSchemaTableTrees(SqlgGraph sqlgGraph, int replacedStepDepth, Set<SchemaTableTree> result, Map<SchemaTable, List<Multimap<BiPredicate, RecordId>>> groupedIds, String table) {
SchemaTable schemaTable = SchemaTable.from(sqlgGraph, table);
List<HasContainer> schemaTableTreeHasContainers = new ArrayList<>(this.hasContainers);
if (groupedIds != null) {
List<Multimap<BiPredicate, RecordId>> biPredicateRecordIds = groupedIds.get(schemaTable.withOutPrefix());
if (biPredicateRecordIds != null) {
for (Multimap<BiPredicate, RecordId> biPredicateRecordId : biPredicateRecordIds) {
for (BiPredicate biPredicate : biPredicateRecordId.keySet()) {
Collection<RecordId> recordIds = biPredicateRecordId.get(biPredicate);
HasContainer idHasContainer;
// id hasContainers are only optimized for BaseStrategy.SUPPORTED_ID_BI_PREDICATE within, without, eq, neq
if (biPredicate == Contains.without || biPredicate == Contains.within) {
idHasContainer = new HasContainer(T.id.getAccessor(), P.test(biPredicate, recordIds));
schemaTableTreeHasContainers.add(idHasContainer);
} else {
Preconditions.checkState(biPredicate == Compare.eq || biPredicate == Compare.neq);
for (RecordId recordId : recordIds) {
idHasContainer = new HasContainer(T.id.getAccessor(), P.test(biPredicate, recordId));
schemaTableTreeHasContainers.add(idHasContainer);
}
}
}
}
}
}
SchemaTableTree schemaTableTree = new SchemaTableTree(sqlgGraph, schemaTable, 0, schemaTableTreeHasContainers, this.andOrHasContainers, this.sqlgComparatorHolder, this.sqlgComparatorHolder.getComparators(), this.sqlgRangeHolder, SchemaTableTree.STEP_TYPE.GRAPH_STEP, ReplacedStep.this.emit, ReplacedStep.this.untilFirst, ReplacedStep.this.leftJoin, ReplacedStep.this.drop, replacedStepDepth, ReplacedStep.this.labels);
result.add(schemaTableTree);
}
use of java.util.function.BiPredicate in project cassandra by apache.
the class CommitLog method recoverSegmentsOnDisk.
/**
* Perform recovery on commit logs located in the directory specified by the config file.
*
* @return the number of mutations replayed
* @throws IOException
*/
public int recoverSegmentsOnDisk() throws IOException {
BiPredicate<File, String> unmanagedFilesFilter = (dir, name) -> CommitLogDescriptor.isValid(name) && CommitLogSegment.shouldReplay(name);
// archiving pass, which we should not treat as serious.
for (File file : new File(segmentManager.storageDirectory).tryList(unmanagedFilesFilter)) {
archiver.maybeArchive(file.path(), file.name());
archiver.maybeWaitForArchiving(file.name());
}
assert archiver.archivePending.isEmpty() : "Not all commit log archive tasks were completed before restore";
archiver.maybeRestoreArchive();
// List the files again as archiver may have added segments.
File[] files = new File(segmentManager.storageDirectory).tryList(unmanagedFilesFilter);
int replayed = 0;
if (files.length == 0) {
logger.info("No commitlog files found; skipping replay");
} else {
Arrays.sort(files, new CommitLogSegmentFileComparator());
logger.info("Replaying {}", StringUtils.join(files, ", "));
replayed = recoverFiles(files);
logger.info("Log replay complete, {} replayed mutations", replayed);
for (File f : files) segmentManager.handleReplayedSegment(f);
}
return replayed;
}
Aggregations