Railway Graph Representation in java