use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.
the class GetWalksIT method shouldGetPathsWithLoops_2.
@Test
public void shouldGetPathsWithLoops_2() throws Exception {
// Given
final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).edge(TestGroups.EDGE_2, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
final GetWalks op = new GetWalks.Builder().input(seedA).operations(operation, operation, operation, operation).build();
// When
final Iterable<Walk> results = graph.execute(op, getUser());
// Then
assertThat(getPaths(results)).isEqualTo("AEDAE,AEDAB");
}
use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.
the class GetWalksIT method shouldGetPaths.
@Test
public void shouldGetPaths() throws Exception {
// Given
final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
final GetWalks op = new GetWalks.Builder().input(seedA).operations(operation, operation).build();
// When
final Iterable<Walk> results = graph.execute(op, getUser());
// Then
assertThat(getPaths(results)).isEqualTo("AED,ABC");
}
use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.
the class GetWalksIT method shouldNotFilterAnyWalksWhenAllContainProperty.
@Test
public void shouldNotFilterAnyWalksWhenAllContainProperty() throws Exception {
final Iterable<Walk> walks = getWalksThatPassPredicateTest(new CollectionContains(1));
assertThat(getPaths(walks)).isEqualTo("AED,ABC");
}
use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.
the class GetWalksIT method shouldGetPathsWithLoops_3.
@Test
public void shouldGetPathsWithLoops_3() throws Exception {
// Given
final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE_3, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
final GetWalks op = new GetWalks.Builder().input(seedA).operations(operation, operation, operation, operation).build();
// When
final Iterable<Walk> results = graph.execute(op, getUser());
// Then
assertThat(getPaths(results)).isEqualTo("AAAAA");
}
use of uk.gov.gchq.gaffer.data.graph.Walk in project gaffer-doc by gchq.
the class OperationExample method printResult.
public <RESULT_TYPE> void printResult(final RESULT_TYPE result) {
print("Result:");
print("\n{% codetabs name=\"Java\", type=\"java\" -%}");
if (result instanceof Iterable) {
for (final Object item : (Iterable) result) {
if (item instanceof Walk) {
final Walk walk = (Walk) item;
print(Walk.class.getName() + walk.getVerticesOrdered().stream().map(Object::toString).collect(Collectors.joining(" --> ", "[ ", " ]")));
} else {
print(item.toString());
}
}
} else if (result instanceof Map) {
final Map<?, ?> resultMap = (Map) result;
for (final Map.Entry<?, ?> entry : resultMap.entrySet()) {
print(entry.getKey() + ":");
if (entry.getValue() instanceof Iterable) {
for (final Object item : (Iterable) entry.getValue()) {
print(" " + item.toString());
}
} else {
print(" " + entry.getValue().toString());
}
}
} else if (result instanceof Stream) {
final Stream stream = (Stream) result;
stream.forEach(item -> print(item.toString()));
} else if (result instanceof Object[]) {
final Object[] array = (Object[]) result;
for (int i = 0; i < array.length; i++) {
print(array[i].toString());
}
} else if (result instanceof JavaRDD) {
final List<Element> elements = ((JavaRDD) result).collect();
for (final Element e : elements) {
print(e.toString());
}
} else if (result instanceof Dataset) {
final Dataset<Row> dataset = ((Dataset) result);
final String resultStr = dataset.showString(100, 20);
print(resultStr.substring(0, resultStr.length() - 2));
} else if (result instanceof Schema) {
print(DocUtil.getJson(result));
} else if (null != result) {
print(result.toString());
} else {
throw new RuntimeException("Operation result was null");
}
try {
final String json = DocUtil.getFullJson(result);
print(WalkthroughStrSubstitutor.JSON_CODE_MARKER);
print(json);
} catch (final Exception e) {
// ignore error - just don't display the json
}
print("{%- endcodetabs %}\n");
}
Aggregations