org.openstreetmap.osmosis.core.domain.v0_6
Class CommonEntityData

java.lang.Object
  extended by org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData
All Implemented Interfaces:
Storeable

public class CommonEntityData
extends java.lang.Object
implements Storeable

Contains data common to all entity types. This is separated from the entity class to allow it to be instantiated before all the data required for a full entity is available.


Constructor Summary
CommonEntityData(long id, int version, java.util.Date timestamp, OsmUser user, long changesetId)
          Creates a new instance.
CommonEntityData(long id, int version, java.util.Date timestamp, OsmUser user, long changesetId, java.util.Collection<Tag> tags)
          Creates a new instance.
CommonEntityData(long id, int version, TimestampContainer timestampContainer, OsmUser user, long changesetId)
          Creates a new instance.
CommonEntityData(long id, int version, TimestampContainer timestampContainer, OsmUser user, long changesetId, java.util.Collection<Tag> tags)
          Creates a new instance.
CommonEntityData(StoreReader sr, StoreClassRegister scr)
          Creates a new instance.
 
Method Summary
protected  void assertWriteable()
          Ensures that the object is writeable.
protected  int compareTags(java.util.Collection<Tag> comparisonTags)
          Compares the tags on this entity to the specified tags.
 long getChangesetId()
          Gets the id of the changeset that this version of the entity was created by.
 java.lang.String getFormattedTimestamp(TimestampFormat timestampFormat)
          Gets the timestamp in a string format.
 long getId()
          Gets the identifier.
 java.util.Collection<Tag> getTags()
          Returns the attached tags.
 java.util.Date getTimestamp()
          Gets the timestamp in date form.
 TimestampContainer getTimestampContainer()
          Gets the timestamp container object which may hold the timestamp in a different format.
 OsmUser getUser()
          Returns the user who last edited the entity.
 int getVersion()
          Gets the version.
 CommonEntityData getWriteableInstance()
          Returns a writeable instance of this object.
 boolean isReadOnly()
          Indicates if the object has been set to read-only.
 void makeReadOnly()
          Configures the object to be read-only.
 void setChangesetId(long changesetId)
          Sets the id of the changeset that this version of the entity was created by.
 void setId(long id)
          Sets the identifier.
 void setTimestamp(java.util.Date timestamp)
          Sets the timestamp in date form.
 void setTimestampContainer(TimestampContainer timestampContainer)
          Sets the timestamp container object allowing the timestamp to be held in a different format.
 void setUser(OsmUser user)
          Sets the last modification user.
 void setVersion(int version)
          Sets the version.
 void store(StoreWriter sw, StoreClassRegister scr)
          Stores all state to the specified store writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommonEntityData

public CommonEntityData(long id,
                        int version,
                        java.util.Date timestamp,
                        OsmUser user,
                        long changesetId)
Creates a new instance.

Parameters:
id - The unique identifier.
version - The version of the entity.
timestamp - The last updated timestamp.
user - The user that last modified this entity.
changesetId - The id of the changeset that this version of the entity was created by.

CommonEntityData

public CommonEntityData(long id,
                        int version,
                        TimestampContainer timestampContainer,
                        OsmUser user,
                        long changesetId)
Creates a new instance.

Parameters:
id - The unique identifier.
version - The version of the entity.
timestampContainer - The container holding the timestamp in an alternative timestamp representation.
user - The user that last modified this entity.
changesetId - The id of the changeset that this version of the entity was created by.

CommonEntityData

public CommonEntityData(long id,
                        int version,
                        java.util.Date timestamp,
                        OsmUser user,
                        long changesetId,
                        java.util.Collection<Tag> tags)
Creates a new instance.

Parameters:
id - The unique identifier.
version - The version of the entity.
timestamp - The last updated timestamp.
user - The user that last modified this entity.
changesetId - The id of the changeset that this version of the entity was created by.
tags - The tags to apply to the object.

CommonEntityData

public CommonEntityData(long id,
                        int version,
                        TimestampContainer timestampContainer,
                        OsmUser user,
                        long changesetId,
                        java.util.Collection<Tag> tags)
Creates a new instance.

Parameters:
id - The unique identifier.
version - The version of the entity.
timestampContainer - The container holding the timestamp in an alternative timestamp representation.
user - The user that last modified this entity.
changesetId - The id of the changeset that this version of the entity was created by.
tags - The tags to apply to the object.

CommonEntityData

public CommonEntityData(StoreReader sr,
                        StoreClassRegister scr)
Creates a new instance.

Parameters:
sr - The store to read state from.
scr - Maintains the mapping between classes and their identifiers within the store.
Method Detail

store

public void store(StoreWriter sw,
                  StoreClassRegister scr)
Stores all state to the specified store writer.

Specified by:
store in interface Storeable
Parameters:
sw - The writer that persists data to an underlying store.
scr - Maintains the mapping between classes and their identifiers within the store.

compareTags

protected int compareTags(java.util.Collection<Tag> comparisonTags)
Compares the tags on this entity to the specified tags. The tag comparison is based on a comparison of key and value in that order.

Parameters:
comparisonTags - The tags to compare to.
Returns:
0 if equal, < 0 if considered "smaller", and > 0 if considered "bigger".

getId

public long getId()
Gets the identifier.

Returns:
The id.

setId

public void setId(long id)
Sets the identifier.

Parameters:
id - The identifier.

getVersion

public int getVersion()
Gets the version.

Returns:
The version.

setVersion

public void setVersion(int version)
Sets the version.

Parameters:
version - The version.

getTimestamp

public java.util.Date getTimestamp()
Gets the timestamp in date form. This is the standard method for retrieving timestamp information.

Returns:
The timestamp.

setTimestamp

public void setTimestamp(java.util.Date timestamp)
Sets the timestamp in date form. This is the standard method of updating a timestamp.

Parameters:
timestamp - The timestamp.

getTimestampContainer

public TimestampContainer getTimestampContainer()
Gets the timestamp container object which may hold the timestamp in a different format. This is most useful if creating new copies of entities because it can avoid the need to parse timestamp information into Date form.

Returns:
The timestamp container.

setTimestampContainer

public void setTimestampContainer(TimestampContainer timestampContainer)
Sets the timestamp container object allowing the timestamp to be held in a different format. This should be used if a date is already held in a timestamp container, or if date parsing can be avoided.

Parameters:
timestampContainer - The timestamp container.

getFormattedTimestamp

public java.lang.String getFormattedTimestamp(TimestampFormat timestampFormat)
Gets the timestamp in a string format. If the entity already contains a string in string format it will return the original unparsed string instead of formatting a date object.

Parameters:
timestampFormat - The formatter to use for formatting the timestamp into a string.
Returns:
The timestamp string.

getUser

public OsmUser getUser()
Returns the user who last edited the entity.

Returns:
The user.

setUser

public void setUser(OsmUser user)
Sets the last modification user.

Parameters:
user - The user.

getChangesetId

public long getChangesetId()
Gets the id of the changeset that this version of the entity was created by.

Returns:
The changeset id.

setChangesetId

public void setChangesetId(long changesetId)
Sets the id of the changeset that this version of the entity was created by.

Parameters:
changesetId - The changeset id.

getTags

public java.util.Collection<Tag> getTags()
Returns the attached tags. If the class is read-only, the collection will be read-only.

Returns:
The tagList.

isReadOnly

public boolean isReadOnly()
Indicates if the object has been set to read-only. A read-only object must be cloned in order to make updates. This allows objects shared between multiple threads to be locked for thread safety.

Returns:
True if the object is read-only.

assertWriteable

protected void assertWriteable()
Ensures that the object is writeable. If not an exception will be thrown. This is intended to be called within all update methods.


makeReadOnly

public void makeReadOnly()
Configures the object to be read-only. This should be called if the object is to be processed by multiple threads concurrently. It updates the read-only status of the object, and makes all collections unmodifiable. This must be overridden by sub-classes to make their own collections unmodifiable.


getWriteableInstance

public CommonEntityData getWriteableInstance()
Returns a writeable instance of this object. If the object is read-only a clone is created, if it is already writeable then this object is returned.

Returns:
A writeable instance of this object.