@Override public Iterable<Relationship> expand(Path path, BranchState<Double> branchState) { ArrayList<Relationship> rels = new ArrayList<>(); Node endNode = path.endNode(); Double voltage = (Double) endNode.getProperty("voltage", 999.0); if (voltage <= branchState.getState()) { // Set the new voltage branchState.setState(voltage); endNode.getRelationships(Direction.OUTGOING, RelationshipTypes.CONNECTED).forEach(rel -> { if ((Boolean)rel.getProperty("incoming_switch_on", false) && (Boolean)rel.getProperty("outgoing_switch_on", false)) { rels.add(rel); } }); } return rels; }
@Override public Iterable<Relationship> expand(Path path, BranchState state) { if (System.currentTimeMillis() < stopTime) { switch (path.length()) { case 0: return path.endNode().getRelationships(Direction.OUTGOING, RelationshipTypes.HAS_DESTINATION); case 1: { Node lastNode = path.endNode(); if (destinations.contains((String) lastNode.getProperty("code"))) { return path.endNode().getRelationships(Direction.OUTGOING, relationshipTypes); } else { return Collections.emptyList(); } } case 2: case 3: { return path.endNode().getRelationships(Direction.OUTGOING, relationshipTypes); } default: return Collections.emptyList(); } } else { return Collections.emptyList(); } }
@Override public final Iterable<Relationship> expand(final Path path, final BranchState state) { List<Relationship> result = new ArrayList<>(); if (this.since == Long.MIN_VALUE && this.until == Long.MAX_VALUE) { return path.endNode().getRelationships(); } if (path.length() >= this.depth) { return result; } for (Relationship rel : path.endNode().getRelationships()) { long current = Long.parseLong(rel.getProperty("timestamp").toString()); if (until > current && current > since) { result.add(rel); } } return result; }
private StepExpander buildStepExpander( RelationshipFilterDescriptor relationshipDescriptor ) { List<PropertyContainerPredicate> relationshipPredicateList = relationshipDescriptor.getFilterPredicates(); final PredicateGroup<PropertyContainer> relationshipPredicates = ( relationshipPredicateList.isEmpty() ) ? null : new PredicateGroup<PropertyContainer>( relationshipPredicateList.toArray( new PropertyContainerPredicate[relationshipPredicateList.size()] ) ); final Function<Node, Iterator<Relationship>> expandFun = relationshipDescriptor.expandFun(); return new StepExpander() { @Override public Iterable<Relationship> expand( Path path, BranchState<StepState> state ) { final Node startNode = path.endNode(); Iterator<Relationship> relationships = ( null == relationshipPredicates ) ? expandFun.apply( startNode ) : Iterators.filter( expandFun.apply( startNode ), relationshipPredicates ); return ImmutableList.copyOf( relationships ); } }; }
@Override public Iterable<Relationship> expand(Path path, BranchState state) { List<Relationship> children = CHILDREN_ORDER.sortedCopy(path.endNode().getRelationships(RelType.PARENT_OF, Direction.OUTGOING)); if (synRels.isEmpty()) { return children; } else { List<Iterable<Relationship>> synResults = Lists.newArrayList(); for (RelType rt : synRels) { synResults.add(path.endNode().getRelationships(rt, Direction.INCOMING)); } return Iterables.concat( SYNONYM_ORDER.sortedCopy(Iterables.concat(synResults)), children ); } }
@Override public Iterable<Relationship> expand(Path path, BranchState branchState) { if (path.endNode().hasLabel(stopLabel)) { return Collections.emptyList(); } if (path.length() % 2 == 0) { return path.endNode().getRelationships(Direction.INCOMING); } else { return path.endNode().getRelationships(Direction.OUTGOING); } }
@Override public Evaluation evaluate(Path path, BranchState branchState) { if (path.endNode().hasLabel(stopLabel)) { return Evaluation.EXCLUDE_AND_PRUNE; } else { return Evaluation.INCLUDE_AND_CONTINUE; } }
@Override public Evaluation evaluate(Path path, BranchState<Double> branchState) { // Path with just the single node, ignore it and continue if (path.length() == 0 ) { return Evaluation.INCLUDE_AND_CONTINUE; } // Make sure last Equipment voltage is equal to or lower than previous voltage Double voltage = (Double) path.endNode().getProperty("voltage", 999.0); if (voltage <= branchState.getState()) { return Evaluation.INCLUDE_AND_CONTINUE; } else { return Evaluation.EXCLUDE_AND_PRUNE; } }
@Override public Iterable<Relationship> expand( Path path, BranchState<StepState> state ) { StepExpander stepExpander = stepExpanders[state.getState().step()]; /* * Return List because Iterable should be capable of returning multiple Iterator instances * Wrapping Iterator in an Iterable that can only consume it once would break the Iterable contract */ return ImmutableList.copyOf( stepExpander.expand( path, state ) ); }
@Override public Iterable<Relationship> expand(Path path, BranchState<Void> state) { return path.endNode().getRelationships(direction); }
@Override public Evaluation evaluate( Path path, BranchState<StepState> state ) { int currentStep = state.getState().step(); int stepStateState = state.getState().state(); while ( true ) { StepEvaluationResult result = stepEvaluators[currentStep].evaluate( path, stepStateState ); switch ( result.stepEvaluation() ) { case REJECT_STAY_EXCLUDE_PRUNE: /* * evaluator failed fatally */ return Evaluation.EXCLUDE_AND_PRUNE; case REJECT_ADVANCE_EXCLUDE_CONTINUE: /* * evaluator failed & exhausted * advance evaluator immediately (current step) & retry */ currentStep++; stepStateState = result.stepState(); continue; case ACCEPT_ADVANCE_EXCLUDE_CONTINUE: /* * evaluator succeeded & exhausted * advance evaluator for next step */ currentStep++; state.setState( new StepState( currentStep, result.stepState() ) ); return Evaluation.EXCLUDE_AND_CONTINUE; case ACCEPT_STAY_EXCLUDE_CONTINUE: /* * evaluator succeeded but not exhausted * reuse evaluator @ next step */ state.setState( new StepState( currentStep, result.stepState() ) ); return Evaluation.EXCLUDE_AND_CONTINUE; case ACCEPT_STAY_INCLUDE_CONTINUE: /* * final evaluator succeeded but not exhausted * return path & reuse evaluator @ next step */ state.setState( new StepState( currentStep, result.stepState() ) ); return Evaluation.INCLUDE_AND_CONTINUE; case ACCEPT_ADVANCE_INCLUDE_PRUNE: /* * final evaluator succeeded & exhausted * return path */ return Evaluation.INCLUDE_AND_PRUNE; } } }