Ignore:
Timestamp:
2016-08-30T13:27:07+02:00 (8 years ago)
Author:
simon04
Message:

JOSM/wikipedia: refactoring (move label to WikidataEntry)

Location:
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/data
Files:
2 edited

Legend:

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

    r32891 r32892  
    44import org.openstreetmap.josm.data.coor.LatLon;
    55import org.openstreetmap.josm.data.osm.Tag;
     6import org.openstreetmap.josm.tools.AlphanumComparator;
    67import org.openstreetmap.josm.tools.CheckParameterUtil;
    78import org.openstreetmap.josm.tools.Utils;
    89import org.wikipedia.WikipediaApp;
    910
     11import java.util.Comparator;
     12import java.util.Optional;
     13
    1014public class WikidataEntry extends WikipediaEntry {
    1115
     16    public final String label;
    1217    public final String description;
    1318
    1419    public WikidataEntry(String id, String label, LatLon coordinate, String description) {
    15         super("wikidata", id, label, coordinate);
     20        super("wikidata", id, coordinate);
     21        this.label = label;
    1622        this.description = description;
    1723        ensureValidWikidataId(id);
     
    3339    }
    3440
     41    @Override
     42    public String getSearchText() {
     43        return Optional.ofNullable(label).orElse(article);
     44    }
     45
    3546    private static void ensureValidWikidataId(String id) {
    3647        CheckParameterUtil.ensureThat(WikipediaApp.WIKIDATA_PATTERN.matcher(id).matches(), "Invalid Wikidata ID given: " + id);
    3748    }
     49
     50    @Override
     51    public int compareTo(WikipediaEntry o) {
     52        if (o instanceof WikidataEntry) {
     53            return Comparator
     54                    .<WikidataEntry, String>comparing(x -> x.label, AlphanumComparator.getInstance())
     55                    .thenComparing(x -> x.article, AlphanumComparator.getInstance())
     56                    .compare(this, ((WikidataEntry) o));
     57        } else {
     58            return super.compareTo(o);
     59        }
     60    }
    3861}
  • applications/editors/josm/plugins/wikipedia/src/org/wikipedia/data/WikipediaEntry.java

    r32891 r32892  
    88import org.wikipedia.WikipediaApp;
    99
    10 import java.util.Comparator;
    1110import java.util.Objects;
    1211import java.util.regex.Matcher;
     
    1716    public final String lang;
    1817    public final String article;
    19     public final String label;
    2018    public final LatLon coordinate;
    2119    private Boolean wiwosmStatus;
    2220
    2321    public WikipediaEntry(String lang, String article) {
    24         this(lang, article, null, null);
     22        this(lang, article, null);
    2523    }
    2624
    27     public WikipediaEntry(String lang, String article, String label, LatLon coordinate) {
     25    public WikipediaEntry(String lang, String article, LatLon coordinate) {
    2826        this.lang = lang;
    2927        this.article = article;
    30         this.label = label;
    3128        this.coordinate = coordinate;
    3229    }
     
    9087    }
    9188
     89    public String getSearchText() {
     90        return article;
     91    }
     92
    9293    @Override
    9394    public String toString() {
     
    9798    @Override
    9899    public int compareTo(WikipediaEntry o) {
    99         return Comparator
    100                 .<WikipediaEntry, String>comparing(x -> x.label, AlphanumComparator.getInstance())
    101                 .thenComparing(x -> x.article, AlphanumComparator.getInstance())
    102                 .compare(this, o);
     100        return AlphanumComparator.getInstance().compare(article, o.article);
    103101    }
    104102
Note: See TracChangeset for help on using the changeset viewer.