Ticket #4142: 4142.patch

File 4142.patch, 9.7 KB (added by taylor.smock, 16 months ago)

Extract common serialization/deserialization steps, initial functions for setting whether or not all referrers are downloaded

  • src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    Subject: [PATCH] 4142
    ---
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java b/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
    a b  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.io.IOException;
     7import java.io.ObjectInputStream;
     8import java.io.ObjectOutputStream;
    69import java.text.MessageFormat;
    710import java.time.Instant;
    811import java.util.ArrayList;
     
    130133     */
    131134    protected static final short FLAG_PRESERVED = 1 << 13;
    132135
     136    /**
     137     * Determines if the primitive has all of its referrers
     138     */
     139    protected static final short FLAG_ALL_REFERRERS_DOWNLOADED = 1 << 14;
     140
    133141    /**
    134142     * Put several boolean flags to one short int field to save memory.
    135143     * Other bits of this field are used in subclasses.
    136144     */
    137     protected volatile short flags = FLAG_VISIBLE;   // visible per default
     145    private volatile short flags = FLAG_VISIBLE;   // visible per default
    138146
    139147    /**
    140148     * The mappaint cache index for this primitive.
     
    365373        return oldFlags != flags;
    366374    }
    367375
     376    protected void writeObjectCommon(ObjectOutputStream oos) throws IOException {
     377        oos.writeLong(id);
     378        oos.writeLong(user == null ? -1 : user.getId());
     379        oos.writeInt(version);
     380        oos.writeInt(changesetId);
     381        oos.writeInt(timestamp);
     382        oos.writeObject(keys);
     383        oos.writeShort(flags);
     384    }
     385
     386    protected void readObjectCommon(ObjectInputStream ois) throws ClassNotFoundException, IOException {
     387        id = ois.readLong();
     388        final long userId = ois.readLong();
     389        user = userId == -1 ? null : User.getById(userId);
     390        version = ois.readInt();
     391        changesetId = ois.readInt();
     392        timestamp = ois.readInt();
     393        keys = (String[]) ois.readObject();
     394        flags = ois.readShort();
     395    }
     396
    368397    @Override
    369398    public void setModified(boolean modified) {
    370399        updateFlags(FLAG_MODIFIED, modified);
     
    408437        setModified(deleted ^ !isVisible());
    409438    }
    410439
     440    @Override
     441    public boolean hasDirectionKeys() {
     442        return (flags & FLAG_HAS_DIRECTIONS) != 0;
     443    }
     444
     445    @Override
     446    public boolean reversedDirection() {
     447        return (flags & FLAG_DIRECTION_REVERSED) != 0;
     448    }
     449
     450    @Override
     451    public boolean isTagged() {
     452        return (flags & FLAG_TAGGED) != 0;
     453    }
     454
     455    @Override
     456    public boolean isAnnotated() {
     457        return (flags & FLAG_ANNOTATED) != 0;
     458    }
     459
     460    @Override
     461    public boolean isHighlighted() {
     462        return (flags & FLAG_HIGHLIGHTED) != 0;
     463    }
     464
     465    @Override
     466    public boolean isDisabled() {
     467        return (flags & FLAG_DISABLED) != 0;
     468    }
     469
     470    @Override
     471    public boolean isDisabledAndHidden() {
     472        return ((flags & FLAG_DISABLED) != 0) && ((flags & FLAG_HIDE_IF_DISABLED) != 0);
     473    }
     474
     475    @Override
     476    public boolean isPreserved() {
     477        return (flags & FLAG_PRESERVED) != 0;
     478    }
     479
    411480    /**
    412481     * If set to true, this object is incomplete, which means only the id
    413482     * and type is known (type is the objects instance class)
  • src/org/openstreetmap/josm/data/osm/IPrimitive.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/data/osm/IPrimitive.java b/src/org/openstreetmap/josm/data/osm/IPrimitive.java
    a b  
    3636     */
    3737    void setModified(boolean modified);
    3838
     39    default void setReferrersDownloaded(boolean referrersDownloaded) {
     40
     41    }
     42
    3943    /**
    4044     * Checks if object is known to the server.
    4145     * Replies true if this primitive is either unknown to the server (i.e. its id
     
    7579     */
    7680    void setDeleted(boolean deleted);
    7781
     82    /**
     83     * Determines if this primitive is fully downloaded
     84     * @return {@code true} if the primitive is fully downloaded and all parents and children should be available.
     85     * {@code false} otherwise.
     86     * @since xxx
     87     */
     88    default boolean isReferrersDownloaded() {
     89        return false;
     90    }
     91
    7892    /**
    7993     * Determines if this primitive is incomplete.
    8094     * @return {@code true} if this primitive is incomplete, {@code false} otherwise
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java b/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
    a b  
    363363        updateFlags(FLAG_PRESERVED, isPreserved);
    364364    }
    365365
    366     @Override
    367     public boolean isDisabled() {
    368         return (flags & FLAG_DISABLED) != 0;
    369     }
    370 
    371     @Override
    372     public boolean isDisabledAndHidden() {
    373         return ((flags & FLAG_DISABLED) != 0) && ((flags & FLAG_HIDE_IF_DISABLED) != 0);
    374     }
    375 
    376     @Override
    377     public boolean isPreserved() {
    378         return (flags & FLAG_PRESERVED) != 0;
    379     }
    380366
    381367    @Override
    382368    public boolean isSelectable() {
     
    492478        }
    493479    }
    494480
    495     @Override
    496     public boolean isHighlighted() {
    497         return (flags & FLAG_HIGHLIGHTED) != 0;
    498     }
    499 
    500481    /*---------------
    501482     * DIRECTION KEYS
    502483     *---------------*/
     
    526507        updateFlagsNoLock(FLAG_ANNOTATED, hasKeys() && getWorkInProgressKeys().stream().anyMatch(this::hasKey));
    527508    }
    528509
    529     @Override
    530     public boolean isTagged() {
    531         return (flags & FLAG_TAGGED) != 0;
    532     }
    533 
    534     @Override
    535     public boolean isAnnotated() {
    536         return (flags & FLAG_ANNOTATED) != 0;
    537     }
    538 
    539510    protected void updateDirectionFlags() {
    540511        boolean hasDirections = false;
    541512        boolean directionReversed = false;
     
    551522        updateFlagsNoLock(FLAG_HAS_DIRECTIONS, hasDirections);
    552523    }
    553524
    554     @Override
    555     public boolean hasDirectionKeys() {
    556         return (flags & FLAG_HAS_DIRECTIONS) != 0;
    557     }
    558 
    559     @Override
    560     public boolean reversedDirection() {
    561         return (flags & FLAG_DIRECTION_REVERSED) != 0;
    562     }
    563 
    564525    /*------------
    565526     * Keys handling
    566527     ------------*/
     
    851812                throw new DataIntegrityProblemException(
    852813                        tr("Cannot merge primitives with different ids. This id is {0}, the other is {1}", id, other.getId()));
    853814
     815            setIncomplete(other.isIncomplete());
     816            super.cloneFrom(other);
    854817            setKeys(other.hasKeys() ? other.getKeys() : null);
    855             timestamp = other.timestamp;
    856818            version = other.version;
    857             setIncomplete(other.isIncomplete());
    858             flags = other.flags;
    859             user = other.user;
    860819            changesetId = other.changesetId;
    861820        } finally {
    862821            writeUnlock(locked);
  • src/org/openstreetmap/josm/data/osm/PrimitiveData.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/data/osm/PrimitiveData.java b/src/org/openstreetmap/josm/data/osm/PrimitiveData.java
    a b  
    8484
    8585    private void writeObject(ObjectOutputStream oos) throws IOException {
    8686        // since super class is not Serializable
    87         oos.writeLong(id);
    88         oos.writeLong(user == null ? -1 : user.getId());
    89         oos.writeInt(version);
    90         oos.writeInt(changesetId);
    91         oos.writeInt(timestamp);
    92         oos.writeObject(keys);
    93         oos.writeShort(flags);
     87        super.writeObjectCommon(oos);
    9488        oos.defaultWriteObject();
    9589    }
    9690
    9791    private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
    9892        // since super class is not Serializable
    99         id = ois.readLong();
    100         final long userId = ois.readLong();
    101         user = userId == -1 ? null : User.getById(userId);
    102         version = ois.readInt();
    103         changesetId = ois.readInt();
    104         timestamp = ois.readInt();
    105         keys = (String[]) ois.readObject();
    106         flags = ois.readShort();
     93        super.readObjectCommon(ois);
    10794        ois.defaultReadObject();
    10895    }
    10996
  • src/org/openstreetmap/josm/data/vector/VectorPrimitive.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/data/vector/VectorPrimitive.java b/src/org/openstreetmap/josm/data/vector/VectorPrimitive.java
    a b  
    5858        this.highlighted = highlighted;
    5959    }
    6060
    61     @Override
    62     public boolean isTagged() {
    63         return (flags & FLAG_TAGGED) != 0;
    64     }
    65 
    6661    @Override
    6762    public boolean isAnnotated() {
    6863        return this.getInterestingTags().size() - this.getKeys().size() > 0;