Changeset 17524 in josm


Ignore:
Timestamp:
2021-02-22T13:59:25+01:00 (2 weeks ago)
Author:
Don-vip
Message:

fix #20440 - don't create SubclassFilteredCollection just for counting instances in conflict dialog title

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/conflict/ConflictCollection.java

    r15832 r17524  
    1111import java.util.Set;
    1212import java.util.concurrent.CopyOnWriteArrayList;
     13import java.util.function.Predicate;
    1314import java.util.stream.Collectors;
    1415
     
    344345    }
    345346
     347    /**
     348     * Returns the number of conflicts involving nodes.
     349     * @return The number of conflicts involving nodes.
     350     * @since 17524
     351     */
     352    public final long getNumberOfNodeConflicts() {
     353        return getNumberOfConflicts(c -> c.getMy() instanceof Node);
     354    }
     355
     356    /**
     357     * Returns the number of conflicts involving nodes.
     358     * @return The number of conflicts involving nodes.
     359     * @since 17524
     360     */
     361    public final long getNumberOfWayConflicts() {
     362        return getNumberOfConflicts(c -> c.getMy() instanceof Way);
     363    }
     364
     365    /**
     366     * Returns the number of conflicts involving nodes.
     367     * @return The number of conflicts involving nodes.
     368     * @since 17524
     369     */
     370    public final long getNumberOfRelationConflicts() {
     371        return getNumberOfConflicts(c -> c.getMy() instanceof Relation);
     372    }
     373
     374    private long getNumberOfConflicts(Predicate<Conflict<?>> predicate) {
     375        return conflicts.isEmpty() ? 0 : conflicts.stream().filter(Objects::nonNull).filter(predicate).count();
     376    }
     377
    346378    @Override
    347379    public int hashCode() {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r17340 r17524  
    238238            setTitle(trn("Conflict: {0} unresolved", "Conflicts: {0} unresolved", conflictsCount, conflictsCount) +
    239239                    " ("+tr("Rel.:{0} / Ways:{1} / Nodes:{2}",
    240                             conflicts.getRelationConflicts().size(),
    241                             conflicts.getWayConflicts().size(),
    242                             conflicts.getNodeConflicts().size())+')');
     240                            conflicts.getNumberOfRelationConflicts(),
     241                            conflicts.getNumberOfWayConflicts(),
     242                            conflicts.getNumberOfNodeConflicts())+')');
    243243        } else {
    244244            setTitle(tr("Conflict"));
Note: See TracChangeset for help on using the changeset viewer.