Ignore:
Timestamp:
2014-01-06T20:42:32+01:00 (10 years ago)
Author:
simon04
Message:

fix #9525 - multiselecting objects does not show differing relation membership correctly in the sidebar

For instance, positions are displayed as 48-49,91,✗.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Predicates.java

    r6592 r6652  
    33import org.openstreetmap.josm.data.osm.OsmPrimitive;
    44
     5import java.util.Collection;
    56import java.util.regex.Pattern;
    67
     
    8485        };
    8586    }
     87
     88    /**
     89     * Returns a {@link Predicate} executing {@link Collection#contains(Object)}.
     90     */
     91    public static <T> Predicate<T> inCollection(final Collection<? extends T> target) {
     92        return new Predicate<T>() {
     93            @Override
     94            public boolean evaluate(T object) {
     95                return target.contains(object);
     96            }
     97        };
     98    }
    8699}
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6642 r6652  
    3737import java.util.Arrays;
    3838import java.util.Collection;
     39import java.util.Collections;
    3940import java.util.Iterator;
    4041import java.util.List;
     
    861862
    862863    /**
     864     * Returns a human readable representation of a list of positions.
     865     * <p/>
     866     * For instance, {@code [1,5,2,6,7} yields "1-2,5-7
     867     * @param positionList a list of positions
     868     * @return a human readable representation
     869     */
     870    public static String getPositionListString(List<Integer> positionList)  {
     871        Collections.sort(positionList);
     872        final StringBuilder sb = new StringBuilder(32);
     873        sb.append(positionList.get(0));
     874        int cnt = 0;
     875        int last = positionList.get(0);
     876        for (int i = 1; i < positionList.size(); ++i) {
     877            int cur = positionList.get(i);
     878            if (cur == last + 1) {
     879                ++cnt;
     880            } else if (cnt == 0) {
     881                sb.append(",").append(cur);
     882            } else {
     883                sb.append("-").append(last);
     884                sb.append(",").append(cur);
     885                cnt = 0;
     886            }
     887            last = cur;
     888        }
     889        if (cnt >= 1) {
     890            sb.append("-").append(last);
     891        }
     892        return sb.toString();
     893    }
     894
     895
     896    /**
    863897     * Returns a list of capture groups if {@link Matcher#matches()}, or {@code null}.
    864898     * The first element (index 0) is the complete match.
Note: See TracChangeset for help on using the changeset viewer.