ischool.info340.teamE
Class Tag

java.lang.Object
  extended by ischool.info340.teamE.Tag

public class Tag
extends java.lang.Object

Represents a tag for a place that exists in a storage medium (reprented by a TagManager). Tag objects should directly mirror an item in this medium, but this cannot be guaranteed in environments with multiple theads or instances of the program running.


Constructor Summary
Tag(java.lang.String name, java.lang.String desc, int id, int parentId, int creatorId, TagManager manager)
          Creates a new instance of Tag with creator and parent loaded when needed
Tag(java.lang.String name, java.lang.String desc, int parentId, int creatorId, TagManager manager)
          Creates a new instance of a Tag, inserting it into the storage medium.
Tag(java.lang.String name, java.lang.String desc, int id, Tag parent, User creator, TagManager manager)
          Creates a new instance of Tag, automatically adds itself as one of its parents children if it is not one already.
Tag(java.lang.String name, java.lang.String desc, Tag parent, User creator, TagManager manager)
          Creates a new instance of a Tag, inserting it into the storage medium.
 
Method Summary
 boolean equals(java.lang.Object other)
           
 boolean exists()
          Returns whether or not this tag exists in the storage medium and can be used.
 java.util.Collection getChildren()
           
 User getCreator()
           
 int getCreatorId()
           
 java.lang.String getDesc()
           
 int getId()
           
 java.lang.String getName()
           
 Tag getParent()
           
 int getParentId()
           
 boolean hasParent()
           
 boolean remove()
          Removes this tag from the storage medium and prevents it from being used (unless restored)
 boolean restore()
          Restores a previously removed tag back into the storage medium and marks it as usable again.
 boolean update(java.lang.String nName, java.lang.String nDesc, int nParentId, int nCreatorId)
          Updates this Tag and saves them to the database
 boolean update(java.lang.String nName, java.lang.String nDesc, Tag nParent, User nCreator)
          Updates this Tag and saves them to the database
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tag

public Tag(java.lang.String name,
           java.lang.String desc,
           int id,
           Tag parent,
           User creator,
           TagManager manager)
Creates a new instance of Tag, automatically adds itself as one of its parents children if it is not one already.

Parameters:
name - Name of the tag
desc - Optional textual description of the tag
id - Unique identifier for the tag in the storage medium
creator - The creator of this tag
parent - The parent of this tag if it is not a root tag null otherwise
manager - Manager that connects to the medium this tag is stored in
Throws:
java.lang.IllegalArgumentException - if name, manager, or creator is null, or if id is less than 0

Tag

public Tag(java.lang.String name,
           java.lang.String desc,
           int id,
           int parentId,
           int creatorId,
           TagManager manager)
Creates a new instance of Tag with creator and parent loaded when needed

Parameters:
name - Name of the tag
desc - Optional textual description of the tag
id - Unique identifier for the tag in the storage medium
creatorId - Id of the creator of this tag
parentId - Id of the parent of this tag, -1 if it has no parent
manager - TagManager responsible for dynamically loading parent and creator
Throws:
java.lang.IllegalArgumentException - if name or manager is null, or if id or creatorId is less than 0 or if parentId is less than -1

Tag

public Tag(java.lang.String name,
           java.lang.String desc,
           int parentId,
           int creatorId,
           TagManager manager)
Creates a new instance of a Tag, inserting it into the storage medium. Creator and parent will be dynamically loaded when needed.

Parameters:
name - Name of the tag
desc - Optional textual description of the tag
creatorId - Id of the creator of this tag
parentId - Id of the parent of this tag, -1 if it has no parent
manager - TagManager responsible for dynamically loading parent and creator and insert this record
Throws:
java.lang.IllegalArgumentException - if name or manager is null, or if creatorId is less than 0 or if parentId is less than -1

Tag

public Tag(java.lang.String name,
           java.lang.String desc,
           Tag parent,
           User creator,
           TagManager manager)
Creates a new instance of a Tag, inserting it into the storage medium. Automatically adds it to its parents list of children if it is not already

Parameters:
name - Name of the tag
desc - Optional textual description of the tag
creator - The creator of this tag
parent - The parent of this tag if it is not a root tag null otherwise
manager - TagManager responsible for dynamically loading parent and creator and insert this record
Throws:
java.lang.IllegalArgumentException - if name, creator, or manager is null
Method Detail

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

getName

public java.lang.String getName()

getDesc

public java.lang.String getDesc()

getId

public int getId()

getCreatorId

public int getCreatorId()

getParentId

public int getParentId()

hasParent

public boolean hasParent()

getCreator

public User getCreator()
Returns:
The user that created this tag

getParent

public Tag getParent()
Returns:
This tag's parent or null if this is a root tag.

getChildren

public java.util.Collection getChildren()
Returns:
A collection containing all the nodes which list this node as their parent.

exists

public boolean exists()
Returns whether or not this tag exists in the storage medium and can be used.

Returns:
true if it exists in the storage medium, false otherwise.

remove

public boolean remove()
Removes this tag from the storage medium and prevents it from being used (unless restored)

Returns:
true if this operation succedes, or false otherwise

restore

public boolean restore()
Restores a previously removed tag back into the storage medium and marks it as usable again. Note that it will probably have a new id after this method is called.

Returns:
true if this operation succedes, false otherwise.
Throws:
java.lang.IllegalStateException - if this tag has not been deleted

update

public boolean update(java.lang.String nName,
                      java.lang.String nDesc,
                      int nParentId,
                      int nCreatorId)
Updates this Tag and saves them to the database

Parameters:
nName - The new name for this tag
nDesc - The new description for this tag (null for none)
nParentId - The new parent id for this tag (-1 for no parent)
nCreatorId - The new creator id for this tag
Throws:
java.lang.IllegalArgumentException - if nName is null, or if nParentId < -1 or if nCreatorId < 0

update

public boolean update(java.lang.String nName,
                      java.lang.String nDesc,
                      Tag nParent,
                      User nCreator)
Updates this Tag and saves them to the database

Parameters:
nName - The new name for this tag
nDesc - The new description for this tag (null for none)
nParent - The new parent for this tag (null for none)
nCreator - The new creator for this tag
Throws:
java.lang.IllegalArgumentException - if nName, or nCreator is null