Search in sources :

Example 1 with BiPredicate

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;
}
Also used : Files(java.nio.file.Files) BibEntry(org.jabref.model.entry.BibEntry) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) FileHelper(org.jabref.model.util.FileHelper) HashSet(java.util.HashSet) Objects(java.util.Objects) BiPredicate(java.util.function.BiPredicate) List(java.util.List) Stream(java.util.stream.Stream) Map(java.util.Map) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Path(java.nio.file.Path) Path(java.nio.file.Path) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) HashSet(java.util.HashSet)

Example 2 with BiPredicate

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;
}
Also used : AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) ExistsP(org.unipop.process.predicate.ExistsP) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) P(org.apache.tinkerpop.gremlin.process.traversal.P) Condition(org.jooq.Condition) AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) MultiDateFormat(org.unipop.util.MultiDateFormat) java.util(java.util) DSL(org.jooq.impl.DSL) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) ExistsP(org.unipop.process.predicate.ExistsP) DSL.field(org.jooq.impl.DSL.field) Field(org.jooq.Field) Contains(org.apache.tinkerpop.gremlin.process.traversal.Contains) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) Compare(org.apache.tinkerpop.gremlin.process.traversal.Compare) BiPredicate(java.util.function.BiPredicate) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP) PredicatesTranslator(org.unipop.common.util.PredicatesTranslator) Date(org.unipop.process.predicate.Date) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) ParseException(java.text.ParseException) P(org.apache.tinkerpop.gremlin.process.traversal.P) Text(org.unipop.process.predicate.Text) AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP) BiPredicate(java.util.function.BiPredicate)

Example 3 with BiPredicate

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);
                    }
                }
            }
        }
    }
}
Also used : HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) BiPredicate(java.util.function.BiPredicate)

Example 4 with BiPredicate

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);
}
Also used : Multimap(com.google.common.collect.Multimap) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) BiPredicate(java.util.function.BiPredicate)

Example 5 with BiPredicate

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;
}
Also used : DataOutputBufferFixed(org.apache.cassandra.io.util.DataOutputBufferFixed) java.util(java.util) BufferedDataOutputStreamPlus(org.apache.cassandra.io.util.BufferedDataOutputStreamPlus) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) TableId(org.apache.cassandra.schema.TableId) EncryptionContext(org.apache.cassandra.security.EncryptionContext) File(org.apache.cassandra.io.util.File) LoggerFactory(org.slf4j.LoggerFactory) org.apache.cassandra.db(org.apache.cassandra.db) ICompressor(org.apache.cassandra.io.compress.ICompressor) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) FBUtilities.updateChecksum(org.apache.cassandra.utils.FBUtilities.updateChecksum) ByteBuffer(java.nio.ByteBuffer) BiPredicate(java.util.function.BiPredicate) Allocation(org.apache.cassandra.db.commitlog.CommitLogSegment.Allocation) CDCWriteException(org.apache.cassandra.exceptions.CDCWriteException) PathUtils(org.apache.cassandra.io.util.PathUtils) CommitLogMetrics(org.apache.cassandra.metrics.CommitLogMetrics) FBUtilities.updateChecksumInt(org.apache.cassandra.utils.FBUtilities.updateChecksumInt) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) JVMStabilityInspector(org.apache.cassandra.utils.JVMStabilityInspector) FSWriteError(org.apache.cassandra.io.FSWriteError) MessagingService(org.apache.cassandra.net.MessagingService) Logger(org.slf4j.Logger) FileStore(java.nio.file.FileStore) StorageService(org.apache.cassandra.service.StorageService) IOException(java.io.IOException) ENTRY_OVERHEAD_SIZE(org.apache.cassandra.db.commitlog.CommitLogSegment.ENTRY_OVERHEAD_SIZE) CompressionParams(org.apache.cassandra.schema.CompressionParams) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) FileUtils(org.apache.cassandra.io.util.FileUtils) MBeanWrapper(org.apache.cassandra.utils.MBeanWrapper) CRC32(java.util.zip.CRC32) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CommitLogSegmentFileComparator(org.apache.cassandra.db.commitlog.CommitLogSegment.CommitLogSegmentFileComparator) File(org.apache.cassandra.io.util.File) CommitLogSegmentFileComparator(org.apache.cassandra.db.commitlog.CommitLogSegment.CommitLogSegmentFileComparator)

Aggregations

BiPredicate (java.util.function.BiPredicate)35 List (java.util.List)17 Collectors (java.util.stream.Collectors)16 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)12 Collections (java.util.Collections)12 Map (java.util.Map)11 Files (java.nio.file.Files)10 Set (java.util.Set)8 HashMap (java.util.HashMap)7 Objects (java.util.Objects)7 Paths (java.nio.file.Paths)6 Arrays (java.util.Arrays)6 HashSet (java.util.HashSet)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)6 Path (java.nio.file.Path)5 java.util (java.util)5 Collection (java.util.Collection)5 Function (java.util.function.Function)5