Changeset 7109 in josm for trunk


Ignore:
Timestamp:
2014-05-12T00:40:09+02:00 (10 years ago)
Author:
Don-vip
Message:

see #8671 - some code refactoring done in an unsuccessful attempt to reproduce error, but worth keeping

Location:
trunk
Files:
1 added
5 edited

Legend:

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

    r7108 r7109  
    2525import java.awt.geom.Point2D;
    2626import java.awt.geom.Rectangle2D;
    27 import java.util.AbstractList;
    2827import java.util.ArrayList;
    2928import java.util.Collection;
     
    7170import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList;
    7271import org.openstreetmap.josm.gui.mappaint.TextElement;
     72import org.openstreetmap.josm.tools.CompositeList;
    7373import org.openstreetmap.josm.tools.ImageProvider;
    7474import org.openstreetmap.josm.tools.Utils;
     
    237237
    238238            return Float.compare(this.style.object_z_index, other.style.object_z_index);
    239         }
    240     }
    241 
    242     /**
    243      * Joined List build from two Lists (read-only).
    244      *
    245      * Extremely simple single-purpose implementation.
    246      * @param <T>
    247      */
    248     public static class CompositeList<T> extends AbstractList<T> {
    249         List<? extends T> a,b;
    250 
    251         /**
    252          * Constructs a new {@code CompositeList} from two lists.
    253          * @param a First list
    254          * @param b Second list
    255          */
    256         public CompositeList(List<? extends T> a, List<? extends T> b) {
    257             this.a = a;
    258             this.b = b;
    259         }
    260 
    261         @Override
    262         public T get(int index) {
    263             return index < a.size() ? a.get(index) : b.get(index - a.size());
    264         }
    265 
    266         @Override
    267         public int size() {
    268             return a.size() + b.size();
    269239        }
    270240    }
     
    13601330
    13611331        /**
    1362          * Constructor for CreateStyleRecordsWorker.
     1332         * Constructs a new {@code ComputeStyleListWorker}.
    13631333         * @param input the primitives to process
    13641334         * @param from first index of <code>input</code> to use
    13651335         * @param to last index + 1
     1336         * @param output the list of styles to which styles will be added
     1337         * @param data the data set
    13661338         */
    13671339        public ComputeStyleListWorker(final List<? extends OsmPrimitive> input, int from, int to, List<StyleRecord> output, DataSet data) {
     
    15161488            List<Way> ways = data.searchWays(bbox);
    15171489            List<Relation> relations = data.searchRelations(bbox);
    1518 
     1490   
    15191491            final List<StyleRecord> allStyleElems = new ArrayList<>(nodes.size()+ways.size()+relations.size());
    1520 
     1492   
    15211493            ConcurrentTasksHelper helper = new ConcurrentTasksHelper(allStyleElems, data);
    15221494
     
    15451517                );
    15461518            }
    1547 
     1519   
    15481520            if (Main.isTraceEnabled()) {
    15491521                timeFinished = System.currentTimeMillis();
    15501522                System.err.println("; phase 2 (draw): " + (timeFinished - timePhase1) + " ms; total: " + (timeFinished - timeStart) + " ms");
    15511523            }
    1552 
     1524   
    15531525            drawVirtualNodes(data, bbox);
    15541526        } finally {
  • trunk/test/performance/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRendererPerformanceTest.java

    r7093 r7109  
    44import java.awt.Graphics2D;
    55import java.awt.image.BufferedImage;
     6import java.io.File;
    67import java.io.FileInputStream;
    78import java.io.InputStream;
    8 import java.io.File;
    99
    1010import org.junit.BeforeClass;
    1111import org.junit.Test;
    12 import org.openstreetmap.josm.Main;
     12import org.openstreetmap.josm.JOSMFixture;
    1313import org.openstreetmap.josm.data.Bounds;
    1414import org.openstreetmap.josm.data.osm.DataSet;
    15 import org.openstreetmap.josm.data.projection.Projections;
    1615import org.openstreetmap.josm.gui.NavigatableComponent;
    1716import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    1817import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
     18import org.openstreetmap.josm.io.Compression;
    1919import org.openstreetmap.josm.io.OsmReader;
    20 import org.openstreetmap.josm.io.Compression;
    2120
    2221public class StyledMapRendererPerformanceTest {
     
    3433    @BeforeClass
    3534    public static void load() throws Exception {
    36         Main.initApplicationPreferences();
    37         Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
     35        JOSMFixture.createPerformanceTestFixture().init();
    3836        img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_3BYTE_BGR);
    3937        g = (Graphics2D)img.getGraphics();
     
    5351            dsCity = OsmReader.parseDataSet(fisC, NullProgressMonitor.INSTANCE);
    5452        }
    55 
    56         // Warm up
    57         new StyledMapRendererPerformanceTest().testRestrictionSmall();
    58         new StyledMapRendererPerformanceTest().testCity();
    5953    }
    6054
  • trunk/test/performance/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSPerformanceTest.groovy

    r7068 r7109  
    111111        def mv = Main.map.mapView
    112112
    113         BufferedImage img = mv.createImage(mv.getWidth(), mv.getHeight())
     113        BufferedImage img = new BufferedImage(mv.getWidth(), mv.getHeight(), BufferedImage.TYPE_3BYTE_BGR)
    114114        Graphics2D g = img.createGraphics()
    115115        g.setClip(0,0, mv.getWidth(), mv.getHeight())
  • trunk/test/unit/org/openstreetmap/josm/TestUtils.java

    r7068 r7109  
    55import static org.junit.Assert.assertThat;
    66import static org.junit.Assert.assertTrue;
     7import static org.junit.Assert.fail;
    78
     9import java.util.Arrays;
     10import java.util.Comparator;
    811import java.util.Map;
    912
    1013import org.junit.Test;
    11 import org.openstreetmap.josm.Main;
    1214import org.openstreetmap.josm.data.osm.Node;
    1315import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    6567    }
    6668
     69    /**
     70     * Checks that the given Comparator respects its contract on the given table.
     71     * @param comparator The comparator to test
     72     * @param array The array sorted for test purpose
     73     */
     74    public static <T> void checkComparableContract(Comparator<T> comparator, T[] array) {
     75        System.out.println("Validating Comparable contract on array of "+array.length+" elements");
     76        // Check each compare possibility
     77        for (int i=0; i<array.length; i++) {
     78            T r1 = array[i];
     79            for (int j=i; j<array.length; j++) {
     80                T r2 = array[j];
     81                int a = comparator.compare(r1, r2);
     82                int b = comparator.compare(r2, r1);
     83                if (i==j || a==b) {
     84                    if (a != 0 || b != 0) {
     85                        fail(getFailMessage(r1, r2, a, b));
     86                    }
     87                } else {
     88                    if (a != -b) {
     89                        fail(getFailMessage(r1, r2, a, b));
     90                    }
     91                }
     92                for (int k=j; k<array.length; k++) {
     93                    T r3 = array[k];
     94                    int c = comparator.compare(r1, r3);
     95                    int d = comparator.compare(r2, r3);
     96                    if (a > 0 && d > 0) {
     97                        if (c <= 0) {
     98                           fail(getFailMessage(r1, r2, r3, a, b, c, d));
     99                        }
     100                    } else if (a == 0 && d == 0) {
     101                        if (c != 0) {
     102                            fail(getFailMessage(r1, r2, r3, a, b, c, d));
     103                        }
     104                    } else if (a < 0 && d < 0) {
     105                        if (c >= 0) {
     106                            fail(getFailMessage(r1, r2, r3, a, b, c, d));
     107                        }
     108                    }
     109                }
     110            }
     111        }
     112        // Sort relation array
     113        Arrays.sort(array, comparator);
     114    }
     115
     116    private static <T> String getFailMessage(T o1, T o2, int a, int b) {
     117        return new StringBuilder("Compared\no1: ").append(o1).append("\no2: ")
     118        .append(o2).append("\ngave: ").append(a).append("/").append(b)
     119        .toString();
     120    }
     121
     122    private static <T> String getFailMessage(T o1, T o2, T o3, int a, int b, int c, int d) {
     123        return new StringBuilder(getFailMessage(o1, o2, a, b))
     124        .append("\nCompared\no1: ").append(o1).append("\no3: ").append(o3).append("\ngave: ").append(c)
     125        .append("\nCompared\no2: ").append(o2).append("\no3: ").append(o3).append("\ngave: ").append(d)
     126        .toString();
     127    }
    67128}
  • trunk/test/unit/org/openstreetmap/josm/gui/DefaultNameFormatterTest.java

    r7100 r7109  
    33
    44import static org.junit.Assert.assertTrue;
    5 import static org.junit.Assert.fail;
    65
    76import java.io.FileInputStream;
     
    98import java.io.InputStream;
    109import java.util.ArrayList;
    11 import java.util.Arrays;
    1210import java.util.Comparator;
    1311
     
    7573            Relation[] relations = new ArrayList<>(ds.getRelations()).toArray(new Relation[0]);
    7674
    77             // Check each compare possibility
    78             for (int i=0; i<relations.length; i++) {
    79                 Relation r1 = relations[i];
    80                 for (int j=i; j<relations.length; j++) {
    81                     Relation r2 = relations[j];
    82                     int a = comparator.compare(r1, r2);
    83                     int b = comparator.compare(r2, r1);
    84                     if (i==j || a==b) {
    85                         if (a != 0 || b != 0) {
    86                             fail(getFailMessage(r1, r2, a, b));
    87                         }
    88                     } else {
    89                         if (a != -b) {
    90                             fail(getFailMessage(r1, r2, a, b));
    91                         }
    92                     }
    93                     for (int k=j; k<relations.length; k++) {
    94                         Relation r3 = relations[k];
    95                         int c = comparator.compare(r1, r3);
    96                         int d = comparator.compare(r2, r3);
    97                         if (a > 0 && d > 0) {
    98                             if (c <= 0) {
    99                                fail(getFailMessage(r1, r2, r3, a, b, c, d));
    100                             }
    101                         } else if (a == 0 && d == 0) {
    102                             if (c != 0) {
    103                                 fail(getFailMessage(r1, r2, r3, a, b, c, d));
    104                             }
    105                         } else if (a < 0 && d < 0) {
    106                             if (c >= 0) {
    107                                 fail(getFailMessage(r1, r2, r3, a, b, c, d));
    108                             }
    109                         }
    110                     }
    111                 }
    112             }
    113             // Sort relation array
    114             Arrays.sort(relations, comparator);
     75            TestUtils.checkComparableContract(comparator, relations);
    11576        }
    11677    }
    117 
    118     private static String getFailMessage(Relation r1, Relation r2, int a, int b) {
    119         return new StringBuilder("Compared\nr1: ").append(r1).append("\nr2: ")
    120         .append(r2).append("\ngave: ").append(a).append("/").append(b)
    121         .toString();
    122     }
    123 
    124     private static String getFailMessage(Relation r1, Relation r2, Relation r3, int a, int b, int c, int d) {
    125         return new StringBuilder(getFailMessage(r1, r2, a, b))
    126         .append("\nCompared\nr1: ").append(r1).append("\nr3: ").append(r3).append("\ngave: ").append(c)
    127         .append("\nCompared\nr2: ").append(r2).append("\nr3: ").append(r3).append("\ngave: ").append(d)
    128         .toString();
    129     }
    13078}
Note: See TracChangeset for help on using the changeset viewer.