View Javadoc

1   package uk.ac.ebi.intenz.domain.reference;
2   
3   import uk.ac.ebi.intenz.domain.constants.EnzymeSourceConstant;
4   import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
5   
6   /**
7    * This class stores additional information about patents.
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:10 $
13   */
14  public class Patent extends Reference {
15  
16    private String patentNumber;
17  
18    /**
19     * Returns a <code>Patent</code> instance.
20     *
21     * @param id           The pubId
22     * @param authors      String containing all author names.
23     * @param title        The title of the publication.
24     * @param year         The year of the publication.
25     * @param patentNumber The patent number.
26     */
27    public Patent(Long id, String authors, String title, String year, String patentNumber, EnzymeViewConstant view,
28                   EnzymeSourceConstant source) {
29      super(id, authors, title, year, view, source);
30      if (patentNumber == null) throw new NullPointerException("Parameter 'patentNumber' must not be null.");
31      this.patentNumber = patentNumber;
32    }
33  
34     /**
35     * Returns a string representation of this patent.
36     *
37     * @return the string representation.
38     */
39    public String toString() {
40      StringBuffer referenceString = new StringBuffer();
41  
42      referenceString.append(authors);
43      referenceString.append(" ");
44      referenceString.append(title);
45      if (!patentNumber.equals("")) {
46        referenceString.append("<i>");
47        referenceString.append(patentNumber);
48        referenceString.append("</i>,");
49      }
50      if (!year.equals("")) {
51        referenceString.append(year);
52      }
53  
54      return referenceString.toString();
55    }
56  
57    /**
58     * Standard <code>equals()</code> method.
59     *
60     * @param o The object to be compared to this one.
61     * @return <code>true</code> if <code>o</code> is equal to this object.
62     */
63    public boolean equals(Object o) {
64      if (this == o) return true;
65      if (!(o instanceof Patent)) return false;
66      if (!super.equals(o)) return false;
67  
68      final Patent patent = (Patent) o;
69  
70      if (patentNumber != null ? !patentNumber.equals(patent.patentNumber) : patent.patentNumber != null) return false;
71  
72      return true;
73    }
74  
75    /**
76     * Generates a hash code for this object.
77     *
78     * @return the hash code.
79     */
80    public int hashCode() {
81      int result = super.hashCode();
82      result = 29 * result + (patentNumber != null ? patentNumber.hashCode() : 0);
83      return result;
84    }
85  
86  
87    // --------------------  GETTER -----------------------
88  
89    public String getPatentNumber() {
90      return patentNumber;
91    }
92  
93    // TODO: Put method's content somewhere else.
94    public String toXML(int number, boolean intenzTextXML) {
95      StringBuffer xmlStringBuffer = new StringBuffer();
96  
97      xmlStringBuffer.append(super.toXML(number, intenzTextXML));
98      if (intenzTextXML) {
99        xmlStringBuffer.append("<issue>");
100       xmlStringBuffer.append("</issue>");
101       xmlStringBuffer.append("<patent_no>");
102       xmlStringBuffer.append(patentNumber);
103       xmlStringBuffer.append("</patent_no>");
104       xmlStringBuffer.append("<first_page>");
105       xmlStringBuffer.append("</first_page>");
106       xmlStringBuffer.append("<last_page>");
107       xmlStringBuffer.append("</last_page>");
108       xmlStringBuffer.append("<edition>");
109       xmlStringBuffer.append("</edition>");
110       xmlStringBuffer.append("<editor>");
111       xmlStringBuffer.append("</editor>");
112       xmlStringBuffer.append("<volume>");
113       xmlStringBuffer.append("</volume>");
114       xmlStringBuffer.append("<pub_place>");
115       xmlStringBuffer.append("</pub_place>");
116       xmlStringBuffer.append("<pub_company>");
117       xmlStringBuffer.append("</pub_company>");
118       xmlStringBuffer.append("<pub_med>");
119       xmlStringBuffer.append("</pub_med>");
120       xmlStringBuffer.append("<medline>");
121       xmlStringBuffer.append("</medline>");
122     } else {
123       xmlStringBuffer.append("      <issue>");
124       xmlStringBuffer.append("</issue>\n");
125       xmlStringBuffer.append("      <patent_no>");
126       xmlStringBuffer.append(patentNumber);
127       xmlStringBuffer.append("</patent_no>\n");
128       xmlStringBuffer.append("      <first_page>");
129       xmlStringBuffer.append("</first_page>\n");
130       xmlStringBuffer.append("      <last_page>");
131       xmlStringBuffer.append("</last_page>\n");
132       xmlStringBuffer.append("      <edition>");
133       xmlStringBuffer.append("</edition>\n");
134       xmlStringBuffer.append("      <editor>");
135       xmlStringBuffer.append("</editor>\n");
136       xmlStringBuffer.append("      <volume>");
137       xmlStringBuffer.append("</volume>\n");
138       xmlStringBuffer.append("      <pub_place>");
139       xmlStringBuffer.append("</pub_place>\n");
140       xmlStringBuffer.append("      <pub_company>");
141       xmlStringBuffer.append("</pub_company>\n");
142       xmlStringBuffer.append("      <pub_med>");
143       xmlStringBuffer.append("</pub_med>\n");
144       xmlStringBuffer.append("      <medline>");
145       xmlStringBuffer.append("</medline>\n");
146     }
147     return xmlStringBuffer.toString();
148   }
149 }