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

java.lang.Object
  extended by org.openstreetmap.osmosis.core.domain.v0_6.Entity
All Implemented Interfaces:
Storeable
Direct Known Subclasses:
Bound, Node, Relation, Way

public abstract class Entity
extends java.lang.Object
implements Storeable

A data class representing a single OSM entity. All top level data types inherit from this class.

Author:
Brett Henderson

Constructor Summary
Entity(CommonEntityData entityData)
          Creates a new instance.
Entity(long id, int version, java.util.Date timestamp, OsmUser user, long changesetId)
          Creates a new instance.
Entity(long id, int version, java.util.Date timestamp, OsmUser user, long changesetId, java.util.Collection<Tag> tags)
          Creates a new instance.
Entity(long id, int version, TimestampContainer timestampContainer, OsmUser user, long changesetId)
          Creates a new instance.
Entity(long id, int version, TimestampContainer timestampContainer, OsmUser user, long changesetId, java.util.Collection<Tag> tags)
          Creates a new instance.
Entity(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.
abstract  EntityType getType()
          Returns the specific data type represented by this entity.
 OsmUser getUser()
          Returns the user who last edited the entity.
 int getVersion()
          Gets the version.
abstract  Entity getWriteableInstance()
          Returns a writeable instance of this entity.
 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

Entity

public Entity(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.

Entity

public Entity(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.

Entity

public Entity(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.

Entity

public Entity(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.

Entity

public Entity(CommonEntityData entityData)
Creates a new instance.

Parameters:
entityData - The data to store in the entity. This instance is used directly and is not cloned.

Entity

public Entity(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".

getType

public abstract EntityType getType()
Returns the specific data type represented by this entity.

Returns:
The entity type enum value.

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 abstract Entity getWriteableInstance()
Returns a writeable instance of this entity. 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 entity.