source: josm/trunk/src/org/openstreetmap/josm/data/osm/Way.java@ 627

Last change on this file since 627 was 627, checked in by framm, 16 years ago
  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data.osm;
3
4import java.util.ArrayList;
5import java.util.Arrays;
6import java.util.List;
7
8import org.openstreetmap.josm.data.osm.visitor.Visitor;
9import org.openstreetmap.josm.tools.Pair;
10
11/**
12 * One full way, consisting of a list of way nodes.
13 *
14 * @author imi
15 */
16public final class Way extends OsmPrimitive {
17
18 /**
19 * All way nodes in this way
20 */
21 public final List<Node> nodes = new ArrayList<Node>();
22
23 public void visitNodes(Visitor v) {
24 for (Node n : this.nodes)
25 v.visit(n);
26 }
27
28 public ArrayList<Pair<Node,Node>> getNodePairs(boolean sort) {
29 ArrayList<Pair<Node,Node>> chunkSet = new ArrayList<Pair<Node,Node>>();
30 Node lastN = null;
31 for (Node n : this.nodes) {
32 if (lastN == null) {
33 lastN = n;
34 continue;
35 }
36 Pair<Node,Node> np = new Pair<Node,Node>(lastN, n);
37 if (sort) {
38 Pair.sort(np);
39 }
40 chunkSet.add(np);
41 lastN = n;
42 }
43 return chunkSet;
44 }
45
46
47 @Override public void visit(Visitor visitor) {
48 visitor.visit(this);
49 }
50
51 /**
52 * Create an identical clone of the argument (including the id)
53 */
54 public Way(Way clone) {
55 cloneFrom(clone);
56 }
57
58 /**
59 * Create an empty way without id. Use this only if you set meaningful
60 * values yourself.
61 */
62 public Way() {
63 }
64
65 /**
66 * Create an incomplete Way.
67 */
68 public Way(long id) {
69 this.id = id;
70 incomplete = true;
71 }
72
73 @Override public void cloneFrom(OsmPrimitive osm) {
74 super.cloneFrom(osm);
75 nodes.clear();
76 nodes.addAll(((Way)osm).nodes);
77 checkDirectionTagged();
78 }
79
80 @Override public String toString() {
81 return "{Way id="+id+" version="+version+" nodes="+Arrays.toString(nodes.toArray())+"}";
82 }
83
84 @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
85 return osm instanceof Way ? super.realEqual(osm, semanticOnly) && nodes.equals(((Way)osm).nodes) : false;
86 }
87
88 public int compareTo(OsmPrimitive o) {
89 return o instanceof Way ? Long.valueOf(id).compareTo(o.id) : -1;
90 }
91
92 @Deprecated
93 public boolean isIncomplete() {
94 return incomplete;
95 }
96}
Note: See TracBrowser for help on using the repository browser.