Changeset 14857 in josm for trunk/src


Ignore:
Timestamp:
2019-03-09T14:58:23+01:00 (6 years ago)
Author:
GerdP
Message:

see #17401, #17431

  • make sure that list of errors is never null
  • performance: avoid to sort list of errors when only elemets were removed from an already sorted list. This reduces time spent to rebuild the tree when primitives are removed or errors are fixed with the Fix button.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java

    r14856 r14857  
    88import java.util.ArrayList;
    99import java.util.Collection;
    10 import java.util.Collections;
    1110import java.util.Enumeration;
    1211import java.util.HashSet;
     
    7271    protected DefaultTreeModel valTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
    7372
    74     /** The list of errors shown in the tree */
    75     private transient List<TestError> errors = new ArrayList<>();
     73    /** The list of errors shown in the tree, normally identical to field validationErrors in current edit layer*/
     74    private transient List<TestError> errors;
    7675
    7776    /**
     
    9190     */
    9291    public ValidatorTreePanel(List<TestError> errors) {
     92        setErrorList(errors);
    9393        ToolTipManager.sharedInstance().registerComponent(this);
    9494        this.setModel(valTreeModel);
     
    9999        this.setCellRenderer(new ValidatorTreeRenderer());
    100100        this.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    101         setErrorList(errors);
    102101        for (KeyListener keyListener : getKeyListeners()) {
    103102            // Fix #3596 - Remove default keyListener to avoid conflicts with JOSM commands
     
    159158            return;
    160159        }
    161         // Sort validation errors - #8517
    162         sortErrors(errors);
    163160
    164161        // Remember first selected tree row
     
    264261                    }
    265262
     263                 // add the matching errors to the current node
    266264                    errors.stream().map(DefaultMutableTreeNode::new).forEach(messageNode::add);
    267265                });
     
    283281
    284282    /**
    285      * Sort list or errors in place.
    286      * @param errors error list to be sorted
    287      */
    288     static void sortErrors(List<TestError> errors) {
     283     * Sort list of errors in place (#8517).
     284     */
     285    void sortErrors() {
     286        if (errors.isEmpty())
     287            return;
    289288        // Calculate the string to sort only once for each element
    290         // Avoids to call TestError.compare() which costly
     289        // Avoids to call TestError.compare() which is costly
    291290        List<Pair<String, TestError>> toSort = new ArrayList<>();
    292291        for (int i = 0; i < errors.size(); i++) {
     
    325324     */
    326325    public final void setErrorList(List<TestError> errors) {
    327         this.errors = errors;
     326        this.errors = errors != null ? errors : new ArrayList<>();
     327        sortErrors();
    328328        if (isVisible()) {
    329329            buildTree();
     
    336336     */
    337337    public void setErrors(List<TestError> newerrors) {
    338         if (errors == null)
    339             return;
    340         clearErrors();
     338        errors.clear();
    341339        for (TestError error : newerrors) {
    342340            if (!error.isIgnored()) {
     
    344342            }
    345343        }
     344        sortErrors();
    346345        if (isVisible()) {
    347346            buildTree();
     
    354353     */
    355354    public List<TestError> getErrors() {
    356         return errors != null ? errors : Collections.<TestError>emptyList();
     355        return errors;
    357356    }
    358357
     
    436435    }
    437436
    438     private void clearErrors() {
    439         if (errors != null) {
    440             errors.clear();
    441         }
    442     }
    443 
    444437    @Override
    445438    public void destroy() {
    446439        DatasetEventManager.getInstance().removeDatasetListener(this);
    447440        ToolTipManager.sharedInstance().unregisterComponent(this);
    448         clearErrors();
     441        errors.clear();
    449442    }
    450443
     
    546539     */
    547540    private boolean filterRemovedPrimitives() {
    548         return errors != null && errors.removeIf(
     541        return errors.removeIf(
    549542                error -> error.getPrimitives().stream().anyMatch(p -> p.isDeleted() || p.getDataSet() == null));
    550543    }
Note: See TracChangeset for help on using the changeset viewer.