package se.chalmers.cs.gf.graph; import java.util.*; public class Path { private List legs; public Path() { legs = new LinkedList(); } public void addLeg(String from, String to, double dist, String label) { legs.add(new Leg(from, to, dist, label)); } public List getLegs() { return Collections.unmodifiableList(legs); } public double getLength() { double length = 0.0; for (Leg l : legs) length += l.getDist(); return length; } public class Leg { private String from; private String to; private double dist; private String label; public Leg(String from, String to, double dist, String label) { this.from = from; this.to = to; this.dist = dist; this.label = label; } public String getFrom() { return from; } public String getTo() { return to; } public double getDist() { return dist; } public String getLabel() { return label; } } public String toString() { StringBuilder sb = new StringBuilder(); for (Leg l : legs) { sb.append(l.getLabel()); sb.append(" from ").append(l.getFrom()); sb.append(" to ").append(l.getTo()); sb.append(", dist ").append(l.getDist()); sb.append(".\n"); } return sb.toString(); } }