Changeset 2206 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2009-09-27T20:23:04+02:00 (15 years ago)
Author:
jttt
Message:

Minor optimalizations

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
3 edited

Legend:

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

    r2188 r2206  
    3535abstract public class OsmPrimitive implements Comparable<OsmPrimitive>, Tagged {
    3636
     37    private static final int FLAG_MODIFIED = 1 << 0;
     38    private static final int FLAG_VISIBLE  = 1 << 1;
     39    private static final int FLAG_DISABLED = 1 << 2;
     40    private static final int FLAG_DELETED  = 1 << 3;
     41    private static final int FLAG_FILTERED = 1 << 4;
     42    private static final int FLAG_SELECTED = 1 << 5;
     43
    3744    /**
    3845     * Replies the sub-collection of {@see OsmPrimitive}s of type <code>type</code> present in
    3946     * another collection of {@see OsmPrimitive}s. The result collection is a list.
    40      * 
     47     *
    4148     * If <code>list</code> is null, replies an empty list.
    42      * 
     49     *
    4350     * @param <T>
    4451     * @param list  the original list
     
    6067     * Replies the sub-collection of {@see OsmPrimitive}s of type <code>type</code> present in
    6168     * another collection of {@see OsmPrimitive}s. The result collection is a set.
    62      * 
     69     *
    6370     * If <code>list</code> is null, replies an empty set.
    64      * 
     71     *
    6572     * @param <T>
    6673     * @param list  the original collection
     
    117124    private long id = 0;
    118125
    119     /**
    120      * <code>true</code> if the object has been modified since it was loaded from
    121      * the server. In this case, on next upload, this object will be updated.
    122      * Deleted objects are deleted from the server. If the objects are added (id=0),
    123      * the modified is ignored and the object is added to the server.
    124      *
    125      */
    126     private boolean modified = false;
    127 
    128     /**
    129      * <code>true</code>, if the object has been deleted.
    130      *
    131      */
    132     private boolean deleted = false;
    133 
    134     /**
    135      * Visibility status as specified by the server. The visible attribute was
    136      * introduced with the 0.4 API to be able to communicate deleted objects
    137      * (they will have visible=false).
    138      *
    139      */
    140     private boolean visible = true;
    141 
    142     /**
    143      * <code>true</code>, if the object has been set inactive
    144      *
    145      */
    146     private boolean disabled = false;
    147 
    148     /**
    149      * <code>true</code>, if the object has been filtered out
    150      *
    151      */
    152     private boolean filtered = false;
     126    private volatile byte flags;
     127
    153128
    154129    /**
     
    157132     */
    158133    public User user = null;
    159 
    160     /**
    161      * If set to true, this object is currently selected.
    162      *
    163      */
    164     private volatile boolean selected = false;
    165134
    166135    /**
     
    208177     */
    209178    public void setDisabled(boolean disabled) {
    210         this.disabled = disabled;
     179        if (disabled) {
     180            flags |= FLAG_DISABLED;
     181        } else {
     182            flags &= ~FLAG_DISABLED;
     183        }
     184
    211185    }
    212186
     
    217191     */
    218192    public boolean isDisabled() {
    219         return disabled;
     193        return (flags & FLAG_DISABLED) != 0;
    220194    }
    221195    /**
     
    225199     */
    226200    public void setFiltered(boolean filtered) {
    227         this.filtered = filtered;
     201        if (filtered) {
     202            flags |= FLAG_FILTERED;
     203        } else {
     204            flags &= ~FLAG_FILTERED;
     205        }
    228206    }
    229207    /**
     
    233211     */
    234212    public boolean isFiltered() {
    235         return filtered;
     213        return (flags & FLAG_FILTERED) != 0;
    236214    }
    237215
     
    243221     */
    244222    public void setSelected(boolean selected) {
    245         this.selected = selected;
     223        if (selected) {
     224            flags |= FLAG_SELECTED;
     225        } else {
     226            flags &= ~FLAG_SELECTED;
     227        }
    246228    }
    247229    /**
     
    252234     */
    253235    public boolean isSelected() {
    254         return selected;
     236        return (flags & FLAG_SELECTED) != 0;
    255237    }
    256238
     
    261243     */
    262244    public void setModified(boolean modified) {
    263         this.modified = modified;
     245        if (modified) {
     246            flags |= FLAG_MODIFIED;
     247        } else {
     248            flags &= ~FLAG_MODIFIED;
     249        }
    264250    }
    265251
     
    268254     * the server. In this case, on next upload, this object will be updated.
    269255     *
     256     * Deleted objects are deleted from the server. If the objects are added (id=0),
     257     * the modified is ignored and the object is added to the server.
     258     *
    270259     * @return <code>true</code> if the object has been modified since it was loaded from
    271260     * the server
    272261     */
    273262    public boolean isModified() {
    274         return modified;
     263        return (flags & FLAG_MODIFIED) != 0;
    275264    }
    276265
     
    282271     */
    283272    public boolean isDeleted() {
    284         return deleted;
     273        return (flags & FLAG_DELETED) != 0;
    285274    }
    286275
     
    292281     */
    293282    public boolean isUsable() {
    294         return !deleted && !incomplete && !disabled;
     283        return !isDeleted() && !incomplete && !isDisabled();
    295284    }
    296285
     
    304293     */
    305294    public boolean isVisible() {
    306         return visible;
     295        return (flags & FLAG_VISIBLE) != 0;
    307296    }
    308297
     
    318307        if (id == 0 && visible == false)
    319308            throw new IllegalStateException(tr("A primitive with ID = 0 can't be invisible."));
    320         this.visible = visible;
     309        if (visible) {
     310            flags |= FLAG_VISIBLE;
     311        } else {
     312            flags &= ~FLAG_VISIBLE;
     313        }
    321314    }
    322315
     
    456449     */
    457450    public void setDeleted(boolean deleted) {
    458         this.modified = deleted;
    459         this.deleted = deleted;
    460         this.selected = false;
     451        if (deleted) {
     452            flags |= FLAG_DELETED;
     453        } else {
     454            flags &= ~FLAG_DELETED;
     455        }
     456        setModified(deleted);
     457        setSelected(false);
    461458    }
    462459
     
    623620        keys = osm.keys == null ? null : new HashMap<String, String>(osm.keys);
    624621        id = osm.id;
    625         modified = osm.modified;
    626         deleted = osm.deleted;
    627         setSelected(osm.isSelected());
    628622        timestamp = osm.timestamp;
    629623        version = osm.version;
    630624        incomplete = osm.incomplete;
    631         visible = osm.visible;
     625        flags = osm.flags;
    632626        clearCached();
    633627        clearErrors();
     
    674668
    675669        return
    676         deleted == other.deleted
    677         && modified == other.modified
     670        isDeleted() == other.isDeleted()
     671        && isModified() == other.isModified()
    678672        && timestamp == other.timestamp
    679673        && version == other.version
    680         && visible == other.visible
     674        && isVisible() == other.isVisible()
    681675        && (user == null ? other.user==null : user==other.user);
    682676    }
  • trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java

    r2186 r2206  
    2525     */
    2626    public String getRole() {
    27         if (role == null)
    28             return "";
    2927        return role;
    3028    }
     
    3634     */
    3735    public boolean hasRole() {
    38         return role != null && !"".equals(role);
     36        return !"".equals(role);
    3937    }
    4038
     
    9593    /**
    9694     *
    97      * @return Member
     95     * @return Member. Returned value is never null.
    9896     * @since 1937
    9997     */
     
    102100    }
    103101
     102    /**
     103     *
     104     * @param role Can be null, in this case it's save as ""
     105     * @param member Cannot be null
     106     */
    104107    public RelationMember(String role, OsmPrimitive member) {
     108        if (role == null) {
     109            role = "";
     110        }
     111        if (member == null) {
     112            throw new IllegalArgumentException("Relation member cannot be null");
     113        }
    105114        this.role = role;
    106115        this.member = member;
     
    109118    /**
    110119     * Copy constructor.
     120     * This constructor is left only for backwards compatibility. Copying RelationMember doesn't make sense
     121     * because it's immutable
    111122     * @param other relation member to be copied.
    112123     */
    113124    public RelationMember(RelationMember other) {
    114         role = other.role;
    115         member = other.member;
     125        this(other.role, other.member);
    116126    }
    117127
     
    127137     */
    128138    public boolean refersTo(OsmPrimitive primitive) {
    129         if (primitive == null) return false;
    130         if (member == null) return false;
    131139        return member == primitive;
    132140    }
     
    136144        final int prime = 31;
    137145        int result = 1;
    138         result = prime * result + ((member == null) ? 0 : member.hashCode());
    139         result = prime * result + ((role == null) ? 0 : role.hashCode());
     146        result = prime * result + member.hashCode();
     147        result = prime * result + role.hashCode();
    140148        return result;
    141149    }
     
    143151    @Override
    144152    public boolean equals(Object obj) {
    145         if (this == obj)
    146             return true;
    147         if (obj == null)
     153        if (obj instanceof RelationMember) {
     154            RelationMember other = (RelationMember) obj;
     155            return member.equals(other.getMember()) && role.equals(other.getRole());
     156        } else {
    148157            return false;
    149         if (getClass() != obj.getClass())
    150             return false;
    151         RelationMember other = (RelationMember) obj;
    152         if (member == null) {
    153             if (other.member != null)
    154                 return false;
    155         } else if (!member.equals(other.member))
    156             return false;
    157         if (role == null) {
    158             if (other.role != null)
    159                 return false;
    160         } else if (!role.equals(other.role))
    161             return false;
    162         return true;
     158        }
    163159    }
    164160}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r2120 r2206  
    582582            //    System.out.println("member " + m.member + " selected " + r.selected);
    583583
    584             if(m.getMember() == null) {
    585                 // TODO Nullable member will not be allowed after RelationMember.member is encalupsed
    586                 r.putError(tr("Empty member in relation."), true);
    587             } else if(m.getMember().isDeleted()) {
     584            if (m.getMember().isDeleted()) {
    588585                r.putError(tr("Deleted member ''{0}'' in relation.",
    589586                        m.getMember().getDisplayName(DefaultNameFormatter.getInstance())), true);
     
    678675                if("-1".equals(onewayviastr)) {
    679676                    onewayvia = true;
    680                     Node t = firstNode;
    681677                    firstNode = lastNode;
    682678                    lastNode = firstNode;
     
    851847        for (RelationMember m : r.getMembers())
    852848        {
    853             if(m.getMember() == null) {
    854                 //TODO Remove useless nullcheck when RelationMember.member is encalupsed
    855                 r.putError(tr("Empty member in relation."), true);
    856             } else if(m.getMember().isDeleted()) {
     849            if (m.getMember().isDeleted()) {
    857850                r.putError(tr("Deleted member ''{0}'' in relation.",
    858851                        m.getMember().getDisplayName(DefaultNameFormatter.getInstance())), true);
Note: See TracChangeset for help on using the changeset viewer.