Changeset 343 in josm for trunk/src/org/openstreetmap/josm/data/osm/Segment.java
- Timestamp:
- 2007-10-07T13:20:27+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Segment.java
r298 r343 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others2 package org.openstreetmap.josm.data.osm;3 4 import org.openstreetmap.josm.data.osm.visitor.Visitor;5 6 7 /**8 * One way segment consisting of a pair of nodes (from/to)9 *10 * @author imi11 */12 public final class Segment extends OsmPrimitive {13 14 /**15 * The starting node of the segment16 */17 public Node from;18 19 /**20 * The ending node of the segment21 */22 public Node to;23 24 /**25 * If set to true, this object is incomplete, which means only the id26 * and type is known (type is the objects instance class)27 */28 public boolean incomplete;29 30 /**31 * Create an identical clone of the argument (including the id)32 */33 public Segment(Segment clone) {34 cloneFrom(clone);35 }36 37 /**38 * Create an segment from the given starting and ending node39 * @param from Starting node of the segment.40 * @param to Ending node of the segment.41 */42 public Segment(Node from, Node to) {43 this.from = from;44 this.to = to;45 incomplete = false;46 }47 48 public Segment(long id) {49 this.id = id;50 incomplete = true;51 }52 53 @Override public void visit(Visitor visitor) {54 visitor.visit(this);55 }56 57 /**58 * @return <code>true</code>, if the <code>ls</code> occupy59 * exactly the same place as <code>this</code>.60 */61 public boolean equalPlace(Segment ls) {62 if (equals(ls))63 return true;64 if (incomplete || ls.incomplete)65 return incomplete == ls.incomplete;66 return ((from.coor.equals(ls.from.coor) && to.coor.equals(ls.to.coor)) ||67 (from.coor.equals(ls.to.coor) && to.coor.equals(ls.from.coor)));68 }69 70 @Override public void cloneFrom(OsmPrimitive osm) {71 super.cloneFrom(osm);72 Segment ls = ((Segment)osm);73 from = ls.from;74 to = ls.to;75 incomplete = ls.incomplete;76 }77 78 @Override public String toString() {79 return "{Segment id="+id+" from="+from+" to="+to+"}";80 }81 82 @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {83 if (!(osm instanceof Segment))84 return super.realEqual(osm, semanticOnly);85 if (incomplete)86 return super.realEqual(osm, semanticOnly) && ((Segment)osm).incomplete;87 return super.realEqual(osm, semanticOnly) && from.equals(((Segment)osm).from) && to.equals(((Segment)osm).to);88 }89 90 public int compareTo(OsmPrimitive o) {91 return o instanceof Segment ? Long.valueOf(id).compareTo(o.id) : (o instanceof Node ? -1 : 1);92 }93 }
Note:
See TracChangeset
for help on using the changeset viewer.