Search in sources :

Example 31 with BiPredicate

use of java.util.function.BiPredicate in project sqlg by pietermartin.

the class ReplacedStep method appendPathForVertexStep.

private Set<SchemaTableTree> appendPathForVertexStep(SchemaTableTree schemaTableTree) {
    Preconditions.checkArgument(schemaTableTree.getSchemaTable().isVertexTable(), "Expected a Vertex table found " + schemaTableTree.getSchemaTable().getTable());
    Set<SchemaTableTree> result = new HashSet<>();
    Pair<Set<SchemaTable>, Set<SchemaTable>> inAndOutLabelsFromCurrentPosition = this.topology.getTableLabels(schemaTableTree.getSchemaTable());
    VertexStep vertexStep = (VertexStep) this.step;
    String[] edgeLabels = vertexStep.getEdgeLabels();
    Direction direction = vertexStep.getDirection();
    Class<? extends Element> elementClass = vertexStep.getReturnClass();
    Set<SchemaTable> inEdgeLabels = inAndOutLabelsFromCurrentPosition != null ? inAndOutLabelsFromCurrentPosition.getLeft() : new HashSet<>();
    Set<SchemaTable> outEdgeLabels = inAndOutLabelsFromCurrentPosition != null ? inAndOutLabelsFromCurrentPosition.getRight() : new HashSet<>();
    Set<SchemaTable> inEdgeLabelsToTraversers;
    Set<SchemaTable> outEdgeLabelsToTraversers;
    switch(vertexStep.getDirection()) {
        case IN:
            inEdgeLabelsToTraversers = filterVertexStepOnEdgeLabels(inEdgeLabels, edgeLabels);
            outEdgeLabelsToTraversers = new HashSet<>();
            break;
        case OUT:
            outEdgeLabelsToTraversers = filterVertexStepOnEdgeLabels(outEdgeLabels, edgeLabels);
            inEdgeLabelsToTraversers = new HashSet<>();
            break;
        case BOTH:
            inEdgeLabelsToTraversers = edgeLabels.length > 0 ? filterVertexStepOnEdgeLabels(inEdgeLabels, edgeLabels) : inEdgeLabels;
            outEdgeLabelsToTraversers = edgeLabels.length > 0 ? filterVertexStepOnEdgeLabels(outEdgeLabels, edgeLabels) : outEdgeLabels;
            break;
        default:
            throw new IllegalStateException("Unknown direction " + direction.name());
    }
    Map<SchemaTable, List<Multimap<BiPredicate, RecordId>>> groupedIds = groupIdsBySchemaTable();
    // Each labelToTravers more than the first one forms a new distinct path
    for (SchemaTable inEdgeLabelToTravers : inEdgeLabelsToTraversers) {
        if (elementClass.isAssignableFrom(Edge.class)) {
            if (passesLabelHasContainers(this.topology.getSqlgGraph(), false, inEdgeLabelToTravers.toString())) {
                SchemaTableTree schemaTableTreeChild = schemaTableTree.addChild(inEdgeLabelToTravers, Direction.IN, elementClass, this, this.labels);
                SchemaTable schemaTable = SchemaTable.from(this.topology.getSqlgGraph(), inEdgeLabelToTravers.toString());
                List<Multimap<BiPredicate, RecordId>> biPredicateRecordIs = groupedIds.get(schemaTable.withOutPrefix());
                addIdHasContainers(schemaTableTreeChild, biPredicateRecordIs);
                result.add(schemaTableTreeChild);
            }
        } else {
            Map<String, Set<String>> edgeForeignKeys = this.topology.getAllEdgeForeignKeys();
            Set<String> foreignKeys = edgeForeignKeys.get(inEdgeLabelToTravers.toString());
            boolean first = true;
            SchemaTableTree schemaTableTreeChild = null;
            for (String foreignKey : foreignKeys) {
                if (foreignKey.endsWith(Topology.OUT_VERTEX_COLUMN_END)) {
                    String[] split = foreignKey.split("\\.");
                    String foreignKeySchema = split[0];
                    String foreignKeyTable = split[1];
                    SchemaTable schemaTableTo = SchemaTable.of(foreignKeySchema, VERTEX_PREFIX + SqlgUtil.removeTrailingOutId(foreignKeyTable));
                    if (passesLabelHasContainers(this.topology.getSqlgGraph(), true, schemaTableTo.toString())) {
                        if (first) {
                            first = false;
                            schemaTableTreeChild = schemaTableTree.addChild(inEdgeLabelToTravers, Direction.IN, elementClass, this, Collections.emptySet());
                        }
                        result.addAll(calculatePathFromVertexToEdge(schemaTableTreeChild, schemaTableTo, Direction.IN, groupedIds));
                    }
                }
            }
        }
    }
    for (SchemaTable outEdgeLabelToTravers : outEdgeLabelsToTraversers) {
        if (elementClass.isAssignableFrom(Edge.class)) {
            if (passesLabelHasContainers(this.topology.getSqlgGraph(), false, outEdgeLabelToTravers.toString())) {
                SchemaTableTree schemaTableTreeChild = schemaTableTree.addChild(outEdgeLabelToTravers, Direction.OUT, elementClass, this, this.labels);
                SchemaTable schemaTable = SchemaTable.from(this.topology.getSqlgGraph(), outEdgeLabelToTravers.toString());
                List<Multimap<BiPredicate, RecordId>> biPredicateRecordIds = groupedIds.get(schemaTable.withOutPrefix());
                addIdHasContainers(schemaTableTreeChild, biPredicateRecordIds);
                result.add(schemaTableTreeChild);
            }
        } else {
            Map<String, Set<String>> edgeForeignKeys = this.topology.getAllEdgeForeignKeys();
            Set<String> foreignKeys = edgeForeignKeys.get(outEdgeLabelToTravers.toString());
            boolean first = true;
            SchemaTableTree schemaTableTreeChild = null;
            for (String foreignKey : foreignKeys) {
                if (foreignKey.endsWith(Topology.IN_VERTEX_COLUMN_END)) {
                    String[] split = foreignKey.split("\\.");
                    String foreignKeySchema = split[0];
                    String foreignKeyTable = split[1];
                    SchemaTable schemaTableTo = SchemaTable.of(foreignKeySchema, VERTEX_PREFIX + SqlgUtil.removeTrailingInId(foreignKeyTable));
                    if (passesLabelHasContainers(this.topology.getSqlgGraph(), true, schemaTableTo.toString())) {
                        if (first) {
                            first = false;
                            schemaTableTreeChild = schemaTableTree.addChild(outEdgeLabelToTravers, Direction.OUT, elementClass, this, Collections.emptySet());
                        }
                        result.addAll(calculatePathFromVertexToEdge(schemaTableTreeChild, schemaTableTo, Direction.OUT, groupedIds));
                    }
                }
            }
        }
    }
    return result;
}
Also used : EdgeOtherVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeOtherVertexStep) EdgeVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) Multimap(com.google.common.collect.Multimap) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) BiPredicate(java.util.function.BiPredicate)

Example 32 with BiPredicate

use of java.util.function.BiPredicate in project fmv by f-agu.

the class PdfSoftProvider method getDefaultSoftPolicy.

// ***********************************************************************
/**
 * @return
 */
private static SoftPolicy getDefaultSoftPolicy() {
    Version v012 = new Version(0, 12);
    BiPredicate<SoftInfo, Provider> isProvider = (s, p) -> s instanceof XPdfVersionSoftInfo && ((XPdfVersionSoftInfo) s).getProvider() == p;
    return new VersionSoftPolicy().on("xpdf", s -> isProvider.test(s, Provider.XPDF), minVersion(Version.V3)).on("poppler", s -> isProvider.test(s, Provider.POPPLER), minVersion(v012)).onAllPlatforms(minVersion(v012));
}
Also used : Arrays(java.util.Arrays) VersionParserManager(org.fagu.version.VersionParserManager) SoftFound(org.fagu.fmv.soft.find.SoftFound) ProgramFilesLocatorSupplier(org.fagu.fmv.soft.win32.ProgramFilesLocatorSupplier) ArrayList(java.util.ArrayList) SoftProvider(org.fagu.fmv.soft.find.SoftProvider) BiPredicate(java.util.function.BiPredicate) Matcher(java.util.regex.Matcher) VersionSoftPolicy(org.fagu.fmv.soft.find.policy.VersionSoftPolicy) ObjectUtils(org.apache.commons.lang3.ObjectUtils) ExceptionKnownAnalyzer(org.fagu.fmv.soft.exec.exception.ExceptionKnownAnalyzer) XpdfExceptionKnownAnalyzer(org.fagu.fmv.soft.xpdf.exception.XpdfExceptionKnownAnalyzer) Soft(org.fagu.fmv.soft.Soft) SoftFoundFactory(org.fagu.fmv.soft.find.SoftFoundFactory) SoftLocator(org.fagu.fmv.soft.find.SoftLocator) SoftPolicy(org.fagu.fmv.soft.find.SoftPolicy) SystemUtils(org.apache.commons.lang3.SystemUtils) SoftInfo(org.fagu.fmv.soft.find.SoftInfo) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) VersionSoftPolicy.minVersion(org.fagu.fmv.soft.find.policy.VersionSoftPolicy.minVersion) List(java.util.List) Parser(org.fagu.fmv.soft.find.ExecSoftFoundFactory.Parser) Pattern(java.util.regex.Pattern) Version(org.fagu.version.Version) Collections(java.util.Collections) SoftExecutor(org.fagu.fmv.soft.SoftExecutor) SoftInfo(org.fagu.fmv.soft.find.SoftInfo) VersionSoftPolicy(org.fagu.fmv.soft.find.policy.VersionSoftPolicy) VersionSoftPolicy.minVersion(org.fagu.fmv.soft.find.policy.VersionSoftPolicy.minVersion) Version(org.fagu.version.Version) SoftProvider(org.fagu.fmv.soft.find.SoftProvider)

Example 33 with BiPredicate

use of java.util.function.BiPredicate in project azure-tools-for-java by Microsoft.

the class IntellijStorageActionsContributor method registerHandlers.

@Override
public void registerHandlers(AzureActionManager am) {
    final BiPredicate<Object, AnActionEvent> condition = (r, e) -> r instanceof AzureStorageAccount;
    final BiConsumer<Object, AnActionEvent> handler = (c, e) -> CreateStorageAccountAction.createStorageAccount((e.getProject()));
    am.registerHandler(ResourceCommonActionsContributor.CREATE, condition, handler);
    am.<IAzureResource<?>, AnActionEvent>registerHandler(ResourceCommonActionsContributor.CONNECT, (r, e) -> r instanceof StorageAccount, (r, e) -> AzureTaskManager.getInstance().runLater(() -> {
        final ConnectorDialog dialog = new ConnectorDialog(e.getProject());
        dialog.setResource(new AzureServiceResource<>(((StorageAccount) r), StorageAccountResourceDefinition.INSTANCE));
        dialog.show();
    }));
}
Also used : AzureActionManager(com.microsoft.azure.toolkit.lib.common.action.AzureActionManager) AzureServiceResource(com.microsoft.azure.toolkit.intellij.connector.AzureServiceResource) CreateStorageAccountAction(com.microsoft.azure.toolkit.intellij.storage.creation.CreateStorageAccountAction) AzureStorageAccount(com.microsoft.azure.toolkit.lib.storage.service.AzureStorageAccount) StorageAccountResourceDefinition(com.microsoft.azure.toolkit.intellij.storage.connection.StorageAccountResourceDefinition) BiPredicate(java.util.function.BiPredicate) IActionsContributor(com.microsoft.azure.toolkit.ide.common.IActionsContributor) ResourceCommonActionsContributor(com.microsoft.azure.toolkit.ide.common.action.ResourceCommonActionsContributor) StorageAccount(com.microsoft.azure.toolkit.lib.storage.service.StorageAccount) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) BiConsumer(java.util.function.BiConsumer) ConnectorDialog(com.microsoft.azure.toolkit.intellij.connector.ConnectorDialog) IAzureResource(com.microsoft.azure.toolkit.lib.common.entity.IAzureResource) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) ConnectorDialog(com.microsoft.azure.toolkit.intellij.connector.ConnectorDialog) AzureStorageAccount(com.microsoft.azure.toolkit.lib.storage.service.AzureStorageAccount) AzureServiceResource(com.microsoft.azure.toolkit.intellij.connector.AzureServiceResource) AzureStorageAccount(com.microsoft.azure.toolkit.lib.storage.service.AzureStorageAccount) StorageAccount(com.microsoft.azure.toolkit.lib.storage.service.StorageAccount) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) IAzureResource(com.microsoft.azure.toolkit.lib.common.entity.IAzureResource)

Example 34 with BiPredicate

use of java.util.function.BiPredicate in project cassandra by apache.

the class LogRecord method getExistingFiles.

/**
 * absoluteFilePaths contains full file parts up to (but excluding) the component name
 *
 * This method finds all files on disk beginning with any of the paths in absoluteFilePaths
 *
 * @return a map from absoluteFilePath to actual file on disk.
 */
public static Map<String, List<File>> getExistingFiles(Set<String> absoluteFilePaths) {
    Map<String, List<File>> fileMap = new HashMap<>();
    Map<File, TreeSet<String>> dirToFileNamePrefix = new HashMap<>();
    for (String absolutePath : absoluteFilePaths) {
        Path fullPath = new File(absolutePath).toPath();
        Path path = fullPath.getParent();
        if (path != null)
            dirToFileNamePrefix.computeIfAbsent(new File(path), (k) -> new TreeSet<>()).add(fullPath.getFileName().toString());
    }
    BiPredicate<File, String> ff = (dir, name) -> {
        TreeSet<String> dirSet = dirToFileNamePrefix.get(dir);
        // if the set contains a prefix of the current file name, the file name we have here should sort directly
        // after the prefix in the tree set, which means we can use 'floor' to get the prefix (returns the largest
        // of the smaller strings in the set). Also note that the prefixes always end with '-' which means we won't
        // have "xy-1111-Data.db".startsWith("xy-11") below (we'd get "xy-1111-Data.db".startsWith("xy-11-"))
        String baseName = dirSet.floor(name);
        if (baseName != null && name.startsWith(baseName)) {
            String absolutePath = new File(dir, baseName).path();
            fileMap.computeIfAbsent(absolutePath, k -> new ArrayList<>()).add(new File(dir, name));
        }
        return false;
    };
    // populate the file map:
    for (File f : dirToFileNamePrefix.keySet()) f.tryList(ff);
    return fileMap;
}
Also used : Path(java.nio.file.Path) java.util(java.util) FBUtilities(org.apache.cassandra.utils.FBUtilities) File(org.apache.cassandra.io.util.File) SSTable(org.apache.cassandra.io.sstable.SSTable) Collectors(java.util.stream.Collectors) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) BiPredicate(java.util.function.BiPredicate) Matcher(java.util.regex.Matcher) FileUtils(org.apache.cassandra.io.util.FileUtils) Component(org.apache.cassandra.io.sstable.Component) CRC32(java.util.zip.CRC32) PathUtils(org.apache.cassandra.io.util.PathUtils) Pattern(java.util.regex.Pattern) Path(java.nio.file.Path) File(org.apache.cassandra.io.util.File)

Example 35 with BiPredicate

use of java.util.function.BiPredicate in project kafka by apache.

the class MetadataCache method mergeWith.

/**
 * Merges the metadata cache's contents with the provided metadata, returning a new metadata cache. The provided
 * metadata is presumed to be more recent than the cache's metadata, and therefore all overlapping metadata will
 * be overridden.
 *
 * @param newClusterId the new cluster Id
 * @param newNodes the new set of nodes
 * @param addPartitions partitions to add
 * @param addUnauthorizedTopics unauthorized topics to add
 * @param addInternalTopics internal topics to add
 * @param newController the new controller node
 * @param topicIds the mapping from topic name to topic ID from the MetadataResponse
 * @param retainTopic returns whether a topic's metadata should be retained
 * @return the merged metadata cache
 */
MetadataCache mergeWith(String newClusterId, Map<Integer, Node> newNodes, Collection<PartitionMetadata> addPartitions, Set<String> addUnauthorizedTopics, Set<String> addInvalidTopics, Set<String> addInternalTopics, Node newController, Map<String, Uuid> topicIds, BiPredicate<String, Boolean> retainTopic) {
    Predicate<String> shouldRetainTopic = topic -> retainTopic.test(topic, internalTopics.contains(topic));
    Map<TopicPartition, PartitionMetadata> newMetadataByPartition = new HashMap<>(addPartitions.size());
    // We want the most recent topic ID. We start with the previous ID stored for retained topics and then
    // update with newest information from the MetadataResponse. We always take the latest state, removing existing
    // topic IDs if the latest state contains the topic name but not a topic ID.
    Map<String, Uuid> newTopicIds = topicIds.entrySet().stream().filter(entry -> shouldRetainTopic.test(entry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    for (PartitionMetadata partition : addPartitions) {
        newMetadataByPartition.put(partition.topicPartition, partition);
        Uuid id = topicIds.get(partition.topic());
        if (id != null)
            newTopicIds.put(partition.topic(), id);
        else
            // Remove if the latest metadata does not have a topic ID
            newTopicIds.remove(partition.topic());
    }
    for (Map.Entry<TopicPartition, PartitionMetadata> entry : metadataByPartition.entrySet()) {
        if (shouldRetainTopic.test(entry.getKey().topic())) {
            newMetadataByPartition.putIfAbsent(entry.getKey(), entry.getValue());
        }
    }
    Set<String> newUnauthorizedTopics = fillSet(addUnauthorizedTopics, unauthorizedTopics, shouldRetainTopic);
    Set<String> newInvalidTopics = fillSet(addInvalidTopics, invalidTopics, shouldRetainTopic);
    Set<String> newInternalTopics = fillSet(addInternalTopics, internalTopics, shouldRetainTopic);
    return new MetadataCache(newClusterId, newNodes, newMetadataByPartition.values(), newUnauthorizedTopics, newInvalidTopics, newInternalTopics, newController, newTopicIds);
}
Also used : Uuid(org.apache.kafka.common.Uuid) TopicPartition(org.apache.kafka.common.TopicPartition) ClusterResource(org.apache.kafka.common.ClusterResource) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) HashMap(java.util.HashMap) PartitionInfo(org.apache.kafka.common.PartitionInfo) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) PartitionMetadata(org.apache.kafka.common.requests.MetadataResponse.PartitionMetadata) HashSet(java.util.HashSet) BiPredicate(java.util.function.BiPredicate) Cluster(org.apache.kafka.common.Cluster) List(java.util.List) Map(java.util.Map) Optional(java.util.Optional) Node(org.apache.kafka.common.Node) MetadataResponse(org.apache.kafka.common.requests.MetadataResponse) Collections(java.util.Collections) HashMap(java.util.HashMap) Uuid(org.apache.kafka.common.Uuid) TopicPartition(org.apache.kafka.common.TopicPartition) PartitionMetadata(org.apache.kafka.common.requests.MetadataResponse.PartitionMetadata) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

BiPredicate (java.util.function.BiPredicate)36 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 Objects (java.util.Objects)8 Set (java.util.Set)8 HashMap (java.util.HashMap)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