Ignore:
Timestamp:
2012-08-08T22:37:36+02:00 (12 years ago)
Author:
Don-vip
Message:

see #7934 - Only throw DataIntegrityProblemException for *visible* complete nodes without coordinates + fix javadoc of Way

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r5266 r5408  
    1919
    2020/**
    21  * One full way, consisting of a list of way nodes.
     21 * One full way, consisting of a list of way {@link Node nodes}.
    2222 *
    2323 * @author imi
     24 * @since 64
    2425 */
    2526public final class Way extends OsmPrimitive implements IWay {
     
    128129     * @return true if this way contains the node <code>node</code>, false
    129130     * otherwise
    130      * @since 1909
     131     * @since 1911
    131132     */
    132133    public boolean containsNode(Node node) {
     
    146147     * @param node the node. May be null.
    147148     * @return Set of nodes adjacent to <code>node</code>
    148      * @since 4666
     149     * @since 4671
    149150     */
    150151    public Set<Node> getNeighbours(Node node) {
     
    165166    }
    166167
     168    /**
     169     * Replies the ordered {@link List} of chunks of this way. Each chunk is replied as a {@link Pair} of {@link Node nodes}.
     170     * @param sort If true, the nodes of each pair are sorted as defined by {@link Pair#sort}.
     171     *             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.)
     172     * @return The ordered list of chunks of this way.
     173     * @since 3348
     174     */
    167175    public List<Pair<Node,Node>> getNodePairs(boolean sort) {
    168176        List<Pair<Node,Node>> chunkSet = new ArrayList<Pair<Node,Node>>();
     
    198206
    199207    /**
    200      * Creates a new way with id 0.
    201      *
    202      */
    203     public Way(){
     208     * Contructs a new {@code Way} with id 0.
     209     * @since 86
     210     */
     211    public Way() {
    204212        super(0, false);
    205213    }
    206214
    207215    /**
    208      *
    209      * @param original
    210      * @param clearId
     216     * Contructs a new {@code Way} from an existing {@code Way}.
     217     * @param original The original {@code Way} to be identically cloned. Must not be null
     218     * @param clearId If true, clears the OSM id as defined by {@link #clearOsmId}. If false, does nothing
     219     * @since 2410
    211220     */
    212221    public Way(Way original, boolean clearId) {
     
    219228
    220229    /**
    221      * Create an identical clone of the argument (including the id).
    222      *
    223      * @param original  the original way. Must not be null.
     230     * Contructs a new {@code Way} from an existing {@code Way} (including its id).
     231     * @param original The original {@code Way} to be identically cloned. Must not be null
     232     * @since 86
    224233     */
    225234    public Way(Way original) {
     
    228237
    229238    /**
    230      * Creates a new way for the given id. If the id > 0, the way is marked
     239     * Contructs a new {@code Way} for the given id. If the id > 0, the way is marked
    231240     * as incomplete. If id == 0 then way is marked as new
    232241     *
    233242     * @param id the id. >= 0 required
    234      * @throws IllegalArgumentException thrown if id < 0
     243     * @throws IllegalArgumentException if id < 0
     244     * @since 343
    235245     */
    236246    public Way(long id) throws IllegalArgumentException {
     
    239249
    240250    /**
    241      * Creates new way with given id and version.
    242      * @param id
    243      * @param version
    244      */
    245     public Way(long id, int version) {
     251     * Contructs a new {@code Way} with given id and version.
     252     * @param id the id. >= 0 required
     253     * @param version the version
     254     * @throws IllegalArgumentException if id < 0
     255     * @since 2620
     256     */
     257    public Way(long id, int version) throws IllegalArgumentException {
    246258        super(id, version, false);
    247259    }
    248260
    249     /**
    250      *
    251      * @param data
    252      */
    253261    @Override
    254262    public void load(PrimitiveData data) {
     
    273281    }
    274282
    275     @Override public WayData save() {
     283    @Override
     284    public WayData save() {
    276285        WayData data = new WayData();
    277286        saveCommonAttributes(data);
     
    282291    }
    283292
    284     @Override public void cloneFrom(OsmPrimitive osm) {
     293    @Override
     294    public void cloneFrom(OsmPrimitive osm) {
    285295        boolean locked = writeLock();
    286296        try {
     
    293303    }
    294304
    295     @Override public String toString() {
     305    @Override
     306    public String toString() {
    296307        String nodesDesc = isIncomplete()?"(incomplete)":"nodes=" + Arrays.toString(nodes);
    297308        return "{Way id=" + getUniqueId() + " version=" + getVersion()+ " " + getFlagsAsString()  + " " + nodesDesc + "}";
     
    320331    }
    321332
     333    /**
     334     * Removes the given {@link Node} from this way. Ignored, if n is null.
     335     * @param n The node to remove. Ignored, if null
     336     * @since 1463
     337     */
    322338    public void removeNode(Node n) {
    323         if (isIncomplete()) return;
     339        if (n == null || isIncomplete()) return;
    324340        boolean locked = writeLock();
    325341        try {
     
    342358    }
    343359
    344     public void removeNodes(Set<? extends OsmPrimitive> selection) {
    345         if (isIncomplete()) return;
     360    /**
     361     * Removes the given set of {@link Node nodes} from this way. Ignored, if selection is null.
     362     * @param selection The selection of nodes to remove. Ignored, if null
     363     * @since 5408
     364     */
     365    public void removeNodes(Set<? extends Node> selection) {
     366        if (selection == null || isIncomplete()) return;
    346367        boolean locked = writeLock();
    347368        try {
     
    370391     * Adds a node to the end of the list of nodes. Ignored, if n is null.
    371392     *
    372      * @param n the node. Ignored, if null.
     393     * @param n the node. Ignored, if null
    373394     * @throws IllegalStateException thrown, if this way is marked as incomplete. We can't add a node
    374395     * to an incomplete way
     396     * @since 1313
    375397     */
    376398    public void addNode(Node n) throws IllegalStateException {
     
    396418     * Adds a node at position offs.
    397419     *
    398      * @param int offs the offset
     420     * @param offs the offset
    399421     * @param n the node. Ignored, if null.
    400422     * @throws IllegalStateException thrown, if this way is marked as incomplete. We can't add a node
    401423     * to an incomplete way
    402424     * @throws IndexOutOfBoundsException thrown if offs is out of bounds
     425     * @since 1313
    403426     */
    404427    public void addNode(int offs, Node n) throws IllegalStateException, IndexOutOfBoundsException {
     
    453476     * The result equals <tt>{@link #getNode getNode}({@link #getNodesCount getNodesCount} - 1)</tt>.
    454477     * @return the last node of this way
     478     * @since 1400
    455479     */
    456480    public Node lastNode() {
     
    464488     * The result equals {@link #getNode getNode}{@code (0)}.
    465489     * @return the first node of this way
     490     * @since 1400
    466491     */
    467492    public Node firstNode() {
     
    471496    }
    472497
     498    /**
     499     * Replies true if the given node is the first or the last one of this way, false otherwise.
     500     * @param n The node to test
     501     * @return true if the {@code n} is the first or the last node, false otherwise.
     502     * @since 1400
     503     */
    473504    public boolean isFirstLastNode(Node n) {
    474505        Node[] nodes = this.nodes;
     
    477508    }
    478509
     510    /**
     511     * Replies true if the given node is an inner node of this way, false otherwise.
     512     * @param n The node to test
     513     * @return true if the {@code n} is an inner node, false otherwise.
     514     * @since 3515
     515     */
    479516    public boolean isInnerNode(Node n) {
    480517        Node[] nodes = this.nodes;
     
    482519        /* circular ways have only inner nodes, so return true for them! */
    483520        if (n == nodes[0] && n == nodes[nodes.length-1]) return true;
    484         for(int i = 1; i < nodes.length - 1; ++i) {
    485             if(nodes[i] == n) return true;
     521        for (int i = 1; i < nodes.length - 1; ++i) {
     522            if (nodes[i] == n) return true;
    486523        }
    487524        return false;
    488525    }
    489526
    490 
     527    @Override
    491528    public String getDisplayName(NameFormatter formatter) {
    492529        return formatter.format(this);
     
    517554            if (Main.pref.getBoolean("debug.checkNullCoor", true)) {
    518555                for (Node n: nodes) {
    519                     if (!n.isIncomplete() && (n.getCoor() == null || n.getEastNorth() == null))
    520                         throw new DataIntegrityProblemException("Complete node with null coordinates: " + toString() + n.get3892DebugInfo(),
     556                    if (n.isVisible() && !n.isIncomplete() && (n.getCoor() == null || n.getEastNorth() == null))
     557                        throw new DataIntegrityProblemException("Complete visible node with null coordinates: " + toString() + n.get3892DebugInfo(),
    521558                                "<html>" + tr("Complete node {0} with null coordinates in way {1}",
    522559                                DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(n),
     
    555592    }
    556593
     594    /**
     595     * Replies true if this way has incomplete nodes, false otherwise.
     596     * @return true if this way has incomplete nodes, false otherwise.
     597     * @since 2587
     598     */
    557599    public boolean hasIncompleteNodes() {
    558600        Node[] nodes = this.nodes;
    559         for (Node node:nodes) {
     601        for (Node node : nodes) {
    560602            if (node.isIncomplete())
    561603                return true;
     
    574616    }
    575617
    576 
    577     /* since revision 4138 */
     618    /**
     619     * Replies the length of the way, in metres, as computed by {@link LatLon#greatCircleDistance}.
     620     * @return The length of the way, in metres
     621     * @since 4138
     622     */
    578623    public double getLength() {
    579624        double length = 0;
     
    594639    /**
    595640     * Tests if this way is a oneway.
    596      * @return {@code 1} if the way is a oneway, {@code -1} if the way is a reversed oneway,
    597      * {@code 0} otherwise.
     641     * @return {@code 1} if the way is a oneway,
     642     *         {@code -1} if the way is a reversed oneway,
     643     *         {@code 0} otherwise.
     644     * @since 5199
    598645     */
    599646    public int isOneway() {
     
    612659    }
    613660
     661    /**
     662     * Replies the first node of this way, respecting or not its oneway state.
     663     * @param respectOneway If true and if this way is a oneway, replies the last node. Otherwise, replies the first node.
     664     * @return the first node of this way, according to {@code respectOneway} and its oneway state.
     665     * @since 5199
     666     */
    614667    public Node firstNode(boolean respectOneway) {
    615668        return !respectOneway || isOneway() != -1 ? firstNode() : lastNode();
    616669    }
    617670
     671    /**
     672     * Replies the last node of this way, respecting or not its oneway state.
     673     * @param respectOneway If true and if this way is a oneway, replies the first node. Otherwise, replies the last node.
     674     * @return the last node of this way, according to {@code respectOneway} and its oneway state.
     675     * @since 5199
     676     */
    618677    public Node lastNode(boolean respectOneway) {
    619678        return !respectOneway || isOneway() != -1 ? lastNode() : firstNode();
Note: See TracChangeset for help on using the changeset viewer.