Changeset 9854 in josm


Ignore:
Timestamp:
2016-02-23T02:11:42+01:00 (9 years ago)
Author:
Don-vip
Message:

sonar - squid:S2272 - "Iterator.next()" methods should throw "NoSuchElementException" + javadoc/code style

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r9073 r9854  
    1111import java.util.List;
    1212import java.util.Map;
     13import java.util.NoSuchElementException;
    1314import java.util.Set;
    1415
     
    3233    public boolean fromServer;
    3334
     35    /** Creator (usually software) */
    3436    public String creator;
    3537
     38    /** Tracks */
    3639    public final Collection<GpxTrack> tracks = new LinkedList<>();
     40    /** Routes */
    3741    public final Collection<GpxRoute> routes = new LinkedList<>();
     42    /** Waypoints */
    3843    public final Collection<WayPoint> waypoints = new LinkedList<>();
    3944
     
    4651    public final Set<DataSource> dataSources = new HashSet<>();
    4752
     53    /**
     54     * Merges data from another object.
     55     * @param other existing GPX data
     56     */
    4857    public void mergeFrom(GpxData other) {
    4958        if (storageFile == null && other.storageFile != null) {
     
    361370    }
    362371
     372    /**
     373     * Resets the internal caches of east/north coordinates.
     374     */
    363375    public void resetEastNorthCache() {
    364376        if (waypoints != null) {
     
    401413        private final boolean[] trackVisibility;
    402414
     415        /**
     416         * Constructs a new {@code LinesIterator}.
     417         * @param data GPX data
     418         * @param trackVisibility An array indicating which tracks should be
     419         * included in the iteration. Can be null, then all tracks are included.
     420         */
    403421        public LinesIterator(GpxData data, boolean[] trackVisibility) {
    404422            itTracks = data.tracks.iterator();
     
    416434        @Override
    417435        public Collection<WayPoint> next() {
     436            if (!hasNext()) {
     437                throw new NoSuchElementException();
     438            }
    418439            Collection<WayPoint> current = next;
    419440            next = getNext();
  • trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java

    r9243 r9854  
    77import java.util.Iterator;
    88import java.util.List;
     9import java.util.NoSuchElementException;
    910
    1011import org.openstreetmap.josm.Main;
     
    475476    }
    476477
     478    /**
     479     * Converts to list.
     480     * @return elements as list
     481     */
    477482    public List<T> toList() {
    478483        List<T> a = new ArrayList<>();
     
    498503        private int iteratedOver;
    499504
    500         final QBLevel<T> next_content_node(QBLevel<T> q) {
     505        final QBLevel<T> nextContentNode(QBLevel<T> q) {
    501506            if (q == null)
    502507                return null;
     
    514519                currentNode = qb.root;
    515520            } else {
    516                 currentNode = next_content_node(qb.root);
     521                currentNode = nextContentNode(qb.root);
    517522            }
    518523            iteratedOver = 0;
     
    531536            while ((currentNode.content == null) || (contentIndex >= currentNode.content.size())) {
    532537                contentIndex = 0;
    533                 currentNode = next_content_node(currentNode);
     538                currentNode = nextContentNode(currentNode);
    534539                if (currentNode == null) {
    535540                    break;
     
    544549        public T next() {
    545550            T ret = peek();
     551            if (ret == null)
     552                throw new NoSuchElementException();
    546553            contentIndex++;
    547554            iteratedOver++;
     
    576583    }
    577584
    578     public List<T> search(BBox search_bbox) {
     585    public List<T> search(BBox searchBbox) {
    579586        List<T> ret = new ArrayList<>();
    580587        // Doing this cuts down search cost on a real-life data set by about 25%
     
    583590        }
    584591        // Walk back up the tree when the last search spot can not cover the current search
    585         while (searchCache != null && !searchCache.bbox().bounds(search_bbox)) {
     592        while (searchCache != null && !searchCache.bbox().bounds(searchBbox)) {
    586593            searchCache = searchCache.parent;
    587594        }
     
    589596        if (searchCache == null) {
    590597            searchCache = root;
    591             Main.info("bbox: " + search_bbox + " is out of the world");
     598            Main.info("bbox: " + searchBbox + " is out of the world");
    592599        }
    593600
     
    595602        QBLevel<T> tmp = searchCache.parent;
    596603
    597         searchCache.search(search_bbox, ret);
     604        searchCache.search(searchBbox, ret);
    598605
    599606        // A way that spans this bucket may be stored in one
    600607        // of the nodes which is a parent of the search cache
    601608        while (tmp != null) {
    602             tmp.search_contents(search_bbox, ret);
     609            tmp.search_contents(searchBbox, ret);
    603610            tmp = tmp.parent;
    604611        }
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r9802 r9854  
    3333import java.util.List;
    3434import java.util.Map;
     35import java.util.NoSuchElementException;
    3536import java.util.concurrent.ForkJoinPool;
    3637import java.util.concurrent.ForkJoinTask;
     
    9495     *
    9596     * There is no intention, to handle consecutive duplicate Nodes in a
    96      * perfect way, but it is should not throw an exception.
     97     * perfect way, but it should not throw an exception.
    9798     */
    9899    private class OffsetIterator implements Iterator<Point> {
     
    122123        @Override
    123124        public Point next() {
    124             if (Math.abs(offset) < 0.1d) return nc.getPoint(nodes.get(idx++));
     125            if (!hasNext())
     126                throw new NoSuchElementException();
     127
     128            if (Math.abs(offset) < 0.1d)
     129                return nc.getPoint(nodes.get(idx++));
    125130
    126131            Point current = nc.getPoint(nodes.get(idx));
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r9603 r9854  
    2222import java.util.Map;
    2323import java.util.Map.Entry;
     24import java.util.NoSuchElementException;
    2425import java.util.Set;
    2526import java.util.concurrent.locks.ReadWriteLock;
     
    157158            @Override
    158159            public boolean hasNext() {
    159                 return next >= 0;
     160                return next >= 0 && next < rules.size();
    160161            }
    161162
    162163            @Override
    163164            public MapCSSRule next() {
     165                if (!hasNext())
     166                    throw new NoSuchElementException();
    164167                MapCSSRule rule = rules.get(next);
    165168                next = ruleCandidates.nextSetBit(next + 1);
  • trunk/src/org/openstreetmap/josm/gui/widgets/ComboBoxHistory.java

    r9484 r9854  
    55import java.util.Iterator;
    66import java.util.List;
     7import java.util.NoSuchElementException;
    78
    89import javax.swing.DefaultComboBoxModel;
     
    7980            @Override
    8081            public boolean hasNext() {
    81                 if (position < getSize()-1 && getSize() > 0)
    82                     return true;
    83                 return false;
     82                return position < getSize()-1 && getSize() > 0;
    8483            }
    8584
    8685            @Override
    8786            public AutoCompletionListItem next() {
     87                if (!hasNext())
     88                    throw new NoSuchElementException();
    8889                position++;
    8990                return getElementAt(position);
  • trunk/src/org/openstreetmap/josm/tools/SubclassFilteredCollection.java

    r8836 r9854  
    55import java.util.Collection;
    66import java.util.Iterator;
     7import java.util.NoSuchElementException;
    78
    89/**
     
    5152        @Override
    5253        public T next() {
    53             findNext();
     54            if (!hasNext())
     55                throw new NoSuchElementException();
    5456            S old = current;
    5557            current = null;
Note: See TracChangeset for help on using the changeset viewer.