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;
}
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));
}
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();
}));
}
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;
}
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);
}
Aggregations