001 // License: GPL. Copyright 2007 by Gabriel Ebner
002 package org.openstreetmap.josm.data.osm;
003
004 /**
005 * A segment consisting of 2 consecutive nodes out of a way.
006 */
007 public final class WaySegment {
008 /**
009 * The way.
010 */
011 public Way way;
012
013 /**
014 * The index of one of the 2 nodes in the way. The other node has the
015 * index <code>lowerIndex + 1</code>.
016 */
017 public int lowerIndex;
018
019 public WaySegment(Way w, int i) {
020 way = w;
021 lowerIndex = i;
022 }
023
024 public Node getFirstNode(){
025 return way.getNode(lowerIndex);
026 }
027
028 public Node getSecondNode(){
029 return way.getNode(lowerIndex + 1);
030 }
031
032 /**
033 * returns this way segment as complete way.
034 * @return
035 */
036 public Way toWay() {
037 Way w = new Way();
038 w.addNode(getFirstNode());
039 w.addNode(getSecondNode());
040 return w;
041 }
042
043 @Override public boolean equals(Object o) {
044 return o != null && o instanceof WaySegment
045 && ((WaySegment) o).way == way
046 && ((WaySegment) o).lowerIndex == lowerIndex;
047 }
048
049 @Override public int hashCode() {
050 return way.hashCode() ^ lowerIndex;
051 }
052 }