Changeset 32624 in osm for applications/editors/josm/plugins/wikipedia
- Timestamp:
- 2016-07-10T22:56:50+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/wikipedia
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java
r32614 r32624 96 96 (double) xpathLon.evaluate(node, XPathConstants.NUMBER)); 97 97 if ("wikidata".equals(wikipediaLang)) { 98 entries.add(new WikidataEntry(name, latLon, null));98 entries.add(new WikidataEntry(name, null, latLon)); 99 99 } else { 100 entries.add(new WikipediaEntry( name, wikipediaLang, name, latLon100 entries.add(new WikipediaEntry(wikipediaLang, name, name, latLon 101 101 )); 102 102 } … … 109 109 final List<WikipediaEntry> entriesWithLabel = new ArrayList<>(nodes.getLength()); 110 110 for (WikipediaEntry entry : entries) { 111 entriesWithLabel.add(new WikidataEntry(entry.wikipediaArticle, entry.coordinate, labels.get(entry.wikipediaArticle)));111 entriesWithLabel.add(new WikidataEntry(entry.wikipediaArticle, labels.get(entry.wikipediaArticle), entry.coordinate)); 112 112 } 113 113 return entriesWithLabel; … … 134 134 while (scanner.hasNext()) { 135 135 final String article = scanner.next().trim().replace("_", " "); 136 entries.add(new WikipediaEntry( article,wikipediaLang, article));136 entries.add(new WikipediaEntry(wikipediaLang, article)); 137 137 } 138 138 return entries; … … 149 149 @Override 150 150 public WikipediaEntry apply(String x) { 151 return new WikipediaEntry( x,wikipediaLang, x);151 return new WikipediaEntry(wikipediaLang, x); 152 152 } 153 153 })); … … 409 409 static class WikipediaEntry implements Comparable<WikipediaEntry> { 410 410 411 final String name;411 final String label; 412 412 final String wikipediaLang, wikipediaArticle; 413 413 final LatLon coordinate; 414 414 private Boolean wiwosmStatus; 415 415 416 public WikipediaEntry(String name,String wikipediaLang, String wikipediaArticle) {417 this( name, wikipediaLang, wikipediaArticle, null);418 } 419 420 public WikipediaEntry(String name, String wikipediaLang, String wikipediaArticle, LatLon coordinate) {421 this. name = name;416 WikipediaEntry(String wikipediaLang, String wikipediaArticle) { 417 this(wikipediaLang, wikipediaArticle, null, null); 418 } 419 420 WikipediaEntry(String wikipediaLang, String wikipediaArticle, String label, LatLon coordinate) { 421 this.label = label; 422 422 this.wikipediaLang = wikipediaLang; 423 423 this.wikipediaArticle = wikipediaArticle; … … 442 442 443 443 public String getLabelText() { 444 return name;444 return wikipediaArticle; 445 445 } 446 446 447 447 @Override 448 448 public String toString() { 449 return name;449 return wikipediaArticle; 450 450 } 451 451 452 452 @Override 453 453 public int compareTo(WikipediaEntry o) { 454 return AlphanumComparator.getInstance().compare( name, o.name);454 return AlphanumComparator.getInstance().compare(label, o.label); 455 455 } 456 456 } … … 458 458 static class WikidataEntry extends WikipediaEntry { 459 459 460 WikidataEntry(String id, LatLon coordinate, String label) {461 super( label, "wikidata", id, coordinate);460 WikidataEntry(String id, String label, LatLon coordinate) { 461 super("wikidata", id, label, coordinate); 462 462 ensureValidWikidataId(id); 463 463 } … … 470 470 @Override 471 471 public String getLabelText() { 472 return getLabelText( name, wikipediaArticle);472 return getLabelText(label, wikipediaArticle); 473 473 } 474 474 -
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaToggleDialog.java
r32610 r32624 43 43 import org.openstreetmap.josm.tools.LanguageInfo; 44 44 import org.openstreetmap.josm.tools.OpenBrowser; 45 import org.openstreetmap.josm.tools.Utils; 45 46 import org.wikipedia.WikipediaApp.WikipediaEntry; 46 47 … … 78 79 Main.map.mapView.zoomTo(bbox); 79 80 } 80 SearchAction.search(entry.name.replaceAll("\\(.*\\)", ""), SearchAction.SearchMode.replace); 81 final String search = Utils.firstNonNull(entry.label, entry.wikipediaArticle).replaceAll("\\(.*\\)", ""); 82 SearchAction.search(search, SearchAction.SearchMode.replace); 81 83 } 82 84 } -
applications/editors/josm/plugins/wikipedia/test/unit/org/wikipedia/WikipediaAppTest.java
r32612 r32624 133 133 @Test 134 134 public void testGetBrowserUrl() { 135 final WikipediaEntry entry = new WikipediaEntry(" Sternheim & Emanuel", "de", "Sternheim & Emanuel");135 final WikipediaEntry entry = new WikipediaEntry("de", "Sternheim & Emanuel"); 136 136 assertThat(entry.getBrowserUrl(), is("https://de.wikipedia.org/wiki/Sternheim_%26_Emanuel")); 137 137 } … … 156 156 @Override 157 157 public boolean evaluate(WikipediaEntry entry) { 158 return "Q865406".equals(entry.wikipediaArticle) && "wikidata".equals(entry.wikipediaLang) && "Birgitzer Alm".equals(entry. name);158 return "Q865406".equals(entry.wikipediaArticle) && "wikidata".equals(entry.wikipediaLang) && "Birgitzer Alm".equals(entry.label); 159 159 } 160 160 })); … … 192 192 @Test 193 193 public void testWIWOSMStatus() throws Exception { 194 final WikipediaEntry entry1 = new WikipediaEntry( null,"en", "Vienna");195 final WikipediaEntry entry2 = new WikipediaEntry( null,"en", "London");196 final WikipediaEntry entry3 = new WikipediaEntry( null,"en", "a-non-existing-article");194 final WikipediaEntry entry1 = new WikipediaEntry("en", "Vienna"); 195 final WikipediaEntry entry2 = new WikipediaEntry("en", "London"); 196 final WikipediaEntry entry3 = new WikipediaEntry("en", "a-non-existing-article"); 197 197 WikipediaApp.updateWIWOSMStatus("en", Arrays.asList(entry1, entry2, entry3)); 198 198 assertThat(entry1.getWiwosmStatus(), is(true));
Note:
See TracChangeset
for help on using the changeset viewer.