View Javadoc
1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   */
18  
19  package org.itracker.model;
20  
21  import org.apache.commons.lang.builder.CompareToBuilder;
22  import org.apache.commons.lang.builder.ToStringBuilder;
23  
24  import java.util.Comparator;
25  
26  /**
27   * Models a language entry.
28   *
29   * @author ready
30   */
31  public class Language extends AbstractEntity {
32  
33  
34      /**
35       *
36       */
37      private static final long serialVersionUID = 1L;
38  
39      private String locale;
40  
41      private String resourceKey;
42  
43      private String resourceValue;
44  
45      /**
46       * Default constructor (required by Hibernate).
47       * <p/>
48       * <p>
49       * PENDING: should be <code>private</code> so that it can only be used by
50       * Hibernate, to ensure that the fields which form an instance's identity
51       * are always initialized/never <tt>null</tt>.
52       * </p>
53       */
54      public Language() {
55      }
56  
57      public Language(String locale, String key) {
58          setLocale(locale);
59          setResourceKey(key);
60      }
61  
62      /**
63       * Convenience constructor to set the value too.
64       */
65      public Language(String locale, String key, String value) {
66          this(locale, key);
67          setResourceValue(value);
68      }
69  
70      public String getLocale() {
71          return locale;
72      }
73  
74      public void setLocale(String locale) {
75          if (locale == null) {
76              throw new IllegalArgumentException("null locale");
77          }
78          this.locale = locale;
79      }
80  
81      public String getResourceKey() {
82          return resourceKey;
83      }
84  
85      public void setResourceKey(String resourceKey) {
86          if (resourceKey == null) {
87              throw new IllegalArgumentException("null resourceKey");
88          }
89          this.resourceKey = resourceKey;
90      }
91  
92      public String getResourceValue() {
93          return resourceValue;
94      }
95  
96      public void setResourceValue(String resourceValue) {
97          this.resourceValue = resourceValue;
98      }
99  
100     // @Override
101     // public boolean equals(Object obj) {
102     // if (this == obj) {
103     // return true;
104     // }
105     //
106     // if (obj instanceof Language) {
107     // final Language other = (Language)obj;
108     //
109     // return this.resourceKey.equals(other.resourceKey)
110     // && this.locale.equals(other.locale);
111     // }
112     // return false;
113     // }
114     //
115     // @Override
116     // public int hashCode() {
117     // return this.resourceKey.hashCode() + this.locale.hashCode();
118     // }
119     //
120     @Override
121     public String toString() {
122         return new ToStringBuilder(this).append("id", getId()).append("resourceKey",
123                 getResourceKey()).append("locale", getLocale()).append("value", getResourceValue()).toString();
124     }
125 
126     public static final Comparator<Language> KEY_COMPARATOR = new LanguageKeyComparator();
127 
128     private static class LanguageKeyComparator implements Comparator<Language> {
129 
130         public int compare(Languageef="../../../org/itracker/model/Language.html#Language">Language o1, Language o2) {
131             return new CompareToBuilder().append(o1.getResourceKey(), o2.getResourceKey()).append(o1.getLocale(), o2.getLocale()).append(o1.getId(), o2.getId()).toComparison();
132         }
133 
134     }
135 
136     public static final Comparator<Language> VALUE_COMPARATOR = new LanguageValueComparator();
137 
138     private static class LanguageValueComparator implements Comparator<Language> {
139 
140         public int compare(Languageef="../../../org/itracker/model/Language.html#Language">Language o1, Language o2) {
141             return new CompareToBuilder()
142                     .append(o1.getResourceValue(), o2.getResourceValue())
143                     .append(o1.getResourceKey(), o2.getResourceKey())
144                     .append(o1.getId(), o2.getId()).toComparison();
145         }
146 
147     }
148 
149 }