Changeset 7392 in josm for trunk/src


Ignore:
Timestamp:
2014-08-14T11:27:38+02:00 (5 years ago)
Author:
Don-vip
Message:

code cleanup, javadoc update

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited
1 moved

Legend:

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

    r7012 r7392  
    2727import org.openstreetmap.josm.command.Command;
    2828import org.openstreetmap.josm.command.SequenceCommand;
    29 import org.openstreetmap.josm.data.osm.MultipolygonCreate;
    30 import org.openstreetmap.josm.data.osm.MultipolygonCreate.JoinedPolygon;
     29import org.openstreetmap.josm.data.osm.MultipolygonBuilder;
     30import org.openstreetmap.josm.data.osm.MultipolygonBuilder.JoinedPolygon;
    3131import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3232import org.openstreetmap.josm.data.osm.Relation;
     
    191191        ways.addAll(selectedMultipolygonRelation.getMemberPrimitives(Way.class));
    192192
    193         final MultipolygonCreate polygon = analyzeWays(ways, true);
     193        final MultipolygonBuilder polygon = analyzeWays(ways, true);
    194194        if (polygon == null) {
    195195            return null; //could not make multipolygon.
     
    204204    public static Pair<Relation, Relation> createMultipolygonRelation(Collection<Way> selectedWays, boolean showNotif) {
    205205
    206         final MultipolygonCreate polygon = analyzeWays(selectedWays, showNotif);
     206        final MultipolygonBuilder polygon = analyzeWays(selectedWays, showNotif);
    207207        if (polygon == null) {
    208208            return null; //could not make multipolygon.
     
    265265     * @return <code>null</code>, if there was a problem with the ways.
    266266     */
    267     private static MultipolygonCreate analyzeWays(Collection < Way > selectedWays, boolean showNotif) {
    268 
    269         MultipolygonCreate pol = new MultipolygonCreate();
     267    private static MultipolygonBuilder analyzeWays(Collection < Way > selectedWays, boolean showNotif) {
     268
     269        MultipolygonBuilder pol = new MultipolygonBuilder();
    270270        String error = pol.makeFromWays(selectedWays);
    271271
     
    287287     * @return multipolygon relation
    288288     */
    289     private static Relation createRelation(MultipolygonCreate pol, final Relation rel) {
     289    private static Relation createRelation(MultipolygonBuilder pol, final Relation rel) {
    290290        // Create new relation
    291291        rel.put("type", "multipolygon");
  • trunk/src/org/openstreetmap/josm/data/osm/MultipolygonBuilder.java

    r7391 r7392  
    1616import org.openstreetmap.josm.tools.MultiMap;
    1717
    18 public class MultipolygonCreate {
     18/**
     19 * Helper class to build multipolygons from multiple ways.
     20 * @author viesturs
     21 * @since 7392 (rename)
     22 * @since 3704
     23 */
     24public class MultipolygonBuilder {
    1925
    2026    /**
    2127     * Represents one polygon that consists of multiple ways.
    22      * @author Viesturs
    23      *
    2428     */
    2529    public static class JoinedPolygon {
     
    2933        public final Area area;
    3034
     35        /**
     36         * Constructs a new {@code JoinedPolygon} from given list of ways.
     37         * @param ways The ways used to build joined polygon
     38         */
    3139        public JoinedPolygon(List<Way> ways, List<Boolean> reversed) {
    3240            this.ways = ways;
     
    5563                boolean reversed = this.reversed.get(waypos).booleanValue();
    5664
    57                 if (!reversed){
     65                if (!reversed) {
    5866                    for (int pos = 0; pos < way.getNodesCount() - 1; pos++) {
    5967                        nodes.add(way.getNode(pos));
     
    7179    }
    7280
    73 
    7481    /**
    7582     * Helper storage class for finding findOuterWays
    76      * @author viesturs
    7783     */
    7884    static class PolygonLevel {
     
    8995    }
    9096
    91     public List<JoinedPolygon> outerWays;
    92     public List<JoinedPolygon> innerWays;
    93 
    94     public MultipolygonCreate(List<JoinedPolygon> outerWays, List<JoinedPolygon> innerWays){
     97    /** List of outer ways **/
     98    public final List<JoinedPolygon> outerWays;
     99    /** List of inner ways **/
     100    public final List<JoinedPolygon> innerWays;
     101
     102    /**
     103     * Constructs a new {@code MultipolygonBuilder} initialized with given ways.
     104     * @param outerWays The outer ways
     105     * @param innerWays The inner ways
     106     */
     107    public MultipolygonBuilder(List<JoinedPolygon> outerWays, List<JoinedPolygon> innerWays) {
    95108        this.outerWays = outerWays;
    96109        this.innerWays = innerWays;
    97110    }
    98111
    99     public MultipolygonCreate(){
     112    /**
     113     * Constructs a new empty {@code MultipolygonBuilder}.
     114     */
     115    public MultipolygonBuilder() {
    100116        this.outerWays = new ArrayList<>(0);
    101117        this.innerWays = new ArrayList<>(0);
     
    122138     */
    123139    public static class JoinedPolygonCreationException extends RuntimeException {
     140        /**
     141         * Constructs a new {@code JoinedPolygonCreationException}.
     142         * @param message the detail message. The detail message is saved for
     143         *                later retrieval by the {@link #getMessage()} method
     144         */
    124145        public JoinedPolygonCreationException(String message) {
    125146            super(message);
     
    159180        //process unclosed ways
    160181        for (Way startWay: ways) {
    161             if (usedWays.contains(startWay)){
     182            if (usedWays.contains(startWay)) {
    162183                continue;
    163184            }
     
    191212
    192213                Way nextWay = null;
    193                 for(Way way: adjacentWays){
    194                     if (way != curWay){
     214                for(Way way: adjacentWays) {
     215                    if (way != curWay) {
    195216                        nextWay = way;
    196217                    }
     
    217238        List<PolygonLevel> list = findOuterWaysRecursive(0, polygons);
    218239
    219         if (list == null){
     240        if (list == null) {
    220241            return tr("There is an intersection between ways.");
    221242        }
    222243
    223         this.outerWays = new ArrayList<>(0);
    224         this.innerWays = new ArrayList<>(0);
     244        this.outerWays.clear();
     245        this.innerWays.clear();
    225246
    226247        //take every other level
     
    265286                    innerCandidates.add(innerWay);
    266287                }
    267                 else if (intersection == PolygonIntersection.CROSSING)
    268                 {
     288                else if (intersection == PolygonIntersection.CROSSING) {
    269289                    //ways intersect
    270290                    return null;
  • trunk/src/org/openstreetmap/josm/io/FileImporter.java

    r7119 r7392  
    2121public abstract class FileImporter implements Comparable<FileImporter>, LayerChangeListener {
    2222
     23    /**
     24     * The extension file filter used to accept files.
     25     */
    2326    public final ExtensionFileFilter filter;
    2427
    2528    private boolean enabled;
    2629
     30    /**
     31     * Constructs a new {@code FileImporter} with the given extension file filter.
     32     * @param filter The extension file filter
     33     */
    2734    public FileImporter(ExtensionFileFilter filter) {
    2835        this.filter = filter;
     
    3037    }
    3138
     39    /**
     40     * Determines if this file importer accepts the given file.
     41     * @param pathname The file to test
     42     * @return {@code true} if this file importer accepts the given file, {@code false} otherwise
     43     */
    3244    public boolean acceptFile(File pathname) {
    3345        return filter.acceptName(pathname.getName());
  • trunk/src/org/openstreetmap/josm/io/OsmImporter.java

    r7037 r7392  
    1818import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1919import org.openstreetmap.josm.gui.util.GuiHelper;
    20 import org.openstreetmap.josm.tools.Utils;
    2120
    2221public class OsmImporter extends FileImporter {
    2322
     23    /**
     24     * The OSM file filter (*.osm and *.xml files).
     25     */
    2426    public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
    2527            "osm,xml", "osm", tr("OSM Server Files") + " (*.osm *.xml)");
    2628
     29    /**
     30     * Utility class containing imported OSM layer, and a task to run after it is added to MapView.
     31     */
    2732    public static class OsmImporterData {
    2833
     
    5156    }
    5257
     58    /**
     59     * Constructs a new {@code OsmImporter} with the given extension file filter.
     60     * @param filter The extension file filter
     61     */
    5362    public OsmImporter(ExtensionFileFilter filter) {
    5463        super(filter);
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r7193 r7392  
    2424import org.openstreetmap.josm.data.coor.LatLon;
    2525import org.openstreetmap.josm.data.osm.BBox;
    26 import org.openstreetmap.josm.data.osm.MultipolygonCreate;
     26import org.openstreetmap.josm.data.osm.MultipolygonBuilder;
    2727import org.openstreetmap.josm.data.osm.Node;
    2828import org.openstreetmap.josm.data.osm.NodePositionComparator;
     
    899899        final MultiPolygonMembers mpm = new MultiPolygonMembers(multiPolygon);
    900900        // Construct complete rings for the inner/outer members
    901         final List<MultipolygonCreate.JoinedPolygon> outerRings;
    902         final List<MultipolygonCreate.JoinedPolygon> innerRings;
     901        final List<MultipolygonBuilder.JoinedPolygon> outerRings;
     902        final List<MultipolygonBuilder.JoinedPolygon> innerRings;
    903903        try {
    904             outerRings = MultipolygonCreate.joinWays(mpm.outers);
    905             innerRings = MultipolygonCreate.joinWays(mpm.inners);
    906         } catch (MultipolygonCreate.JoinedPolygonCreationException ex) {
     904            outerRings = MultipolygonBuilder.joinWays(mpm.outers);
     905            innerRings = MultipolygonBuilder.joinWays(mpm.inners);
     906        } catch (MultipolygonBuilder.JoinedPolygonCreationException ex) {
    907907            Main.debug("Invalid multipolygon " + multiPolygon);
    908908            return false;
    909909        }
    910910        // Test if object is inside an outer member
    911         for (MultipolygonCreate.JoinedPolygon out : outerRings) {
     911        for (MultipolygonBuilder.JoinedPolygon out : outerRings) {
    912912            if (nodes.size() == 1
    913913                    ? nodeInsidePolygon(nodes.get(0), out.getNodes())
     
    915915                boolean insideInner = false;
    916916                // If inside an outer, check it is not inside an inner
    917                 for (MultipolygonCreate.JoinedPolygon in : innerRings) {
     917                for (MultipolygonBuilder.JoinedPolygon in : innerRings) {
    918918                    if (polygonIntersection(in.getNodes(), out.getNodes()) == PolygonIntersection.FIRST_INSIDE_SECOND
    919919                            && (nodes.size() == 1
Note: See TracChangeset for help on using the changeset viewer.