Author: agilliland Date: Tue Jun 26 21:29:30 2007 New Revision: 551034 URL: http://svn.apache.org/viewvc?view=rev&rev=551034 Log: implementing comparable and defining a natural sort order for categories, by name. also cleaning up unused code and comments.
Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogCategory.java Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogCategory.java URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogCategory.java?view=diff&rev=551034&r1=551033&r2=551034 ============================================================================== --- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogCategory.java (original) +++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogCategory.java Tue Jun 26 21:29:30 2007 @@ -27,7 +27,6 @@ import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.apache.roller.weblogger.WebloggerException; import org.apache.roller.weblogger.business.RollerFactory; import org.apache.roller.weblogger.business.WeblogManager; @@ -37,18 +36,15 @@ /** * Weblog Category. * - * @ejb:bean name="WeblogCategory" * @hibernate.cache usage="read-write" * @hibernate.class lazy="true" table="weblogcategory" - * @struts.form include-all="true" */ -public class WeblogCategory implements Serializable { +public class WeblogCategory implements Serializable, Comparable { public static final long serialVersionUID = 1435782148712018954L; private static Log log = LogFactory.getLog(WeblogCategory.class); - // attributes private String id = UUIDGenerator.generateUUID(); private String name = null; @@ -68,9 +64,9 @@ public WeblogCategory( Weblog website, WeblogCategory parent, - java.lang.String name, - java.lang.String description, - java.lang.String image) { + String name, + String description, + String image) { this.name = name; this.description = description; @@ -90,26 +86,6 @@ } - public WeblogCategory(WeblogCategory otherData) { - this.setData(otherData); - } - - - public void setData(WeblogCategory otherData) { - WeblogCategory other = (WeblogCategory) otherData; - - this.id = other.getId(); - this.website = other.getWebsite(); - this.name = other.getName(); - this.description = other.getDescription(); - this.image = other.getImage(); - this.path = other.getPath(); - - this.parentCategory = other.getParent(); - this.childCategories = other.getWeblogCategories(); - } - - //------------------------------------------------------- Good citizenship public String toString() { @@ -142,22 +118,25 @@ .toHashCode(); } + /** + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Object o) { + WeblogCategory other = (WeblogCategory)o; + return getName().compareTo(other.getName()); + } + /** * Database surrogate key. * - * @roller.wrapPojoMethod type="simple" - * - * @hibernate.id column="id" - * generator-class="assigned" + * @hibernate.id column="id" generator-class="assigned" */ - public java.lang.String getId() { + public String getId() { return this.id; } - public void setId(java.lang.String id) { - // Form bean workaround: empty string is never a valid id - if (id != null && id.trim().length() == 0) return; + public void setId(String id) { this.id = id; } @@ -165,15 +144,13 @@ /** * The display name for this category. * - * @roller.wrapPojoMethod type="simple" - * * @hibernate.property column="name" non-null="true" unique="false" */ - public java.lang.String getName() { + public String getName() { return this.name; } - public void setName(java.lang.String name) { + public void setName(String name) { this.name = name; } @@ -181,15 +158,13 @@ /** * A full description for this category. * - * @roller.wrapPojoMethod type="simple" - * * @hibernate.property column="description" non-null="true" unique="false" */ - public java.lang.String getDescription() { + public String getDescription() { return this.description; } - public void setDescription(java.lang.String description) { + public void setDescription(String description) { this.description = description; } @@ -197,15 +172,13 @@ /** * An image icon to represent this category. * - * @roller.wrapPojoMethod type="simple" - * * @hibernate.property column="image" non-null="true" unique="false" */ - public java.lang.String getImage() { + public String getImage() { return this.image; } - public void setImage(java.lang.String image) { + public void setImage(String image) { this.image = image; } @@ -213,8 +186,6 @@ /** * The full path to this category in the hierarchy. * - * @roller.wrapPojoMethod type="simple" - * * @hibernate.property column="path" non-null="true" unique="false" */ public String getPath() { @@ -229,8 +200,6 @@ /** * Get the weblog which owns this category. * - * @roller.wrapPojoMethod type="pojo" - * * @hibernate.many-to-one column="websiteid" cascade="none" not-null="true" */ public Weblog getWebsite() { @@ -245,8 +214,6 @@ /** * Get parent category, or null if category is root of hierarchy. * - * @roller.wrapPojoMethod type="pojo" - * * @hibernate.many-to-one column="parentid" cascade="none" not-null="false" */ public WeblogCategory getParent() { @@ -264,7 +231,6 @@ * @hibernate.collection-key column="parentid" * @hibernate.collection-one-to-many class="org.apache.roller.weblogger.pojos.WeblogCategory" * @hibernate.set lazy="true" inverse="true" cascade="delete" - * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojos.WeblogCategory" */ public Set getWeblogCategories() { return this.childCategories; @@ -279,8 +245,6 @@ * Retrieve all weblog entries in this category and, optionally, include * weblog entries all sub-categories. * - * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojos.WeblogEntryData" - * * @param subcats True if entries from sub-categories are to be returned. * @return List of WeblogEntryData objects. * @throws WebloggerException @@ -335,8 +299,6 @@ /** * Is this category a descendent of the other category? - * - * @roller.wrapPojoMethod type="simple" */ public boolean descendentOf(WeblogCategory ancestor) { @@ -353,8 +315,6 @@ /** * Determine if category is in use. Returns true if any weblog entries * use this category or any of it's subcategories. - * - * @roller.wrapPojoMethod type="simple" */ public boolean isInUse() { try { @@ -363,8 +323,6 @@ throw new RuntimeException(e); } } - /** TODO: fix form generation so this is not needed. */ - public void setInUse(boolean dummy) {} // convenience method for updating the category name, which triggers a path tree rebuild