use of com.tinkerpop.pipes.PipeFunction in project gremlin by tinkerpop.
the class TransformStepTest method test_g_v1_transformXnameX.
public void test_g_v1_transformXnameX() {
super.test_g_v1_transformXnameX(new GremlinPipeline(g.getVertex(1)).transform(new PipeFunction<Vertex, String>() {
public String compute(Vertex vertex) {
return (String) vertex.getProperty("name");
}
}));
super.test_g_v1_transformXnameX(new GremlinPipeline(g.getVertex(1)).optimize(false).transform(new PipeFunction<Vertex, String>() {
public String compute(Vertex vertex) {
return (String) vertex.getProperty("name");
}
}));
}
use of com.tinkerpop.pipes.PipeFunction in project gremlin by tinkerpop.
the class TransformStepTest method test_g_v1_out_transformXnameX_transformXlengthX.
public void test_g_v1_out_transformXnameX_transformXlengthX() {
super.test_g_v1_out_transformXnameX_transformXlengthX(new GremlinPipeline(g.getVertex(1)).out().transform(new PipeFunction<Vertex, String>() {
public String compute(Vertex vertex) {
return (String) vertex.getProperty("name");
}
}).transform(new PipeFunction<String, Integer>() {
public Integer compute(String name) {
return name.length();
}
}));
super.test_g_v1_out_transformXnameX_transformXlengthX(new GremlinPipeline(g.getVertex(1)).optimize(false).out().transform(new PipeFunction<Vertex, String>() {
public String compute(Vertex vertex) {
return (String) vertex.getProperty("name");
}
}).transform(new PipeFunction<String, Integer>() {
public Integer compute(String name) {
return name.length();
}
}));
}
use of com.tinkerpop.pipes.PipeFunction in project gremlin by tinkerpop.
the class TransformStepTest method test_g_v1_outE_label_transformXlengthX.
public void test_g_v1_outE_label_transformXlengthX() {
super.test_g_v1_outE_label_transformXlengthX(new GremlinPipeline(g.getVertex(1)).outE().label().transform(new PipeFunction<String, Integer>() {
public Integer compute(String name) {
return name.length();
}
}));
super.test_g_v1_outE_label_transformXlengthX(new GremlinPipeline(g.getVertex(1)).optimize(false).outE().label().transform(new PipeFunction<String, Integer>() {
public Integer compute(String name) {
return name.length();
}
}));
}
use of com.tinkerpop.pipes.PipeFunction in project incubator-atlas by apache.
the class TermResourceDefinition method getHierarchyProjection.
private Projection getHierarchyProjection() {
final String projectionName = "hierarchy";
return new Projection(projectionName, Projection.Cardinality.SINGLE, new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() {
@Override
public Collection<ProjectionResult> compute(VertexWrapper start) {
Map<String, Object> map = new TreeMap<>(new ResourceComparator());
TermPath termPath = new TermPath(start.getVertex().<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY));
map.put("path", termPath.getPath());
map.put("short_name", termPath.getShortName());
map.put("taxonomy", termPath.getTaxonomyName());
return Collections.singleton(new ProjectionResult(projectionName, start, Collections.singleton(map)));
}
}));
}
use of com.tinkerpop.pipes.PipeFunction in project incubator-atlas by apache.
the class TermResourceDefinition method getSubTermProjection.
private Projection getSubTermProjection() {
// todo: combine with other term projections
final String termsProjectionName = "terms";
return new Projection(termsProjectionName, Projection.Cardinality.SINGLE, new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() {
@Override
public Collection<ProjectionResult> compute(VertexWrapper start) {
Map<String, Object> map = new TreeMap<>(new ResourceComparator());
StringBuilder sb = new StringBuilder();
sb.append("v1/taxonomies/");
TermPath termPath = new TermPath(start.getVertex().<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY));
String[] paths = termPath.getPathSegments();
sb.append(termPath.getTaxonomyName());
for (String path : paths) {
// todo: shouldn't need to check for null or empty after TermPath addition
if (path != null && !path.isEmpty()) {
sb.append("/terms/");
sb.append(path);
}
}
sb.append("/terms");
map.put("href", sb.toString());
return Collections.singleton(new ProjectionResult(termsProjectionName, start, Collections.singleton(map)));
}
}));
}
Aggregations