Ignore:
Timestamp:
2016-11-17T08:29:38+01:00 (8 years ago)
Author:
simon04
Message:

JOSM/wikipedia: fix ISE: Duplicate key - #josm13991

Location:
applications/editors/josm/plugins/wikipedia
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java

    r32892 r33066  
    1818import java.util.Objects;
    1919import java.util.TreeMap;
     20import java.util.TreeSet;
    2021import java.util.regex.Pattern;
    2122import java.util.stream.Collectors;
     
    194195    public static Map<String, String> getWikidataForArticles(String wikipediaLang, List<String> articles) {
    195196        if (articles.size() > 50) {
    196             return partitionList(articles, 50).stream()
     197            final List<String> withoutDuplicates = new ArrayList<>(new TreeSet<>(articles));
     198            return partitionList(withoutDuplicates, 50).stream()
    197199                    .flatMap(chunk -> getWikidataForArticles(wikipediaLang, chunk).entrySet().stream())
    198200                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
  • applications/editors/josm/plugins/wikipedia/test/unit/org/wikipedia/WikipediaAppTest.java

    r32892 r33066  
    88import org.wikipedia.data.WikipediaEntry;
    99
     10import java.util.ArrayList;
    1011import java.util.Arrays;
    1112import java.util.Collection;
     13import java.util.Collections;
    1214import java.util.List;
    1315import java.util.Locale;
    1416import java.util.Map;
     17import java.util.stream.Collectors;
     18import java.util.stream.IntStream;
     19import java.util.stream.Stream;
    1520
    1621import static org.hamcrest.CoreMatchers.hasItem;
     
    115120
    116121    @Test
     122    public void testTicket13991() throws Exception {
     123        final Map<String, String> map = WikipediaApp.getWikidataForArticles("en",
     124                Stream.iterate("London", x -> x).limit(100).collect(Collectors.toList()));
     125        assertThat(map, is(Collections.singletonMap("London", "Q84")));
     126    }
     127
     128    @Test
    117129    public void testGetLabelForWikidata() throws Exception {
    118130        assertThat(WikipediaApp.getLabelForWikidata("Q1741", Locale.GERMAN), is("Wien"));
Note: See TracChangeset for help on using the changeset viewer.