Ticket #23468: 23468.patch

File 23468.patch, 3.9 KB (added by GerdP, 19 months ago)
  • src/org/openstreetmap/josm/data/validation/OsmValidator.java

     
    1515import java.util.Arrays;
    1616import java.util.Collection;
    1717import java.util.Collections;
     18import java.util.Comparator;
    1819import java.util.EnumMap;
    1920import java.util.Enumeration;
    2021import java.util.HashMap;
     
    683684
    684685    /**
    685686     * Groups the given collection of errors by severity, then message, then description.
     687     * Uses <code>AlphanumComparator</code> for grouping the strings.
    686688     * @param errors list of errors to group
    687689     * @param filterToUse optional filter
    688690     * @return collection of errors grouped by severity, then message, then description
     
    690692     */
    691693    public static Map<Severity, Map<String, Map<String, List<TestError>>>> getErrorsBySeverityMessageDescription(
    692694            Collection<TestError> errors, Predicate<? super TestError> filterToUse) {
    693         return errors.stream().filter(filterToUse).collect(
     695        return getErrorsBySeverityMessageDescription(errors, filterToUse, AlphanumComparator.getInstance());
     696    }
     697
     698    /**
     699     * Groups the given collection of errors by severity, then message, then description.
     700     * Uses the given comparator for grouping the strings.
     701     * @param errors list of errors to group
     702     * @param filterToUse optional filter
     703     * @param comparator the String comparator to use for grouping the messages and descriptions
     704     * @return collection of errors grouped by severity, then message, then description
     705     * @since xxx
     706     */
     707    public static Map<Severity, Map<String, Map<String, List<TestError>>>> getErrorsBySeverityMessageDescription(
     708            Collection<TestError> errors, Predicate<? super TestError> filterToUse, final Comparator<String> comparator) {
     709        Stopwatch stopwatch = Stopwatch.createStarted();
     710        Map<Severity, Map<String, Map<String, List<TestError>>>>  x = errors.stream().filter(filterToUse).collect(
    694711                Collectors.groupingBy(TestError::getSeverity, () -> new EnumMap<>(Severity.class),
    695                         Collectors.groupingBy(TestError::getMessage, () -> new TreeMap<>(AlphanumComparator.getInstance()),
     712                        Collectors.groupingBy(TestError::getMessage, () -> new TreeMap<>(comparator),
    696713                                Collectors.groupingBy(e -> e.getDescription() == null ? "" : e.getDescription(),
    697                                         () -> new TreeMap<>(AlphanumComparator.getInstance()),
     714                                        () -> new TreeMap<>(comparator),
    698715                                        Collectors.toList()
    699716                                ))));
     717        Logging.debug("getErrorsBySeverityMessageDescription took "  + stopwatch.toString());
     718        return x;
    700719    }
    701720
    702721    /**
  • src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java

     
    209209            filterToUse = filterToUse.and(e -> e.getPrimitives().stream().anyMatch(filter::contains));
    210210        }
    211211        Map<Severity, Map<String, Map<String, List<TestError>>>> errorsBySeverityMessageDescription
    212             = OsmValidator.getErrorsBySeverityMessageDescription(errors, filterToUse);
     212            = OsmValidator.getErrorsBySeverityMessageDescription(errors, filterToUse, String::compareTo);
    213213
    214214        final List<TreePath> expandedPaths = new ArrayList<>();
    215215        for (Entry<Severity, Map<String, Map<String, List<TestError>>>> entry: errorsBySeverityMessageDescription.entrySet()) {