⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 persistentthread.java

📁 一个功能较为完善的论坛
💻 JAVA
字号:
package org.redsoft.forum.dao;

/**
 * This is a immutable value object that represents a thread(post) in a
 * forum
 *
 * @author Charles Huang
 * @since JDK 1.4
 */
import org.redsoft.forum.util.Validation;

public class PersistentThread{
    public static final String TABLE_PERSISTENCE = "threads";
    public static final String PROPERTY_TITLE = "title";
    public static final String PROPERTY_ID = "id";
    public static final String PROPERTY_AUTHOR = "author";
    public static final String PROPERTY_CONTENT = "content";
    public static final String PROPERTY_TIMESTAMP = "timestamp";
    public static final String PROPERTY_CATEGORY = "category";
    public static final String PROPERTY_PARENT_ID = "parent_id";
    public static final String PROPERTY_LAST_UPDATED ="last_update";
    public static final String PROPERTY_REPLY ="reply";
    public static final String PROPERTY_REPLIED_THREAD ="replied_thread";
    public static final String PROPERTY_CLICK ="click";
    public static final String PROPERTY_NOTIFY ="notify";


    // The thread's title
    private String title;

    // The reply of the thread
    private int reply = 0;

	// Content of the thread
	private String content;

	// Author of the thread
	private String author;

    private long id;

	// Time when this thread was posted or updated
	private long timeStamp;

    private long parentID = -1;

    private int category;

    // If to notify the author if there are replies
    private boolean notify = true;

    private long repliedThreadID;
    
	public int getClick() {
		return click;
	}

	public void setClick(int click) {
		this.click = click;
	}

	private long lastUpdated;

	private int click;

    public PersistentThread( final String title,
	               final String content,
        	       final String author,
	    	       final long timeStamp,
                   final long parent_id,
                   final int category,
                   final long lastUpdated,
                   final int reply,
                   final long repliedThreadID,
                   final boolean notify ){
        setTitle( title );
        setContent( content );
        setAuthor( author );
        setParentID( parent_id );
        setTimeStamp( timeStamp );
        setCategory( category );
        setLastUpdated( lastUpdated );
        setReply( reply );
        setRepliedThreadID( repliedThreadID );
        setNotify( notify );
	}

    public PersistentThread( final long id,
                   final String title,
	               final String content,
        	       final String author,
	    	       final long timeStamp,
                   final long parent_id,
                   final int category,
                   final long lastUpdated,
                   final int reply,
				   final int click,
				   final long repliedThreadID,
                   final boolean notify ){
        setID( id );
        setTitle( title );
        setContent( content );
        setAuthor( author );
        setParentID( parent_id );
        setTimeStamp( timeStamp );
        setCategory( category );
        setLastUpdated( lastUpdated );
        setReply( reply );
		setClick(click);
		setRepliedThreadID( repliedThreadID );
        setNotify( notify );
	}


    /**
     * Set the id of the thread
     *
     * @param id - The primary key of the thread
     */
    public void setID( long id ){
        this.id = id;
    }

    /**
     *  Return the thread id
     */
    public long getID(){
        return id;
    }

	/**
 	 * Set the title
 	 *
 	 * @param title - String The title of the thread
	 */
    public void setTitle( final String title ){
		Validation.validateNotNull( title );
		this.title = title;
	}

	/**
	 * Get the title
	 *
	 * @return
	 */
	public String getTitle(){
		return this.title;
	}

	/**
	 * Set the content
	 *
	 * @param content - String The content of the thread
	 */
	public void setContent( final String content ){
		Validation.validateNotNull( content );
		this.content = content;
	}

    /**
     * Get the content
     *
     * @return String - The content of the thread
     */
    public String getContent(){
        return this.content;
    }

    /**
	 * Set the author
	 *
	 * @param author - String The author of the thread
	 */
	public void setAuthor( final String author ){
		Validation.validateNotNull( author );
                Validation.validateString(author,1,15);
		this.author = author;
	}

    /**
     * Get the author
     *
     * @return String - The author of the thread
     */
    public String getAuthor(){
        return this.author;
    }

    /**
	 * Set the time stamp
	 *
	 * @param timestamp - The time stamp the thread was posted or updated
	 */
	public void setTimeStamp( final long timeStamp ){
		this.timeStamp = timeStamp;
	}

    /**
     * Get the timeStamp
     *
     * @return long - The author of the thread
     */
    public long getTimeStamp(){
        return this.timeStamp;
    }

    /**
	 * Set the parent id which refers to the parnet thread
	 *
	 * @param parentID - The id that refers to the parent thread
	 */
	public void setParentID( final long parentID ){
		this.parentID = parentID;
	}

     /**
     * Get the parent id that refers the parent thread
     *
     * @return long - The id that refers the parent thread
     */
    public long getParentID(){
        return this.parentID;
    }

    /**
     * Get the category
     *
     * @return int - The category that the thread belongs to
     */
    public int getCategory(){
        return this.category;
    }

    /**
	 * Set the category the thread is under
	 *
	 * @param category - The category the thread is under
	 */
	public void setCategory( final int category ){
		this.category = category;
	}

    /**
     * Get the reply of this thread
     *
     * @return int - The number of replies of the thread
     */
    public int getReply(){
        return this.reply;
    }

    /**
	 * Set the reply of this thread
	 *
	 * @param reply - The number of the replies for this thread
	 */
	public void setReply( final int reply ){
		this.reply = reply;
	}

    /**
     * Get the last reply time stamp
     *
     * @return long - The last reply time stamp
     */
    public long getLastUpdated(){
        return this.lastUpdated;
    }

    /**
	 * Set the last reply time stamp
	 *
	 * @param lastUpdated - The last reply time stamp
	 */
	public void setLastUpdated( final long lastUpdated ){
		this.lastUpdated = lastUpdated;
	}
 
    /**
     * Set the replied id of the thread
     *
     * @param id - The ID of the replied thread
     */
    public void setRepliedThreadID( long id ){
        this.repliedThreadID = id;
    }

    /**
     *  Return the replied thread id
     */
    public long getRepliedThreadID(){
        return repliedThreadID;
    }

    /**
     * Set the notify flag
     *
     * @param id - The notify flag
     */
    public void setNotify( boolean notify ){
        this.notify = notify;
    }

    /**
     *  Return notification flag
     */
    public boolean getNotify(){
        return this.notify;
    }

	/**
	 * Check if two PersistentThread are equal
	 */
	public boolean equals(Object obj) {
		if(obj instanceof PersistentThread) {
			PersistentThread pt = (PersistentThread)obj;
			if(this.getID() == pt.getID()){
				return true;
			}
		}

		return false;
	}




}//EOC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -