persolijn

an efficient router for busses
Log | Files | Refs

Node.java (2101B)


      1 package osm.message;
      2 
      3 import java.util.Iterator;
      4 
      5 import osm.routing.RoutingNode;
      6 import protobuf.ProtobufReader;
      7 
      8 // required sint64 id = 1;
      9 // repeated uint32 keys = 2 [packed = true]; // String IDs.
     10 // repeated uint32 vals = 3 [packed = true]; // String IDs.
     11 // optional Info info = 4; // May be omitted in omitmeta
     12 // required sint64 lat = 8;
     13 // required sint64 lon = 9;
     14 public class Node extends AbstractEntity<Node> implements RoutingNode<Node> {
     15     protected double latitude, longitude;
     16 
     17     protected Node parent = null;
     18     protected long score = Long.MAX_VALUE;
     19     protected long heuristicScore = Long.MAX_VALUE;
     20 
     21     public Node(PrimitiveBlock block) {
     22         super(block);
     23     }
     24 
     25     @Override
     26     public Node parseRemaining(Iterator<ProtobufReader> tags) {
     27         while (tags.hasNext()) {
     28             ProtobufReader message = tags.next();
     29             switch (message.tag()) {
     30                 case 4 -> message.skip();
     31                 case 8 -> latitude = block.latitudeOffset + block.granularity * message.svarint64();
     32                 case 9 -> longitude = block.longitudeOffset + block.granularity * message.svarint64();
     33                 default -> message.throwUnexpected();
     34             }
     35         }
     36         return null;
     37     }
     38 
     39     @Override
     40     public double getLatitude() {
     41         return latitude;
     42     }
     43 
     44     @Override
     45     public double getLongitude() {
     46         return longitude;
     47     }
     48 
     49     @Override
     50     public Node getParent() {
     51         return parent;
     52     }
     53 
     54     @Override
     55     public void setParent(Node parent) {
     56         this.parent = parent;
     57     }
     58 
     59     @Override
     60     public boolean hasParent() {
     61         return parent != null;
     62     }
     63 
     64     @Override
     65     public long getScore() {
     66         return score;
     67     }
     68 
     69     @Override
     70     public void setScore(long value) {
     71         score = value;
     72     }
     73 
     74     @Override
     75     public long getHeuristicScore() {
     76         return heuristicScore;
     77     }
     78 
     79     @Override
     80     public void setHeuristicScore(long value) {
     81         heuristicScore = value;
     82     }
     83 
     84     @Override
     85     public String toString() {
     86         return String.format("Node#%d", id);
     87     }
     88 }