View Javadoc

1   package uk.ac.ebi.intenz.domain.enzyme;
2   
3   import uk.ac.ebi.intenz.domain.constants.EnzymeSourceConstant;
4   import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
5   
6   /**
7    * This class represents a comment of an enzyme entry.
8    * <p/>
9    * Instances of this class are immutable.
10   *
11   * @author Michael Darsow
12   * @version $Revision: 1.2 $ $Date: 2008/01/28 12:33:00 $
13   */
14  public class EnzymeComment implements Viewable {
15  
16    private String commentText;
17  
18    private EnzymeSourceConstant source;
19  
20    private EnzymeViewConstant view;
21  
22    /**
23     * Returns a <code>EnzymeComment</code> instance.
24     *
25     * @param commentText The actual comment.
26     * @param source      The comment's source.
27     * @param view        The view(s) where this comment will be displayed.
28     * @throws NullPointerException     if <code>commentText</code> or <code>source</code> are <code>null</code>.
29     * @throws IllegalArgumentException if <code>commentText</code> is empty.
30     */
31    public EnzymeComment(String commentText, EnzymeSourceConstant source, EnzymeViewConstant view) {
32      if (commentText == null) throw new NullPointerException("Parameter 'commentText' must not be null.");
33      if (source == null) throw new NullPointerException("Parameter 'source' must not be null.");
34      if (view == null) throw new NullPointerException("Parameter 'view' must not be null.");
35      if (commentText.equals("")) throw new IllegalArgumentException("Parameter 'commentText' must not be empty.");
36      this.commentText = commentText;
37      this.source = source;
38      this.view = view;
39    }
40  
41    /**
42     * Standard equals method.
43     *
44     * @param o Object to be compared to this one.
45     * @return <code>true</code> if the objects are equal.
46     */
47    public boolean equals(Object o) {
48      if (this == o) return true;
49      if (!(o instanceof EnzymeComment)) return false;
50  
51      final EnzymeComment comment = (EnzymeComment) o;
52  
53      if (commentText != null ? !commentText.equals(comment.commentText) : comment.commentText != null) return false;
54      if (source != null ? !source.equals(comment.source) : comment.source != null) return false;
55      if (view != null ? !view.equals(comment.view) : comment.view != null) return false;
56  
57      return true;
58    }
59  
60    /**
61     * Returns the hash code of this object.
62     *
63     * @return the hash code of this object.
64     */
65    public int hashCode() {
66      int result;
67      result = (commentText != null ? commentText.hashCode() : 0);
68      result = 29 * result + (source != null ? source.hashCode() : 0);
69      result = 29 * result + (view != null ? view.hashCode() : 0);
70      return result;
71    }
72  
73  
74    // ----------------  GETTER ------------------
75  
76    public String getCommentText() {
77      return commentText;
78    }
79  
80    public EnzymeSourceConstant getSource() {
81      return source;
82    }
83  
84    public EnzymeViewConstant getView() {
85      return view;
86    }
87  
88  }