use of org.neo4j.helpers.collection.IterableWrapper in project neo4j by neo4j.
the class DatabaseActions method getIndexedNodes.
public ListRepresentation getIndexedNodes(String indexName, final String key, final String value) {
if (!graphDb.index().existsForNodes(indexName)) {
throw new NotFoundException();
}
Index<Node> index = graphDb.index().forNodes(indexName);
final IndexRepresentation indexRepresentation = new NodeIndexRepresentation(indexName);
final IndexHits<Node> indexHits = index.get(key, value);
final IterableWrapper<Representation, Node> results = new IterableWrapper<Representation, Node>(indexHits) {
@Override
protected Representation underlyingObjectToObject(Node node) {
return new IndexedEntityRepresentation(node, key, value, indexRepresentation);
}
};
return new ListRepresentation(RepresentationType.NODE, results);
}
use of org.neo4j.helpers.collection.IterableWrapper in project neo4j by neo4j.
the class DatabaseActions method getIndexedRelationships.
public ListRepresentation getIndexedRelationships(String indexName, final String key, final String value) {
if (!graphDb.index().existsForRelationships(indexName)) {
throw new NotFoundException();
}
Index<Relationship> index = graphDb.index().forRelationships(indexName);
final IndexRepresentation indexRepresentation = new RelationshipIndexRepresentation(indexName);
IterableWrapper<Representation, Relationship> result = new IterableWrapper<Representation, Relationship>(index.get(key, value)) {
@Override
protected Representation underlyingObjectToObject(Relationship relationship) {
return new IndexedEntityRepresentation(relationship, key, value, indexRepresentation);
}
};
return new ListRepresentation(RepresentationType.RELATIONSHIP, result);
}
use of org.neo4j.helpers.collection.IterableWrapper in project neo4j by neo4j.
the class CypherPlanRepresentation method serialize.
@Override
protected void serialize(MappingSerializer mappingSerializer) {
final ExecutionPlanDescription planDescription = getPlan();
mappingSerializer.putString("name", planDescription.getName());
Map<String, Object> arguments = planDescription.getArguments();
MappingRepresentation argsRepresentation = getMapRepresentation(arguments);
mappingSerializer.putMapping("args", argsRepresentation);
if (planDescription.hasProfilerStatistics()) {
ExecutionPlanDescription.ProfilerStatistics stats = planDescription.getProfilerStatistics();
mappingSerializer.putNumber("rows", stats.getRows());
mappingSerializer.putNumber("dbHits", stats.getDbHits());
}
mappingSerializer.putList("children", new ListRepresentation("children", new IterableWrapper<Representation, ExecutionPlanDescription>(planDescription.getChildren()) {
@Override
protected Representation underlyingObjectToObject(final ExecutionPlanDescription childPlan) {
return newFromPlan(childPlan);
}
}));
}
use of org.neo4j.helpers.collection.IterableWrapper in project neo4j-documentation by neo4j.
the class Person method getStatus.
public Iterable<StatusUpdate> getStatus() {
Relationship firstStatus = underlyingNode.getSingleRelationship(STATUS, Direction.OUTGOING);
if (firstStatus == null) {
return Collections.emptyList();
}
// START SNIPPET: getStatusTraversal
TraversalDescription traversal = graphDb().traversalDescription().depthFirst().relationships(NEXT);
return new IterableWrapper<StatusUpdate, Path>(traversal.traverse(firstStatus.getEndNode())) {
@Override
protected StatusUpdate underlyingObjectToObject(Path path) {
return new StatusUpdate(path.endNode());
}
};
}
use of org.neo4j.helpers.collection.IterableWrapper in project neo4j-mobile-android by neo4j-contrib.
the class ShortestPath method getPaths.
private static Iterable<LinkedList<Relationship>> getPaths(Hit hit, DirectionData data) {
LevelData levelData = data.visitedNodes.get(hit.connectingNode);
if (levelData.depth == 0) {
Collection<LinkedList<Relationship>> result = new ArrayList<LinkedList<Relationship>>();
result.add(new LinkedList<Relationship>());
return result;
}
Collection<PathData> set = new ArrayList<PathData>();
GraphDatabaseService graphDb = data.startNode.getGraphDatabase();
for (long rel : levelData.relsToHere) {
set.add(new PathData(hit.connectingNode, new LinkedList<Relationship>(Arrays.asList(graphDb.getRelationshipById(rel)))));
}
for (int i = 0; i < levelData.depth - 1; i++) {
// One level
Collection<PathData> nextSet = new ArrayList<PathData>();
for (PathData entry : set) {
// One path...
Node otherNode = entry.rels.getFirst().getOtherNode(entry.node);
LevelData otherLevelData = data.visitedNodes.get(otherNode);
int counter = 0;
for (long rel : otherLevelData.relsToHere) {
// ...may split into several paths
LinkedList<Relationship> rels = ++counter == otherLevelData.relsToHere.length ? // lists being copied
entry.rels : new LinkedList<Relationship>(entry.rels);
rels.addFirst(graphDb.getRelationshipById(rel));
nextSet.add(new PathData(otherNode, rels));
}
}
set = nextSet;
}
return new IterableWrapper<LinkedList<Relationship>, PathData>(set) {
@Override
protected LinkedList<Relationship> underlyingObjectToObject(PathData object) {
return object.rels;
}
};
}
Aggregations