Ticket #18085: 18085.patch

File 18085.patch, 2.1 KB (added by taylor.smock, 6 years ago)

New functions uniq and uniq_list along with a simple test to make certain they work.

  • src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java

     
    571571    }
    572572
    573573    /**
     574     * Get unique values
     575     * @param values A list of values that may have duplicates
     576     * @return A list with no duplicates
     577     * @since xxx
     578     */
     579    public static List<String> uniq(String... values) {
     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 xxx
     588     */
     589    public static List<String> uniq_list(List<String> values) {
     590        return values.stream().distinct().collect(Collectors.toList());
     591    }
     592
     593    /**
    574594     * Returns the role of current object in parent relation, or role of child if current object is a relation.
    575595     * @param env the environment
    576596     * @return role of current object in parent relation, or role of child if current object is a relation
  • test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java

     
    465465    }
    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();
    470478        Way way1 = TestUtils.newWay("highway=residential name=1",