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

Minor optimalizations

File:
1 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    }
Note: See TracChangeset for help on using the changeset viewer.