View Javadoc

1   package org.gnomekr.potron.data;
2   
3   import java.io.Serializable;
4   import java.util.ArrayList;
5   import java.util.List;
6   import java.util.Set;
7   import java.util.StringTokenizer;
8   
9   import org.apache.commons.lang.StringUtils;
10  import org.apache.commons.lang.builder.EqualsBuilder;
11  import org.apache.commons.lang.builder.HashCodeBuilder;
12  import org.apache.commons.lang.builder.ToStringBuilder;
13  import org.gnomekr.potron.parser.ParserEntry;
14  
15  /***
16   * Entry.java
17   * @author Xavier Cho
18   * @version $Revision 1.1 $ $Date: 2005/09/11 05:49:44 $
19   * @hibernate.class table = "POTRON_TEMPL_ENTRY"
20   * @hibernate.cache usage = "nonstrict-read-write"
21   */
22  public class Entry implements Serializable {
23  
24      private static final long serialVersionUID = 4346200335447050646L;
25  
26      private long id = -1;
27      private String occurrences;
28      private String key;
29      private String pluralKey;
30      private String comment;
31      private Template template;
32      private Set<TranslatedEntry> translatedEntries;
33  
34      public Entry() {
35      }
36  
37      /***
38       * @param entry
39       */
40      public Entry(ParserEntry entry, Template template) {
41          if (entry != null) {
42              this.occurrences = entry.getReferences();
43              this.key = entry.getMsgId();
44              this.pluralKey = entry.getMsgIdPlural();
45              this.comment = entry.getComment();
46          }
47          this.template = template;
48      }
49  
50      /***
51       * @return Returns the id.
52       * @hibernate.id
53       *          column = "entry_id"
54       *          length = "20"
55       *          unsaved-value = "-1"
56       *          generator-class = "native"
57       * @hibernate.generator-param
58       *          name = "sequence"
59       *          value = "POTRON_SEQ_ENTRY"
60       */
61      public long getId() {
62          return id;
63      }
64  
65      /***
66       * @return
67       * @hibernate.property
68       *          column = "entry_name"
69       *          update = "false"
70       *          not-null = "true"
71       *          type = "text"
72       */
73      public String getKey() {
74          return key;
75      }
76  
77      /***
78       * @return
79       * @hibernate.property
80       *          column = "entry_pl_name"
81       *          update = "false"
82       *          not-null = "false"
83       *          type = "text"
84       */
85      public String getPluralKey() {
86          return pluralKey;
87      }
88  
89      /***
90       * @return
91       * @hibernate.property
92       *          column = "entry_refs"
93       *          length = "100"
94       *          update = "true"
95       *          not-null = "false"
96       */
97      public String getOccurrences() {
98          return occurrences;
99      }
100 
101     public List<String> getOccurrencesList() {
102         List<String> list = new ArrayList<String>();
103 
104         if (occurrences != null) {
105             StringTokenizer tokenizer = new StringTokenizer(occurrences);
106             while (tokenizer.hasMoreTokens()) {
107                 list.add(tokenizer.nextToken());
108             }
109         }
110 
111         return list;
112     }
113 
114     /***
115      * @return
116      * @hibernate.property
117      *          column = "comment"
118      *          update = "true"
119      *          not-null = "true"
120      *          type = "text"
121      */
122     public String getComment() {
123         return comment;
124     }
125 
126     /***
127      * @return
128      * @hibernate.many-to-one
129      *          class = "org.gnomekr.potron.data.Template"
130      *          column = "template_id"
131      */
132     public Template getTemplate() {
133         return template;
134     }
135 
136     /***
137      * @return Returns the translatedEntries.
138      * @hibernate.collection-one-to-many
139      *          class = "org.gnomekr.potron.data.TranslatedEntry"
140      * @hibernate.collection-key
141      *          column = "entry_id"
142      * @hibernate.set
143      *          lazy = "true"
144      *          inverse = "true"
145      *          cascade = "all-delete-orphan"
146      */
147     public Set<TranslatedEntry> getTranslatedEntries() {
148         return translatedEntries;
149     }
150 
151     public int getLetterCount() {
152         return key.length();
153     }
154 
155     public int getWordCount() {
156         return StringUtils.split(key).length;
157     }
158 
159     /***
160      * @param comment
161      */
162     public void setComment(String comment) {
163         this.comment = comment;
164     }
165 
166     /***
167      * @param key
168      */
169     public void setKey(String key) {
170         this.key = key;
171     }
172 
173     /***
174      * @param pluralKey
175      */
176     public void setPluralKey(String pluralKey) {
177         this.pluralKey = pluralKey;
178     }
179 
180     /***
181      * @param id The id to set.
182      */
183     public void setId(long id) {
184         this.id = id;
185     }
186 
187     /***
188      * @param occurrences
189      */
190     public void setOccurrences(String references) {
191         this.occurrences = references;
192     }
193 
194     /***
195      * @param template
196      */
197     public void setTemplate(Template template) {
198         this.template = template;
199     }
200 
201     /***
202      * @param translatedEntries The translatedEntries to set.
203      */
204     public void setTranslatedEntries(Set<TranslatedEntry> translatedEntries) {
205         this.translatedEntries = translatedEntries;
206     }
207 
208     /***
209      * @see java.lang.Object#equals(java.lang.Object)
210      */
211     public boolean equals(final Object object) {
212         if (object instanceof Entry) {
213             Entry entry = (Entry) object;
214 
215             EqualsBuilder builder = new EqualsBuilder();
216             builder.append(id, entry.getId());
217             builder.append(key, entry.getKey());
218             builder.append(pluralKey, entry.getPluralKey());
219             builder.append(comment, entry.getComment());
220             builder.append(occurrences, entry.getOccurrences());
221 
222             return builder.isEquals();
223         }
224 
225         return false;
226     }
227 
228     /***
229      * @see java.lang.Object#toString()
230      */
231     public String toString() {
232         ToStringBuilder builder = new ToStringBuilder(this);
233         builder.append("id", id);
234         builder.append("key", key);
235         builder.append("occurrences", occurrences);
236 
237         return builder.toString();
238     }
239 
240     /***
241      * @see java.lang.Object#hashCode()
242      */
243     public int hashCode() {
244         HashCodeBuilder builder = new HashCodeBuilder();
245         builder.append(id);
246         builder.append(key);
247         builder.append(pluralKey);
248         builder.append(comment);
249         builder.append(occurrences);
250 
251         return builder.toHashCode();
252     }
253 }