title: Neo4j Java Embedded Shortestpath
body: <p>I'm using this custom expander for <code>Neo4j</code> embedded using the shortestpath algorithm. However the shortestpath algorithm doesn't allow me to look up the last relationship in the path it's constructed because they haven't implemented it. I get an unsupported exception.</p>
  
  <p>I just need to check the property of the last relationship to keep expanding. Is there a way to do this?</p>
  
  <pre><code>public class CustomExpander implements PathExpander {
  
          private Integer conditionFromTime;
          private Integer conditionToTime;
          private Integer conditionDayInd;
          private Node startNode; 
          private Node endNode;
  
          public CustomExpander( Integer fromTime, Integer toTime, Integer dayInd, Node startNode ) {
              this.conditionFromTime = fromTime;
              this.conditionToTime = toTime;
              this.conditionDayInd = dayInd;
              this.startNode = startNode;
              this.endNode = endNode;
          }
          public CustomExpander( Integer fromTime, Integer toTime, Integer dayInd, Node startNode,Node endNode ) {
              this.conditionFromTime = fromTime;
              this.conditionToTime = toTime;
              this.conditionDayInd = dayInd;
              this.startNode = startNode;
              this.endNode = endNode;
          }
  
  
  
  
          public Iterable expand(Path path, BranchState bs) {
  
  
              Iterable&lt;Relationship&gt; something = path.endNode().getRelationships(TripGraphRelTypes.VISITS,Direction.BOTH);
  
              return new  FilteringIterable&lt;Relationship&gt;( something
                      , new Predicate&lt;Relationship&gt;() {
  
                  public boolean accept(Relationship t) {
                      //boolean result = tripRange.contains((Integer)t.getProperty(TripGraphProperties.VisitedByRel.departureToDsec.name()));
  
  
                          if ( (Integer)t.getProperty("departureToDsec") &lt;= conditionFromTime ) {
                              return false;
                          }
  
                          if ((Integer)t.getProperty("arrivalToDsec") &gt;= conditionToTime) {
                              return false;
                          }   
  
                 if ( path.length() &gt; 0 &amp;&amp; (Integer) path.lastRelationship().getProperty("arrivalToDsec") &lt; (Integer)t.getProperty("departureToDsec")){
                            return false;                        }        
  
                          return true;
  
                  }
              });
  
  
          }
  
  
  
  
  
  
  
  
  
          @Override
          public PathExpander reverse() {
              //System.out.println("reverse");
              return this;
          }
  
      }
  
  
      PathFinder&lt;Path&gt; finderGood = GraphAlgoFactory.shortestPath(expander, 10);
                          validPaths = filterValid2(finderGood.findAllPaths(n1, n2));
  
  java.lang.UnsupportedOperationException
      at org.neo4j.graphalgo.impl.path.ShortestPath$DirectionDataPath.lastRelationship(ShortestPath.java:394)
      at au.com.company.tripresolver.CustomExpander$1.accept(CustomExpander.java:104)
          at org.neo4j.helpers.collection.FilteringIterator.fetchNextOrNull(FilteringIterator.java:49)
          at org.neo4j.helpers.collection.PrefetchingIterator.peek(PrefetchingIterator.java:60)
          at org.neo4j.helpers.collection.PrefetchingIterator.hasNext(PrefetchingIterator.java:46)
          at org.neo4j.helpers.collection.NestingIterator.fetchNextOrNull(NestingIterator.java:69)
          at org.neo4j.helpers.collection.PrefetchingIterator.peek(PrefetchingIterator.java:60)
          at org.neo4j.helpers.collection.PrefetchingIterator.hasNext(PrefetchingIterator.java:46)
          at org.neo4j.graphalgo.impl.path.ShortestPath$DirectionData.fetchNextRelOrNull(ShortestPath.java:351)
          at org.neo4j.graphalgo.impl.path.ShortestPath$DirectionData.fetchNextOrNull(ShortestPath.java:296)
          at org.neo4j.graphalgo.impl.path.ShortestPath$DirectionData.fetchNextOrNull(ShortestPath.java:234)
          at org.neo4j.helpers.collection.PrefetchingIterator.peek(PrefetchingIterator.java:60)
          at org.neo4j.helpers.collection.PrefetchingIterator.hasNext(PrefetchingIterator.java:46)
          at org.neo4j.graphalgo.impl.path.ShortestPath.internalPaths(ShortestPath.java:138)
          at org.neo4j.graphalgo.impl.path.ShortestPath.findAllPaths(ShortestPath.java:110)
  </code></pre>