use of uk.gov.gchq.gaffer.operation.SeedMatching.SeedMatchingType in project Gaffer by gchq.
the class GetElementsUtil method getRelevantElements.
public static Set<Element> getRelevantElements(final MapImpl mapImpl, final ElementId elementId, final View view, final DirectedType directedType, final IncludeIncomingOutgoingType inOutType, final SeedMatchingType seedMatchingType) {
final Set<Element> relevantElements;
final Set<String> groups = view.getGroups();
Predicate<Element> isFiltered = e -> !groups.contains(e.getGroup());
if (elementId instanceof EntityId) {
final Collection<Element> elements = mapImpl.lookup(new EntitySeed(((EntityId) elementId).getVertex()));
if (elements.isEmpty()) {
return Collections.emptySet();
}
relevantElements = new HashSet<>(elements);
// Apply inOutType options - if option is EITHER then nothing to do
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
isFiltered = isFiltered.or(e -> e instanceof Edge && ((Edge) e).isDirected() && (EdgeId.MatchedVertex.SOURCE == ((Edge) e).getMatchedVertex()));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
isFiltered = isFiltered.or(e -> e instanceof Edge && ((Edge) e).isDirected() && (EdgeId.MatchedVertex.DESTINATION == ((Edge) e).getMatchedVertex()));
}
// Apply seedMatching option - if option is RELATED then nothing to do
if (seedMatchingType == SeedMatchingType.EQUAL) {
isFiltered = isFiltered.or(e -> e instanceof Edge);
}
} else {
relevantElements = new HashSet<>();
final EdgeId edgeId = (EdgeId) elementId;
if (DirectedType.isEither(edgeId.getDirectedType())) {
relevantElements.addAll(mapImpl.lookup(new EdgeSeed(edgeId.getSource(), edgeId.getDestination(), false)));
relevantElements.addAll(mapImpl.lookup(new EdgeSeed(edgeId.getSource(), edgeId.getDestination(), true)));
} else {
relevantElements.addAll(mapImpl.lookup(new EdgeSeed(edgeId.getSource(), edgeId.getDestination(), edgeId.getDirectedType())));
}
mapImpl.lookup(new EntitySeed(edgeId.getSource())).stream().filter(e -> e instanceof Entity).forEach(relevantElements::add);
mapImpl.lookup(new EntitySeed(edgeId.getDestination())).stream().filter(e -> e instanceof Entity).forEach(relevantElements::add);
// If option is RELATED then nothing to do
if (seedMatchingType == SeedMatchingType.EQUAL) {
isFiltered = isFiltered.or(e -> e instanceof Entity);
}
}
// Apply directedType flag
if (directedType == DirectedType.DIRECTED) {
isFiltered = isFiltered.or(e -> e instanceof Edge && !((Edge) e).isDirected());
} else if (directedType == DirectedType.UNDIRECTED) {
isFiltered = isFiltered.or(e -> e instanceof Edge && ((Edge) e).isDirected());
}
relevantElements.removeIf(isFiltered);
return relevantElements;
}
Aggregations