Changeset 10910 in josm


Ignore:
Timestamp:
2016-08-28T19:00:16+02:00 (8 years ago)
Author:
Don-vip
Message:

improve javadoc, unit tests, reduce visibility of some public fields

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/DownloadOsmInViewAction.java

    r10848 r10910  
    4444
    4545    private static class DownloadOsmInViewTask extends DownloadOsmTask {
    46         public Future<?> download(Bounds downloadArea) {
     46        Future<?> download(Bounds downloadArea) {
    4747            return download(new DownloadTask(false, new BoundingBoxDownloader(downloadArea), null, false), downloadArea);
    4848        }
  • trunk/src/org/openstreetmap/josm/data/Bounds.java

    r10806 r10910  
    8989    }
    9090
     91    /**
     92     * Constructs bounds out of two points.
     93     * @param min min lat/lon
     94     * @param max max lat/lon
     95     * @param roundToOsmPrecision defines if lat/lon will be rounded
     96     */
    9197    public Bounds(LatLon min, LatLon max, boolean roundToOsmPrecision) {
    9298        this(min.lat(), min.lon(), max.lat(), max.lon(), roundToOsmPrecision);
     
    94100
    95101    /**
    96      * Constructs bounds out a single point.
     102     * Constructs bounds out a single point. Coords will be rounded.
    97103     * @param b lat/lon
    98104     */
     
    134140    }
    135141
     142    /**
     143     * Constructs bounds out of two points. Coords will be rounded.
     144     * @param minlat min lat
     145     * @param minlon min lon
     146     * @param maxlat max lat
     147     * @param maxlon max lon
     148     */
    136149    public Bounds(double minlat, double minlon, double maxlat, double maxlon) {
    137150        this(minlat, minlon, maxlat, maxlon, true);
    138151    }
    139152
     153    /**
     154     * Constructs bounds out of two points.
     155     * @param minlat min lat
     156     * @param minlon min lon
     157     * @param maxlat max lat
     158     * @param maxlon max lon
     159     * @param roundToOsmPrecision defines if lat/lon will be rounded
     160     */
    140161    public Bounds(double minlat, double minlon, double maxlat, double maxlon, boolean roundToOsmPrecision) {
    141162        if (roundToOsmPrecision) {
     
    152173    }
    153174
     175    /**
     176     * Constructs bounds out of two points. Coords will be rounded.
     177     * @param coords exactly 4 values: min lat, min lon, max lat, max lon
     178     * @throws IllegalArgumentException if coords does not contain 4 double values
     179     */
    154180    public Bounds(double ... coords) {
    155181        this(coords, true);
    156182    }
    157183
     184    /**
     185     * Constructs bounds out of two points.
     186     * @param coords exactly 4 values: min lat, min lon, max lat, max lon
     187     * @param roundToOsmPrecision defines if lat/lon will be rounded
     188     * @throws IllegalArgumentException if coords does not contain 4 double values
     189     */
    158190    public Bounds(double[] coords, boolean roundToOsmPrecision) {
    159191        CheckParameterUtil.ensureParameterNotNull(coords, "coords");
     
    232264    }
    233265
     266    /**
     267     * Creates new {@code Bounds} from a rectangle.
     268     * @param rect The rectangle
     269     */
    234270    public Bounds(Rectangle2D rect) {
    235271        this(rect.getMinY(), rect.getMinX(), rect.getMaxY(), rect.getMaxX());
  • trunk/src/org/openstreetmap/josm/gui/MapViewState.java

    r10875 r10910  
    264264    }
    265265
     266    /**
     267     * Returns the area for the given bounds.
     268     * @param bounds bounds
     269     * @return the area for the given bounds
     270     */
    266271    public Area getArea(Bounds bounds) {
    267272        Path2D area = new Path2D.Double();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r10861 r10910  
    388388    /**
    389389     * The list model for the list of relations displayed in the relation list dialog.
    390      *
    391390     */
    392391    private class RelationListModel extends AbstractListModel<Relation> {
     
    400399        }
    401400
     401        /**
     402         * Clears the model.
     403         */
    402404        public void clear() {
    403405            relations.clear();
     
    407409        }
    408410
     411        /**
     412         * Sorts the model using {@link DefaultNameFormatter} relation comparator.
     413         */
    409414        public void sort() {
    410415            relations.sort(DefaultNameFormatter.getInstance().getRelationComparator());
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java

    r10837 r10910  
    332332        final Pattern pattern;
    333333
     334        /**
     335         * Constructs a new {@code KeyValueRegexpCondition}.
     336         * @param k key
     337         * @param v value
     338         * @param op operation
     339         * @param considerValAsKey must be false
     340         */
    334341        public KeyValueRegexpCondition(String k, String v, Op op, boolean considerValAsKey) {
    335342            super(k, v, op, considerValAsKey);
     
    361368    public static class RegexpKeyValueRegexpCondition extends KeyValueRegexpCondition {
    362369
    363         public final Pattern keyPattern;
     370        final Pattern keyPattern;
    364371
    365372        /**
     
    386393
    387394    public static class RoleCondition implements Condition {
    388         public final String role;
    389         public final Op op;
    390 
     395        final String role;
     396        final Op op;
     397
     398        /**
     399         * Constructs a new {@code RoleCondition}.
     400         * @param role role
     401         * @param op operation
     402         */
    391403        public RoleCondition(String role, Op op) {
    392404            this.role = role;
     
    403415
    404416    public static class IndexCondition implements Condition {
    405         public final String index;
    406         public final Op op;
    407 
     417        final String index;
     418        final Op op;
     419
     420        /**
     421         * Constructs a new {@code IndexCondition}.
     422         * @param index index
     423         * @param op operation
     424         */
    408425        public IndexCondition(String index, Op op) {
    409426            this.index = index;
     
    548565
    549566        public final String id;
    550         public final boolean not;
     567        final boolean not;
    551568
    552569        public ClassCondition(String id, boolean not) {
     
    740757    public static class PseudoClassCondition implements Condition {
    741758
    742         public final Method method;
    743         public final boolean not;
     759        final Method method;
     760        final boolean not;
    744761
    745762        protected PseudoClassCondition(Method method, boolean not) {
     
    810827    public static class ExpressionCondition implements Condition {
    811828
    812         private final Expression e;
     829        final Expression e;
    813830
    814831        /**
  • trunk/test/unit/org/openstreetmap/josm/data/BoundsTest.java

    r10758 r10910  
    55import static org.junit.Assert.assertFalse;
    66import static org.junit.Assert.assertTrue;
     7
     8import java.awt.geom.Rectangle2D;
    79
    810import org.junit.Test;
     
    4749        assertEquals(b3, new Bounds(0, 0, 90, -170));
    4850    }
     51
     52    private static void doTestConstructorNominal(Bounds b) {
     53        double eps = 1e-7;
     54        assertEquals(1d, b.getMinLat(), eps);
     55        assertEquals(2d, b.getMinLon(), eps);
     56        assertEquals(3d, b.getMaxLat(), eps);
     57        assertEquals(4d, b.getMaxLon(), eps);
     58    }
     59
     60    private static void doTestConstructorPoint(Bounds b) {
     61        double eps = 1e-7;
     62        assertEquals(1d, b.getMinLat(), eps);
     63        assertEquals(2d, b.getMinLon(), eps);
     64        assertEquals(1d, b.getMaxLat(), eps);
     65        assertEquals(2d, b.getMaxLon(), eps);
     66    }
     67
     68    /**
     69     * Unit tests for {@link Bounds#Bounds} - nominal cases.
     70     */
     71    @Test
     72    public void testConstructorNominalCases() {
     73        doTestConstructorNominal(new Bounds(new LatLon(1d, 2d), new LatLon(3d, 4d)));
     74        doTestConstructorNominal(new Bounds(new LatLon(1d, 2d), new LatLon(3d, 4d), true));
     75        doTestConstructorNominal(new Bounds(1d, 2d, 3d, 4d));
     76        doTestConstructorNominal(new Bounds(1d, 2d, 3d, 4d, true));
     77        doTestConstructorNominal(new Bounds(new double[]{1d, 2d, 3d, 4d}));
     78        doTestConstructorNominal(new Bounds(new double[]{1d, 2d, 3d, 4d}, true));
     79        doTestConstructorNominal(new Bounds(new Bounds(1d, 2d, 3d, 4d)));
     80        doTestConstructorNominal(new Bounds(new Rectangle2D.Double(2d, 1d, 2d, 2d)));
     81    }
     82
     83    /**
     84     * Unit tests for {@link Bounds#Bounds} - single point cases.
     85     */
     86    @Test
     87    public void testConstructorSinglePointCases() {
     88        doTestConstructorPoint(new Bounds(new LatLon(1d, 2d)));
     89        doTestConstructorPoint(new Bounds(new LatLon(1d, 2d), true));
     90        doTestConstructorPoint(new Bounds(1d, 2d, true));
     91    }
    4992}
Note: See TracChangeset for help on using the changeset viewer.