use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class CompiledExpandUtils method connectingRelationships.
public static RelationshipIterator connectingRelationships(ReadOperations readOperations, long fromNode, Direction direction, long toNode) throws EntityNotFoundException {
int fromDegree = readOperations.nodeGetDegree(fromNode, direction);
if (fromDegree == 0) {
return RelationshipIterator.EMPTY;
}
int toDegree = readOperations.nodeGetDegree(toNode, direction.reverse());
if (toDegree == 0) {
return RelationshipIterator.EMPTY;
}
long startNode;
long endNode;
Direction relDirection;
if (fromDegree < toDegree) {
startNode = fromNode;
endNode = toNode;
relDirection = direction;
} else {
startNode = toNode;
endNode = fromNode;
relDirection = direction.reverse();
}
RelationshipIterator allRelationships = readOperations.nodeGetRelationships(startNode, relDirection);
return connectingRelationshipsIterator(allRelationships, startNode, endNode);
}
use of org.neo4j.graphdb.Direction in project neo4j-mobile-android by neo4j-contrib.
the class StandardExpander method create.
static StandardExpander create(RelationshipType type1, Direction dir1, RelationshipType type2, Direction dir2, Object... more) {
Map<Direction, Collection<RelationshipType>> tempMap = temporaryTypeMap();
tempMap.get(dir1).add(type1);
tempMap.get(dir2).add(type2);
for (int i = 0; i < more.length; i++) {
RelationshipType type = (RelationshipType) more[i++];
Direction direction = (Direction) more[i];
tempMap.get(direction).add(type);
}
return new RegularExpander(toTypeMap(tempMap));
}
use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class Ls method wrapInLimitingIterator.
private Iterator<Relationship> wrapInLimitingIterator(AppCommandParser parser, Iterator<Relationship> iterator, Map<String, Object> filterMap, boolean caseInsensitiveFilters, boolean looseFilters) throws ShellException {
final AtomicBoolean handBreak = new AtomicBoolean();
int maxRelsPerType = parser.optionAsNumber("m", DEFAULT_MAX_RELS_PER_TYPE_LIMIT).intValue();
Map<String, Direction> types = filterMapToTypes(getServer().getDb(), Direction.BOTH, filterMap, caseInsensitiveFilters, looseFilters);
return new FilteringIterator<Relationship>(iterator, new LimitPerTypeFilter(maxRelsPerType, types, handBreak)) {
@Override
protected Relationship fetchNextOrNull() {
return handBreak.get() ? null : super.fetchNextOrNull();
}
};
}
use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class Mkrel method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
assertCurrentIsNode(session);
boolean createNode = parser.options().containsKey("c");
boolean suppliedNode = !parser.arguments().isEmpty();
Node node = null;
if (createNode) {
node = getServer().getDb().createNode(parseLabels(parser));
session.set(KEY_LAST_CREATED_NODE, "" + node.getId());
setProperties(node, parser.options().get("np"));
} else if (suppliedNode) {
node = getNodeById(Long.parseLong(parser.arguments().get(0)));
} else {
throw new ShellException("Must either create node (-c)" + " or supply node id as the first argument");
}
if (parser.options().get("t") == null) {
throw new ShellException("Must supply relationship type " + "(-t <relationship-type-name>)");
}
RelationshipType type = getRelationshipType(parser.options().get("t"));
Direction direction = getDirection(parser.options().get("d"));
NodeOrRelationship current = getCurrent(session);
Node currentNode = current.asNode();
Node startNode = direction == Direction.OUTGOING ? currentNode : node;
Node endNode = direction == Direction.OUTGOING ? node : currentNode;
Relationship relationship = startNode.createRelationshipTo(endNode, type);
setProperties(relationship, parser.options().get("rp"));
session.set(KEY_LAST_CREATED_RELATIONSHIP, relationship.getId());
boolean verbose = parser.options().containsKey("v");
if (createNode && verbose) {
out.println("Node " + getDisplayName(getServer(), session, node, false) + " created");
}
if (verbose) {
out.println("Relationship " + getDisplayName(getServer(), session, relationship, true, false) + " created");
}
if (parser.options().containsKey("cd")) {
cdTo(session, node);
}
return Continuation.INPUT_COMPLETE;
}
use of org.neo4j.graphdb.Direction in project graphdb by neo4j-attic.
the class DijkstraDirectionTest method testDijkstraDirection3.
@Test
public void testDijkstraDirection3() {
Relationship r1 = graph.makeEdge("start", "b");
Relationship r2 = graph.makeEdge("c", "b");
Relationship r3 = graph.makeEdge("c", "d");
Relationship r4 = graph.makeEdge("e", "d");
Relationship r5 = graph.makeEdge("e", "f");
Relationship r6 = graph.makeEdge("g", "f");
Relationship r7 = graph.makeEdge("g", "end");
HashMap<Relationship, Direction> dirs = new HashMap<Relationship, Direction>();
Dijkstra<Double> dijkstra = new Dijkstra<Double>((double) 0, graph.getNode("start"), graph.getNode("end"), new directionSavingCostEvaluator(dirs), new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), Direction.BOTH, MyRelTypes.R1);
dijkstra.getCost();
assertEquals(Direction.OUTGOING, dirs.get(r1));
assertEquals(Direction.INCOMING, dirs.get(r2));
assertEquals(Direction.OUTGOING, dirs.get(r3));
assertEquals(Direction.INCOMING, dirs.get(r4));
assertEquals(Direction.OUTGOING, dirs.get(r5));
assertEquals(Direction.INCOMING, dirs.get(r6));
assertEquals(Direction.OUTGOING, dirs.get(r7));
}
Aggregations