Ignore:
Timestamp:
2017-04-15T02:00:43+02:00 (3 years ago)
Author:
Don-vip
Message:

sonar - squid:S2972 - Inner classes should not have too many lines of code

Location:
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r11893 r11914  
    3535import java.util.Optional;
    3636import java.util.concurrent.ForkJoinPool;
    37 import java.util.concurrent.ForkJoinTask;
    38 import java.util.concurrent.RecursiveTask;
    3937import java.util.function.BiConsumer;
    4038import java.util.function.Consumer;
     
    4846import org.openstreetmap.josm.data.coor.EastNorth;
    4947import org.openstreetmap.josm.data.osm.BBox;
    50 import org.openstreetmap.josm.data.osm.Changeset;
    5148import org.openstreetmap.josm.data.osm.DataSet;
    5249import org.openstreetmap.josm.data.osm.Node;
     
    5754import org.openstreetmap.josm.data.osm.Way;
    5855import org.openstreetmap.josm.data.osm.WaySegment;
    59 import org.openstreetmap.josm.data.osm.visitor.Visitor;
    6056import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon;
    6157import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData;
     
    6965import org.openstreetmap.josm.gui.draw.MapViewPath;
    7066import org.openstreetmap.josm.gui.draw.MapViewPositionAndRotation;
    71 import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    72 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    73 import org.openstreetmap.josm.gui.mappaint.StyleElementList;
    74 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    75 import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement;
    76 import org.openstreetmap.josm.gui.mappaint.styleelement.AreaIconElement;
    7767import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement;
    7868import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.HorizontalTextAlignment;
     
    8373import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement;
    8474import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol;
    85 import org.openstreetmap.josm.gui.mappaint.styleelement.TextElement;
    8675import org.openstreetmap.josm.gui.mappaint.styleelement.TextLabel;
    8776import org.openstreetmap.josm.gui.mappaint.styleelement.placement.PositionForAreaStrategy;
     
    247236     * Not used in any public interfaces.
    248237     */
    249     private static final int FLAG_NORMAL = 0;
     238    static final int FLAG_NORMAL = 0;
    250239    /**
    251240     * A primitive with {@link OsmPrimitive#isDisabled()}
    252241     */
    253     private static final int FLAG_DISABLED = 1;
     242    static final int FLAG_DISABLED = 1;
    254243    /**
    255244     * A primitive with {@link OsmPrimitive#isMemberOfSelected()}
    256245     */
    257     private static final int FLAG_MEMBER_OF_SELECTED = 2;
     246    static final int FLAG_MEMBER_OF_SELECTED = 2;
    258247    /**
    259248     * A primitive with {@link OsmPrimitive#isSelected()}
    260249     */
    261     private static final int FLAG_SELECTED = 4;
     250    static final int FLAG_SELECTED = 4;
    262251    /**
    263252     * A primitive with {@link OsmPrimitive#isOuterMemberOfSelected()}
    264253     */
    265     private static final int FLAG_OUTERMEMBER_OF_SELECTED = 8;
     254    static final int FLAG_OUTERMEMBER_OF_SELECTED = 8;
    266255
    267256    private static final double PHI = Math.toRadians(20);
     
    14951484    }
    14961485
    1497     private static class ComputeStyleListWorker extends RecursiveTask<List<StyleRecord>> implements Visitor {
    1498         private final transient List<? extends OsmPrimitive> input;
    1499         private final transient List<StyleRecord> output;
    1500 
    1501         private final transient ElemStyles styles = MapPaintStyles.getStyles();
    1502         private final int directExecutionTaskSize;
    1503         private final double circum;
    1504         private final NavigatableComponent nc;
    1505 
    1506         private final boolean drawArea;
    1507         private final boolean drawMultipolygon;
    1508         private final boolean drawRestriction;
    1509 
    1510         /**
    1511          * Constructs a new {@code ComputeStyleListWorker}.
    1512          * @param circum distance on the map in meters that 100 screen pixels represent
    1513          * @param nc navigatable component
    1514          * @param input the primitives to process
    1515          * @param output the list of styles to which styles will be added
    1516          * @param directExecutionTaskSize the threshold deciding whether to subdivide the tasks
    1517          */
    1518         ComputeStyleListWorker(double circum, NavigatableComponent nc,
    1519                 final List<? extends OsmPrimitive> input, List<StyleRecord> output, int directExecutionTaskSize) {
    1520             this.circum = circum;
    1521             this.nc = nc;
    1522             this.input = input;
    1523             this.output = output;
    1524             this.directExecutionTaskSize = directExecutionTaskSize;
    1525             this.drawArea = circum <= Main.pref.getInteger("mappaint.fillareas", 10_000_000);
    1526             this.drawMultipolygon = drawArea && Main.pref.getBoolean("mappaint.multipolygon", true);
    1527             this.drawRestriction = Main.pref.getBoolean("mappaint.restriction", true);
    1528             this.styles.setDrawMultipolygon(drawMultipolygon);
    1529         }
    1530 
    1531         @Override
    1532         protected List<StyleRecord> compute() {
    1533             if (input.size() <= directExecutionTaskSize) {
    1534                 return computeDirectly();
    1535             } else {
    1536                 final Collection<ForkJoinTask<List<StyleRecord>>> tasks = new ArrayList<>();
    1537                 for (int fromIndex = 0; fromIndex < input.size(); fromIndex += directExecutionTaskSize) {
    1538                     final int toIndex = Math.min(fromIndex + directExecutionTaskSize, input.size());
    1539                     final List<StyleRecord> output = new ArrayList<>(directExecutionTaskSize);
    1540                     tasks.add(new ComputeStyleListWorker(circum, nc, input.subList(fromIndex, toIndex), output, directExecutionTaskSize).fork());
    1541                 }
    1542                 for (ForkJoinTask<List<StyleRecord>> task : tasks) {
    1543                     output.addAll(task.join());
    1544                 }
    1545                 return output;
    1546             }
    1547         }
    1548 
    1549         public List<StyleRecord> computeDirectly() {
    1550             MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock();
    1551             try {
    1552                 for (final OsmPrimitive osm : input) {
    1553                     acceptDrawable(osm);
    1554                 }
    1555                 return output;
    1556             } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {
    1557                 throw BugReport.intercept(e).put("input-size", input.size()).put("output-size", output.size());
    1558             } finally {
    1559                 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().unlock();
    1560             }
    1561         }
    1562 
    1563         private void acceptDrawable(final OsmPrimitive osm) {
    1564             try {
    1565                 if (osm.isDrawable()) {
    1566                     osm.accept(this);
    1567                 }
    1568             } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {
    1569                 throw BugReport.intercept(e).put("osm", osm);
    1570             }
    1571         }
    1572 
    1573         @Override
    1574         public void visit(Node n) {
    1575             add(n, computeFlags(n, false));
    1576         }
    1577 
    1578         @Override
    1579         public void visit(Way w) {
    1580             add(w, computeFlags(w, true));
    1581         }
    1582 
    1583         @Override
    1584         public void visit(Relation r) {
    1585             add(r, computeFlags(r, true));
    1586         }
    1587 
    1588         @Override
    1589         public void visit(Changeset cs) {
    1590             throw new UnsupportedOperationException();
    1591         }
    1592 
    1593         public void add(Node osm, int flags) {
    1594             StyleElementList sl = styles.get(osm, circum, nc);
    1595             for (StyleElement s : sl) {
    1596                 output.add(new StyleRecord(s, osm, flags));
    1597             }
    1598         }
    1599 
    1600         public void add(Relation osm, int flags) {
    1601             StyleElementList sl = styles.get(osm, circum, nc);
    1602             for (StyleElement s : sl) {
    1603                 if (drawMultipolygon && drawArea && (s instanceof AreaElement || s instanceof AreaIconElement) && (flags & FLAG_DISABLED) == 0) {
    1604                     output.add(new StyleRecord(s, osm, flags));
    1605                 } else if (drawMultipolygon && drawArea && s instanceof TextElement) {
    1606                     output.add(new StyleRecord(s, osm, flags));
    1607                 } else if (drawRestriction && s instanceof NodeElement) {
    1608                     output.add(new StyleRecord(s, osm, flags));
    1609                 }
    1610             }
    1611         }
    1612 
    1613         public void add(Way osm, int flags) {
    1614             StyleElementList sl = styles.get(osm, circum, nc);
    1615             for (StyleElement s : sl) {
    1616                 if ((drawArea && (flags & FLAG_DISABLED) == 0) || !(s instanceof AreaElement)) {
    1617                     output.add(new StyleRecord(s, osm, flags));
    1618                 }
    1619             }
    1620         }
    1621     }
    1622 
    16231486    /**
    16241487     * Sets the factory that creates the benchmark data receivers.
Note: See TracChangeset for help on using the changeset viewer.