View Javadoc

1   package org.varienaja.comments;
2   
3   import java.io.Serializable;
4   
5   /**
6    * Class representing an element of a Comment. An element is either normal text,
7    * a Band, a Song, a Keyword, a Playlist or an Artist. The special elementtypes
8    * can be used to create hyperlinks, pointing to a page with more information.
9    * @author Varienaja
10   * @version $Id: CommentElement.java,v 1.1 2010/03/16 18:55:42 varienaja Exp $
11   */
12  public class CommentElement implements Serializable {
13  	private static final long serialVersionUID = 20080224172314L;
14  	
15  	private String _text;
16  	private long _id;
17  	private char _type;
18  	
19  	/**
20  	 * Creates a CommentElement of type 'T' with an empty string as text and an id of -1.
21  	 */
22  	public CommentElement() {
23  		_type = 'T';
24  		_text = "";
25  		_id = -1L;
26  	}
27  	
28  	public String getText() {
29  		return _text;
30  	}
31  	
32  	public void setText(String text) {
33  		_text = text;
34  	}
35  	
36  	public long getId() {
37  		return _id;
38  	}
39  	
40  	public void setId(long id) {
41  		_id = id;
42  	}
43  	
44  	/**
45  	 * Sets the type of the reviewelement. This can be any of the values:
46  	 * <ul>
47  	 * <li>T : Normal text</li>
48  	 * <li>B : Band</li>
49  	 * <li>P : Playlist</li>
50  	 * <li>A : Artist</li>
51  	 * <li>K : Keyword</li>
52  	 * <li>S : Song</li>
53  	 * </ul>
54  	 * @param type
55  	 */
56  	public void setType(char type) {
57  		_type = type;
58  	}
59  	
60  	public boolean isText() {
61  		return _type=='T';
62  	}
63  	
64  	public boolean isBand() {
65  		return _type=='B';
66  	}
67  
68  	public boolean isPlaylist() {
69  		return _type=='P';
70  	}
71  
72  	public boolean isSong() {
73  		return _type=='S';
74  	}
75  
76  	public boolean isArtist() {
77  		return _type=='A';
78  	}
79  
80  	public boolean isKeyword() {
81  		return _type=='K';
82  	}
83  	
84  	/**
85  	 * Returns the contents of this Item as a pair of [id,name]
86  	 * @return A pair of [id,name]
87  	 */
88  	public Object[] getInfo() {
89  		Object[] result = new Object[2];
90  		result[0] = Long.valueOf(_id);
91  		result[1] = _text;
92  		return result;
93  	}
94  	
95  	protected String getType() {
96  		return String.valueOf(_type);
97  	}
98  	
99  	public String toString() {
100 		return "["+getType()+"] "+_text;
101 	}
102 
103 }