org.openstreetmap.josm.data.osm
Class Way

java.lang.Object
  extended by org.openstreetmap.josm.data.osm.AbstractPrimitive
      extended by org.openstreetmap.josm.data.osm.OsmPrimitive
          extended by org.openstreetmap.josm.data.osm.Way
All Implemented Interfaces:
java.lang.Comparable<OsmPrimitive>, IPrimitive, IWay, PrimitiveId, Tagged, TemplateEngineDataProvider

public final class Way
extends OsmPrimitive
implements IWay

One full way, consisting of a list of way nodes.

Since:
64

Field Summary
private  BBox bbox
           
private  Node[] nodes
          All way nodes in this way
 
Fields inherited from class org.openstreetmap.josm.data.osm.OsmPrimitive
allPredicate, FLAG_DIRECTION_REVERSED, FLAG_DISABLED, FLAG_DISABLED_TYPE, FLAG_HAS_DIRECTIONS, FLAG_HIDDEN_TYPE, FLAG_HIDE_IF_DISABLED, FLAG_HIGHLIGHTED, FLAG_TAGGED, isSelectablePredicate, isUsablePredicate, mappaintCacheIdx, mappaintStyle, modifiedPredicate, multipolygonPredicate, nodePredicate, nonDeletedCompletePredicate, nonDeletedPhysicalPredicate, nonDeletedPredicate, relationPredicate, wayPredicate
 
Fields inherited from class org.openstreetmap.josm.data.osm.AbstractPrimitive
changesetId, FLAG_DELETED, FLAG_INCOMPLETE, FLAG_MODIFIED, FLAG_VISIBLE, flags, id, keys, timestamp, user, version
 
Constructor Summary
  Way()
          Contructs a new Way with id 0.
  Way(long id)
          Contructs a new Way for the given id.
protected Way(long id, boolean allowNegative)
           
  Way(long id, int version)
          Contructs a new Way with given id and version.
  Way(Way original)
          Contructs a new Way from an existing Way (including its id).
  Way(Way original, boolean clearId)
          Contructs a new Way from an existing Way.
 
Method Summary
 void addNode(int offs, Node n)
          Adds a node at position offs.
 void addNode(Node n)
          Adds a node to the end of the list of nodes.
private  void checkNodes()
           
 void cloneFrom(OsmPrimitive osm)
          Get and write all attributes from the parameter.
 int compareTo(OsmPrimitive o)
           
 boolean containsNode(Node node)
          Replies true if this way contains the node node, false otherwise.
private  void fireNodesChanged()
           
 Node firstNode()
          Returns the first node of this way.
 Node firstNode(boolean respectOneway)
          Replies the first node of this way, respecting or not its oneway state.
 BBox getBBox()
           
 java.lang.String getDisplayName(NameFormatter formatter)
          Replies the display name of a primitive formatted by formatter
 OsmPrimitiveType getDisplayType()
           
 double getLength()
          Replies the length of the way, in metres, as computed by LatLon.greatCircleDistance(org.openstreetmap.josm.data.coor.LatLon).
 java.util.Set<Node> getNeighbours(Node node)
          Return nodes adjacent to node
 Node getNode(int index)
          Replies the node at position index.
 long getNodeId(int idx)
           
 java.util.List<Pair<Node,Node>> getNodePairs(boolean sort)
          Replies the ordered List of chunks of this way.
 java.util.List<Node> getNodes()
          You can modify returned list but changes will not be propagated back to the Way.
 int getNodesCount()
          Replies the number of nodes in this ways.
 OsmPrimitiveType getType()
          Gets the type of object represented by this object.
 boolean hasEqualSemanticAttributes(OsmPrimitive other)
          Replies true if this primitive and other are equal with respect to their semantic attributes.
 boolean hasIncompleteNodes()
          Replies true if this way has incomplete nodes, false otherwise.
 boolean isClosed()
           
 boolean isDrawable()
           
 boolean isFirstLastNode(Node n)
          Replies true if the given node is the first or the last one of this way, false otherwise.
 boolean isInnerNode(Node n)
          Replies true if the given node is an inner node of this way, false otherwise.
 int isOneway()
          Tests if this way is a oneway.
 boolean isUsable()
          Replies true, if the object is usable (i.e.
 Node lastNode()
          Returns the last node of this way.
 Node lastNode(boolean respectOneway)
          Replies the last node of this way, respecting or not its oneway state.
 void load(PrimitiveData data)
          Loads (clone) this primitive from provided PrimitiveData
private  java.util.List<Node> removeDouble(java.util.List<Node> nodes)
          Prevent directly following identical nodes in ways.
 void removeNode(Node n)
          Removes the given Node from this way.
 void removeNodes(java.util.Set<? extends Node> selection)
          Removes the given set of nodes from this way.
 WayData save()
          Save parameters of this primitive to the transport object
 void setDataset(DataSet dataSet)
          This method should never ever by called from somewhere else than Dataset.addPrimitive or removePrimitive methods
 void setDeleted(boolean deleted)
          Sets whether this primitive is deleted or not.
 void setNodes(java.util.List<Node> nodes)
          Set new list of nodes to way.
 java.lang.String toString()
           
 void updatePosition()
          Called by Dataset to update cached position information of primitive (bbox, cached EarthNorth, ...)
 void visit(PrimitiveVisitor visitor)
           
 void visit(Visitor visitor)
           
 
Methods inherited from class org.openstreetmap.josm.data.osm.OsmPrimitive
addReferrer, checkDataset, clearCachedStyle, clearOsmId, equals, evaluateCondition, getDataSet, getDisabledType, getFilteredList, getFilteredSet, getFlagsAsString, getHiddenType, getParentRelations, getReferrer, getReferrers, getReferrers, getTemplateKeys, getTemplateValue, getUninterestingKeys, hasDirectionKeys, hasEqualTechnicalAttributes, hashCode, isDisabled, isDisabledAndHidden, isHighlighted, isMemberOfSelected, isReferredByWays, isSelectable, isSelected, isTagged, isUninterestingKey, keysChangedImpl, mergeFrom, put, remove, removeAll, removeReferrer, reversedDirection, saveCommonAttributes, setChangesetId, setDisabledState, setDisabledType, setHiddenType, setHighlighted, setIncomplete, setKeys, setOsmId, setTimestamp, setUser, setVisible, unsetDisabledState, updateFlags, visitReferrers, writeLock, writeUnlock
 
Methods inherited from class org.openstreetmap.josm.data.osm.AbstractPrimitive
cloneFrom, generateUniqueId, get, getChangesetId, getId, getIgnoreCase, getKeys, getLocalName, getName, getPrimitiveId, getTimestamp, getUniqueId, getUser, getVersion, hasKey, hasKeys, hasSameTags, hasTag, hasTag, isDeleted, isIncomplete, isModified, isNew, isNewOrUndeleted, isTimestampEmpty, isUndeleted, isVisible, keySet, setModified
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.openstreetmap.josm.data.osm.IPrimitive
getChangesetId, getId, getLocalName, getName, getPrimitiveId, getTimestamp, getUser, getVersion, isDeleted, isIncomplete, isModified, isNewOrUndeleted, isTimestampEmpty, isVisible, setChangesetId, setModified, setOsmId, setTimestamp, setUser, setVisible
 
Methods inherited from interface org.openstreetmap.josm.data.osm.Tagged
get, getKeys, hasKeys, keySet, put, remove, removeAll, setKeys
 
Methods inherited from interface org.openstreetmap.josm.data.osm.PrimitiveId
getUniqueId, isNew
 

Field Detail

nodes

private Node[] nodes
All way nodes in this way


bbox

private BBox bbox
Constructor Detail

Way

protected Way(long id,
              boolean allowNegative)

Way

public Way()
Contructs a new Way with id 0.

Since:
86

Way

public Way(Way original,
           boolean clearId)
Contructs a new Way from an existing Way.

Parameters:
original - The original Way to be identically cloned. Must not be null
clearId - If true, clears the OSM id as defined by OsmPrimitive.clearOsmId(). If false, does nothing
Since:
2410

Way

public Way(Way original)
Contructs a new Way from an existing Way (including its id).

Parameters:
original - The original Way to be identically cloned. Must not be null
Since:
86

Way

public Way(long id)
    throws java.lang.IllegalArgumentException
Contructs a new Way for the given id. If the id > 0, the way is marked as incomplete. If id == 0 then way is marked as new

Parameters:
id - the id. >= 0 required
Throws:
java.lang.IllegalArgumentException - if id < 0
Since:
343

Way

public Way(long id,
           int version)
    throws java.lang.IllegalArgumentException
Contructs a new Way with given id and version.

Parameters:
id - the id. >= 0 required
version - the version
Throws:
java.lang.IllegalArgumentException - if id < 0
Since:
2620
Method Detail

getNodes

public java.util.List<Node> getNodes()
You can modify returned list but changes will not be propagated back to the Way. Use setNodes(List) to update this way

Returns:
Nodes composing the way
Since:
1862

setNodes

public void setNodes(java.util.List<Node> nodes)
Set new list of nodes to way. This method is preferred to multiple calls to addNode/removeNode and similar methods because nodes are internally saved as array which means lower memory overhead but also slower modifying operations.

Parameters:
nodes - New way nodes. Can be null, in that case all way nodes are removed
Since:
1862

removeDouble

private java.util.List<Node> removeDouble(java.util.List<Node> nodes)
Prevent directly following identical nodes in ways.


getNodesCount

public int getNodesCount()
Replies the number of nodes in this ways.

Specified by:
getNodesCount in interface IWay
Returns:
the number of nodes in this ways.
Since:
1862

getNode

public Node getNode(int index)
Replies the node at position index.

Parameters:
index - the position
Returns:
the node at position index
Throws:
java.lang.IndexOutOfBoundsException - thrown if index < 0 or index >= getNodesCount()
Since:
1862

getNodeId

public long getNodeId(int idx)
Specified by:
getNodeId in interface IWay

containsNode

public boolean containsNode(Node node)
Replies true if this way contains the node node, false otherwise. Replies false if node is null.

Parameters:
node - the node. May be null.
Returns:
true if this way contains the node node, false otherwise
Since:
1911

getNeighbours

public java.util.Set<Node> getNeighbours(Node node)
Return nodes adjacent to node

Parameters:
node - the node. May be null.
Returns:
Set of nodes adjacent to node
Since:
4671

getNodePairs

public java.util.List<Pair<Node,Node>> getNodePairs(boolean sort)
Replies the ordered List of chunks of this way. Each chunk is replied as a Pair of nodes.

Parameters:
sort - If true, the nodes of each pair are sorted as defined by Pair.sort(org.openstreetmap.josm.tools.Pair). If false, Pair.a and Pair.b are in the way order (i.e for a given Pair(n), Pair(n-1).b == Pair(n).a, Pair(n).b == Pair(n+1).a, etc.)
Returns:
The ordered list of chunks of this way.
Since:
3348

visit

public void visit(Visitor visitor)
Specified by:
visit in class OsmPrimitive

visit

public void visit(PrimitiveVisitor visitor)
Specified by:
visit in interface IPrimitive

load

public void load(PrimitiveData data)
Description copied from class: OsmPrimitive
Loads (clone) this primitive from provided PrimitiveData

Overrides:
load in class OsmPrimitive

save

public WayData save()
Description copied from class: OsmPrimitive
Save parameters of this primitive to the transport object

Specified by:
save in class OsmPrimitive
Returns:

cloneFrom

public void cloneFrom(OsmPrimitive osm)
Description copied from class: OsmPrimitive
Get and write all attributes from the parameter. Does not fire any listener, so use this only in the data initializing phase

Overrides:
cloneFrom in class OsmPrimitive

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hasEqualSemanticAttributes

public boolean hasEqualSemanticAttributes(OsmPrimitive other)
Description copied from class: OsmPrimitive
Replies true if this primitive and other are equal with respect to their semantic attributes.
  1. equal id
  • both are complete or both are incomplete
  • both have the same tags
  • Overrides:
    hasEqualSemanticAttributes in class OsmPrimitive
    Returns:
    true if this primitive and other are equal with respect to their semantic attributes.

    compareTo

    public int compareTo(OsmPrimitive o)
    Specified by:
    compareTo in interface java.lang.Comparable<OsmPrimitive>

    removeNode

    public void removeNode(Node n)
    Removes the given Node from this way. Ignored, if n is null.

    Parameters:
    n - The node to remove. Ignored, if null
    Since:
    1463

    removeNodes

    public void removeNodes(java.util.Set<? extends Node> selection)
    Removes the given set of nodes from this way. Ignored, if selection is null.

    Parameters:
    selection - The selection of nodes to remove. Ignored, if null
    Since:
    5408

    addNode

    public void addNode(Node n)
                 throws java.lang.IllegalStateException
    Adds a node to the end of the list of nodes. Ignored, if n is null.

    Parameters:
    n - the node. Ignored, if null
    Throws:
    java.lang.IllegalStateException - thrown, if this way is marked as incomplete. We can't add a node to an incomplete way
    Since:
    1313

    addNode

    public void addNode(int offs,
                        Node n)
                 throws java.lang.IllegalStateException,
                        java.lang.IndexOutOfBoundsException
    Adds a node at position offs.

    Parameters:
    offs - the offset
    n - the node. Ignored, if null.
    Throws:
    java.lang.IllegalStateException - thrown, if this way is marked as incomplete. We can't add a node to an incomplete way
    java.lang.IndexOutOfBoundsException - thrown if offs is out of bounds
    Since:
    1313

    setDeleted

    public void setDeleted(boolean deleted)
    Description copied from class: AbstractPrimitive
    Sets whether this primitive is deleted or not. Also marks this primitive as modified if deleted is true.

    Specified by:
    setDeleted in interface IPrimitive
    Overrides:
    setDeleted in class OsmPrimitive
    Parameters:
    deleted - true, if this primitive is deleted; false, otherwise

    isClosed

    public boolean isClosed()
    Specified by:
    isClosed in interface IWay

    lastNode

    public Node lastNode()
    Returns the last node of this way. The result equals getNode(getNodesCount - 1).

    Returns:
    the last node of this way
    Since:
    1400

    firstNode

    public Node firstNode()
    Returns the first node of this way. The result equals getNode(0).

    Returns:
    the first node of this way
    Since:
    1400

    isFirstLastNode

    public boolean isFirstLastNode(Node n)
    Replies true if the given node is the first or the last one of this way, false otherwise.

    Parameters:
    n - The node to test
    Returns:
    true if the n is the first or the last node, false otherwise.
    Since:
    1400

    isInnerNode

    public boolean isInnerNode(Node n)
    Replies true if the given node is an inner node of this way, false otherwise.

    Parameters:
    n - The node to test
    Returns:
    true if the n is an inner node, false otherwise.
    Since:
    3515

    getDisplayName

    public java.lang.String getDisplayName(NameFormatter formatter)
    Description copied from class: OsmPrimitive
    Replies the display name of a primitive formatted by formatter

    Specified by:
    getDisplayName in class OsmPrimitive
    Returns:
    the display name

    getType

    public OsmPrimitiveType getType()
    Description copied from interface: PrimitiveId
    Gets the type of object represented by this object.

    Specified by:
    getType in interface PrimitiveId
    Returns:
    the object type
    See Also:
    Node, Way, Relation

    getDisplayType

    public OsmPrimitiveType getDisplayType()
    Overrides:
    getDisplayType in class AbstractPrimitive

    checkNodes

    private void checkNodes()

    fireNodesChanged

    private void fireNodesChanged()

    setDataset

    public void setDataset(DataSet dataSet)
    Description copied from class: OsmPrimitive
    This method should never ever by called from somewhere else than Dataset.addPrimitive or removePrimitive methods

    Overrides:
    setDataset in class OsmPrimitive

    getBBox

    public BBox getBBox()
    Specified by:
    getBBox in class OsmPrimitive

    updatePosition

    public void updatePosition()
    Description copied from class: OsmPrimitive
    Called by Dataset to update cached position information of primitive (bbox, cached EarthNorth, ...)

    Specified by:
    updatePosition in class OsmPrimitive

    hasIncompleteNodes

    public boolean hasIncompleteNodes()
    Replies true if this way has incomplete nodes, false otherwise.

    Returns:
    true if this way has incomplete nodes, false otherwise.
    Since:
    2587

    isUsable

    public boolean isUsable()
    Description copied from class: AbstractPrimitive
    Replies true, if the object is usable (i.e. complete and not deleted).

    Overrides:
    isUsable in class AbstractPrimitive
    Returns:
    true, if the object is usable.
    See Also:
    AbstractPrimitive.setDeleted(boolean)

    isDrawable

    public boolean isDrawable()
    Overrides:
    isDrawable in class OsmPrimitive

    getLength

    public double getLength()
    Replies the length of the way, in metres, as computed by LatLon.greatCircleDistance(org.openstreetmap.josm.data.coor.LatLon).

    Returns:
    The length of the way, in metres
    Since:
    4138

    isOneway

    public int isOneway()
    Tests if this way is a oneway.

    Returns:
    1 if the way is a oneway, -1 if the way is a reversed oneway, 0 otherwise.
    Since:
    5199

    firstNode

    public Node firstNode(boolean respectOneway)
    Replies the first node of this way, respecting or not its oneway state.

    Parameters:
    respectOneway - If true and if this way is a oneway, replies the last node. Otherwise, replies the first node.
    Returns:
    the first node of this way, according to respectOneway and its oneway state.
    Since:
    5199

    lastNode

    public Node lastNode(boolean respectOneway)
    Replies the last node of this way, respecting or not its oneway state.

    Parameters:
    respectOneway - If true and if this way is a oneway, replies the first node. Otherwise, replies the last node.
    Returns:
    the last node of this way, according to respectOneway and its oneway state.
    Since:
    5199


    JOSM