Ticket #18408: 18408.patch

File 18408.patch, 1.9 KB (added by taylor.smock, 6 years ago)

Add trim_list with test

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

     
    9821023    }
    9831024
    9841025    /**
     1026     * Trim whitespaces from the strings {@code strings}.
     1027     *
     1028     * @param strings The list of strings to strip
     1029     * @return The resulting string
     1030     * @see Utils#strip
     1031     * @since xxx
     1032     */
     1033    public static List<String> trim_list(List<String> strings) {
     1034        return strings.stream().map(Utils::strip).filter(str -> !str.isEmpty()).collect(Collectors.toList());
     1035    }
     1036
     1037    /**
    9851038     * Check if two strings are similar, but not identical, i.e., have a Levenshtein distance of 1 or 2.
    9861039     * @param string1 first string to compare
    9871040     * @param string2 second string to compare
  • test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java

     
    324324        assertTrue(c1.matches(new Environment(n1)));
    325325    }
    326326
     327    /**
     328     * Test case for {@link Functions#trim_list}
     329     */
    327330    @Test
     331    public void testTrimList() {
     332        List<String> trimmed = Functions.trim_list(Arrays.asList(" A1 ", "A2", " A3", "A4 ", ""));
     333        assertEquals(4, trimmed.size());
     334        assertEquals("A1", trimmed.get(0));
     335        assertEquals("A2", trimmed.get(1));
     336        assertEquals("A3", trimmed.get(2));
     337        assertEquals("A4", trimmed.get(3));
     338    }
     339
     340    @Test
    328341    public void testTicket8568() throws Exception {
    329342        MapCSSStyleSource sheet = new MapCSSStyleSource(
    330343                "way { width: 5; }\n" +