Changeset 13766 in josm


Ignore:
Timestamp:
2018-05-14T22:18:40+02:00 (11 months ago)
Author:
Don-vip
Message:

API alignment between Relation/RelationData and RelationMember/RelationMemberData: update of IRelation/IRelationMember interfaces

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DefaultNameFormatter.java

    r13717 r13766  
    140140        if (osm instanceof INode) {
    141141            return format((INode) osm);
    142         } else if (osm instanceof IWay<?>) {
     142        } else if (osm instanceof IWay) {
    143143            return format((IWay<?>) osm);
    144144        } else if (osm instanceof IRelation) {
    145             return format((IRelation) osm);
     145            return format((IRelation<?>) osm);
    146146        }
    147147        return null;
     
    306306
    307307    @Override
    308     public String format(IRelation relation) {
     308    public String format(IRelation<?> relation) {
    309309        StringBuilder name = new StringBuilder();
    310310        if (relation.isIncomplete()) {
     
    336336    }
    337337
    338     private static StringBuilder formatRelationNameAndType(IRelation relation, StringBuilder result, TaggingPreset preset) {
     338    private static StringBuilder formatRelationNameAndType(IRelation<?> relation, StringBuilder result, TaggingPreset preset) {
    339339        if (preset == null || !(relation instanceof TemplateEngineDataProvider)) {
    340340            result.append(getRelationTypeName(relation));
     
    353353    }
    354354
    355     private final Comparator<IRelation> relationComparator = (r1, r2) -> {
     355    private final Comparator<IRelation<?>> relationComparator = (r1, r2) -> {
    356356        //TODO This doesn't work correctly with formatHooks
    357357
     
    396396
    397397    @Override
    398     public Comparator<IRelation> getRelationComparator() {
     398    public Comparator<IRelation<?>> getRelationComparator() {
    399399        return relationComparator;
    400400    }
    401401
    402     private static String getRelationTypeName(IRelation relation) {
     402    private static String getRelationTypeName(IRelation<?> relation) {
    403403        String name = trc("Relation type", relation.get("type"));
    404404        if (name == null) {
     
    433433    }
    434434
    435     private static String getNameTagValue(IRelation relation, String nameTag) {
     435    private static String getNameTagValue(IRelation<?> relation, String nameTag) {
    436436        if ("name".equals(nameTag)) {
    437437            if (Config.getPref().getBoolean("osm-primitives.localize-name", true))
     
    456456    }
    457457
    458     private static String getRelationName(IRelation relation) {
     458    private static String getRelationName(IRelation<?> relation) {
    459459        String nameTag;
    460460        for (String n : getNamingtagsForRelations()) {
  • trunk/src/org/openstreetmap/josm/data/osm/IRelation.java

    r13667 r13766  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.util.List;
     5
    46/**
    57 * IRelation captures the common functions of {@link Relation} and {@link RelationData}.
     8 * @param <M> Type of OSM relation member
    69 * @since 4098
    710 */
    8 public interface IRelation extends IPrimitive {
     11public interface IRelation<M extends IRelationMember<?>> extends IPrimitive {
    912
    1013    /**
     
    1316     */
    1417    int getMembersCount();
     18
     19    /**
     20     * Returns the relation member at the specified index.
     21     * @param index the index of the relation member
     22     * @return relation member at the specified index
     23     * @since 13766 (IRelation)
     24     */
     25    M getMember(int index);
     26
     27    /**
     28     * Returns members of the relation.
     29     * @return Members of the relation. Changes made in returned list are not mapped
     30     * back to the primitive, use setMembers() to modify the members
     31     * @since 1925
     32     * @since 13766 (IRelation)
     33     */
     34    List<M> getMembers();
    1535
    1636    /**
  • trunk/src/org/openstreetmap/josm/data/osm/IRelationMember.java

    r13677 r13766  
    66/**
    77 * IRelationMember captures the common functions of {@link RelationMember} and {@link RelationMemberData}.
     8 * @param <P> the base type of OSM primitives
    89 * @since 13677
    910 */
    10 public interface IRelationMember extends PrimitiveId {
     11public interface IRelationMember<P extends IPrimitive> extends PrimitiveId {
    1112
    1213    /**
     
    5051     */
    5152    boolean isRelation();
     53
     54    /**
     55     * Returns type of member for icon display.
     56     * @return type of member for icon display
     57     * @since 13766 (IRelationMember)
     58     */
     59    default OsmPrimitiveType getDisplayType() {
     60        return getMember().getDisplayType();
     61    }
     62
     63    /**
     64     * Returns the relation member.
     65     * @return Member. Returned value is never null.
     66     * @since 13766 (IRelationMember)
     67     */
     68    P getMember();
    5269}
  • trunk/src/org/openstreetmap/josm/data/osm/IWay.java

    r13717 r13766  
    7777        if (o instanceof IRelation)
    7878            return 1;
    79         return o instanceof IWay<?> ? Long.compare(getUniqueId(), o.getUniqueId()) : -1;
     79        return o instanceof IWay ? Long.compare(getUniqueId(), o.getUniqueId()) : -1;
    8080    }
    8181
  • trunk/src/org/openstreetmap/josm/data/osm/NameFormatter.java

    r13717 r13766  
    3535     * @since 13564 (signature)
    3636     */
    37     String format(IRelation relation);
     37    String format(IRelation<?> relation);
    3838
    3939    /**
     
    6464     * @since 13564 (signature)
    6565     */
    66     Comparator<IRelation> getRelationComparator();
     66    Comparator<IRelation<?>> getRelationComparator();
    6767}
  • trunk/src/org/openstreetmap/josm/data/osm/NameFormatterHook.java

    r13717 r13766  
    1515     * @return The corrected type name if needed, null otherwise.
    1616     */
    17     String checkRelationTypeName(IRelation relation, String defaultName);
     17    String checkRelationTypeName(IRelation<?> relation, String defaultName);
    1818
    1919    /**
     
    3939     * @return The corrected format if needed, null otherwise.
    4040     */
    41     String checkFormat(IRelation relation, String defaultName);
     41    String checkFormat(IRelation<?> relation, String defaultName);
    4242}
  • trunk/src/org/openstreetmap/josm/data/osm/OsmData.java

    r13764 r13766  
    2424 * @since 13764
    2525 */
    26 public interface OsmData<O extends IPrimitive, N extends INode, W extends IWay<N>, R extends IRelation> extends Data, Lockable {
     26public interface OsmData<O extends IPrimitive, N extends INode, W extends IWay<N>, R extends IRelation<?>> extends Data, Lockable {
    2727
    2828    // --------------
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java

    r13717 r13766  
    8686    public static OsmPrimitiveType from(IPrimitive obj) {
    8787        if (obj instanceof INode) return NODE;
    88         if (obj instanceof IWay<?>) return WAY;
     88        if (obj instanceof IWay) return WAY;
    8989        if (obj instanceof IRelation) return RELATION;
    9090        throw new IllegalArgumentException("Unknown type: "+obj);
  • trunk/src/org/openstreetmap/josm/data/osm/QuadBucketPrimitiveStore.java

    r13764 r13766  
    2020 * @since 12048
    2121 */
    22 public class QuadBucketPrimitiveStore<N extends INode, W extends IWay<N>, R extends IRelation> {
     22public class QuadBucketPrimitiveStore<N extends INode, W extends IWay<N>, R extends IRelation<?>> {
    2323    /**
    2424     * All nodes goes here, even when included in other data (ways etc). This enables the instant
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r13667 r13766  
    2424 *
    2525 * @author Frederik Ramm
     26 * @since 343
    2627 */
    27 public final class Relation extends OsmPrimitive implements IRelation {
     28public final class Relation extends OsmPrimitive implements IRelation<RelationMember> {
    2829
    2930    private RelationMember[] members = new RelationMember[0];
     
    3132    private BBox bbox;
    3233
    33     /**
    34      * @return Members of the relation. Changes made in returned list are not mapped
    35      * back to the primitive, use setMembers() to modify the members
    36      * @since 1925
    37      */
     34    @Override
    3835    public List<RelationMember> getMembers() {
    3936        return new CopyList<>(members);
     
    7572    }
    7673
    77     /**
    78      * Returns the relation member at the specified index.
    79      * @param index the index of the relation member
    80      * @return relation member at the specified index
    81      */
     74    @Override
    8275    public RelationMember getMember(int index) {
    8376        return members[index];
  • trunk/src/org/openstreetmap/josm/data/osm/RelationData.java

    r13764 r13766  
    1111 * @since 2284
    1212 */
    13 public class RelationData extends PrimitiveData implements IRelation {
     13public class RelationData extends PrimitiveData implements IRelation<RelationMemberData> {
    1414
    1515    private static final long serialVersionUID = 1163664954890478565L;
     
    4141    }
    4242
    43     /**
    44      * Returns relation members.
    45      * @return relation members
    46      */
     43    @Override
    4744    public List<RelationMemberData> getMembers() {
    4845        return members;
     
    6360
    6461    @Override
     62    public RelationMemberData getMember(int index) {
     63        return members.get(index);
     64    }
     65
     66    @Override
    6567    public long getMemberId(int idx) {
    66         return members.get(idx).getMemberId();
     68        return getMember(idx).getMemberId();
    6769    }
    6870
    6971    @Override
    7072    public String getRole(int idx) {
    71         return members.get(idx).getRole();
     73        return getMember(idx).getRole();
    7274    }
    7375
    7476    @Override
    7577    public OsmPrimitiveType getMemberType(int idx) {
    76         return members.get(idx).getMemberType();
     78        return getMember(idx).getMemberType();
    7779    }
    7880
  • trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java

    r13677 r13766  
    1212 * @since 343
    1313 */
    14 public class RelationMember implements IRelationMember {
     14public class RelationMember implements IRelationMember<OsmPrimitive> {
    1515
    1616    /**
     
    3737    public boolean isWay() {
    3838        return member instanceof Way;
    39     }
    40 
    41     /**
    42      * Returns type of member for icon display.
    43      * @return type of member for icon display
    44      * @since 3844
    45      */
    46     public OsmPrimitiveType getDisplayType() {
    47         return member.getDisplayType();
    4839    }
    4940
     
    8071    }
    8172
    82     /**
    83      * Returns the relation member.
    84      * @return Member. Returned value is never null.
    85      * @since 1937
    86      */
     73    @Override
    8774    public OsmPrimitive getMember() {
    8875        return member;
  • trunk/src/org/openstreetmap/josm/data/osm/RelationMemberData.java

    r13677 r13766  
    1111 * @since 2284
    1212 */
    13 public class RelationMemberData implements IRelationMember, Serializable {
     13public class RelationMemberData implements IRelationMember<PrimitiveData>, Serializable {
    1414
    1515    private static final long serialVersionUID = 381392198209333319L;
     
    6464
    6565    @Override
     66    public OsmPrimitiveType getDisplayType() {
     67        return memberType;
     68    }
     69
     70    @Override
    6671    public boolean isNode() {
    6772        return OsmPrimitiveType.NODE == memberType;
     
    7681    public boolean isRelation() {
    7782        return OsmPrimitiveType.RELATION == memberType;
     83    }
     84
     85    @Override
     86    public PrimitiveData getMember() {
     87        throw new UnsupportedOperationException();
    7888    }
    7989
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/PrimitiveVisitor.java

    r13717 r13766  
    2828     * @param r The relation to inspect.
    2929     */
    30     void visit(IRelation r);
     30    void visit(IRelation<?> r);
    3131}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r13761 r13766  
    730730     * @return The current selected relation membership
    731731     */
    732     public IRelation getSelectedMembershipRelation() {
     732    public IRelation<?> getSelectedMembershipRelation() {
    733733        int row = membershipTable.getSelectedRow();
    734         return row > -1 ? (IRelation) membershipData.getValueAt(row, 0) : null;
     734        return row > -1 ? (IRelation<?>) membershipData.getValueAt(row, 0) : null;
    735735    }
    736736
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r13717 r13766  
    282282
    283283    @Override
    284     public void visit(IRelation e) {
     284    public void visit(IRelation<?> e) {
    285285        if (e.isIncomplete()) return;
    286286        addCommon(e, "relation");
  • trunk/test/unit/org/openstreetmap/josm/data/osm/DefaultNameFormatterTest.java

    r13564 r13766  
    6363        TaggingPresets.addTaggingPresets(TaggingPresetReader.readAll("http://localhost:" + wireMockRule.port() + "/" + source, true));
    6464
    65         Comparator<IRelation> comparator = DefaultNameFormatter.getInstance().getRelationComparator();
     65        Comparator<IRelation<?>> comparator = DefaultNameFormatter.getInstance().getRelationComparator();
    6666
    6767        try (InputStream is = TestUtils.getRegressionDataStream(9632, "data.osm.zip")) {
Note: See TracChangeset for help on using the changeset viewer.