Changeset 15323 in josm


Ignore:
Timestamp:
2019-08-27T00:41:35+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #18085 - Add method to get unique values in mapcss (patch by taylor.smock)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java

    r15317 r15323  
    555555     * @since 15279
    556556     */
    557     public static List<String> sort(String... sortables) {
     557    public static List<String> sort(String... sortables) { // NO_UCD (unused code)
    558558        Arrays.parallelSort(sortables);
    559559        return Arrays.asList(sortables);
     
    566566     * @since 15279
    567567     */
    568     public static List<String> sort_list(List<String> sortables) {
     568    public static List<String> sort_list(List<String> sortables) { // NO_UCD (unused code)
    569569        Collections.sort(sortables);
    570570        return sortables;
     571    }
     572
     573    /**
     574     * Get unique values
     575     * @param values A list of values that may have duplicates
     576     * @return A list with no duplicates
     577     * @since 15323
     578     */
     579    public static List<String> uniq(String... values) { // NO_UCD (unused code)
     580        return uniq_list(Arrays.asList(values));
     581    }
     582
     583    /**
     584     * Get unique values
     585     * @param values A list of values that may have duplicates
     586     * @return A list with no duplicates
     587     * @since 15323
     588     */
     589    public static List<String> uniq_list(List<String> values) {
     590        return values.stream().distinct().collect(Collectors.toList());
    571591    }
    572592
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java

    r15315 r15323  
    466466
    467467    @Test
     468    public void testUniqueValues() throws Exception {
     469        assertEquals(Arrays.asList(new String[] {"alpha", "beta"}),
     470                Functions.uniq("alpha", "alpha", "alpha", "beta"));
     471        assertEquals(Arrays.asList(new String[] {"one", "two", "three"}),
     472                Functions.uniq_list(Arrays.asList(new String[] {"one", "one", "two", "two", "two", "three"})));
     473    }
     474
     475    @Test
    468476    public void testCountRoles() throws Exception {
    469477        DataSet ds = new DataSet();
Note: See TracChangeset for help on using the changeset viewer.