|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Era.java | 66.7% | 62.5% | 54.5% | 60% |
|
1 |
/*
|
|
2 |
* Joey and its relative products are published under the terms
|
|
3 |
* of the Apache Software License.
|
|
4 |
*/
|
|
5 |
package org.asyrinx.brownie.core.util;
|
|
6 |
|
|
7 |
import java.util.Locale;
|
|
8 |
|
|
9 |
/**
|
|
10 |
* 年号を表現するクラス
|
|
11 |
*/
|
|
12 |
public final class Era { |
|
13 |
|
|
14 |
private final Locale locale;
|
|
15 |
|
|
16 |
private final SimpleDateRange range;
|
|
17 |
|
|
18 |
private final String firstLetter;
|
|
19 |
|
|
20 |
private final String caption;
|
|
21 |
|
|
22 |
private final String captionShort;
|
|
23 |
|
|
24 |
/**
|
|
25 |
* constructor
|
|
26 |
*
|
|
27 |
* @param locale
|
|
28 |
* @param caption
|
|
29 |
* @param captionShort
|
|
30 |
* @param firstLetter
|
|
31 |
* @param range
|
|
32 |
*/
|
|
33 | 34 |
public Era(Locale locale, String caption, String captionShort,
|
34 |
String firstLetter, SimpleDateRange range) { |
|
35 | 34 |
this.locale = locale;
|
36 | 34 |
this.firstLetter = firstLetter;
|
37 | 34 |
this.caption = caption;
|
38 | 34 |
this.captionShort = captionShort;
|
39 | 34 |
this.range = range;
|
40 |
} |
|
41 |
|
|
42 |
/**
|
|
43 |
* constructor
|
|
44 |
*
|
|
45 |
* @param locale
|
|
46 |
* @param caption
|
|
47 |
* @param captionShort
|
|
48 |
* @param firstLetter
|
|
49 |
* @param range
|
|
50 |
*/
|
|
51 | 0 |
public Era(Locale locale, String caption, String captionShort,
|
52 |
String firstLetter, DateRange range) { |
|
53 | 0 |
this(locale, caption, captionShort, firstLetter, new SimpleDateRange( |
54 |
range)); |
|
55 |
} |
|
56 |
|
|
57 |
/**
|
|
58 |
* constructor
|
|
59 |
*
|
|
60 |
* @param locale
|
|
61 |
* @param caption
|
|
62 |
* @param captionShort
|
|
63 |
* @param firstLetter
|
|
64 |
* @param begin
|
|
65 |
* @param end
|
|
66 |
*/
|
|
67 | 0 |
public Era(Locale locale, String caption, String captionShort,
|
68 |
String firstLetter, SimpleDate begin, SimpleDate end) { |
|
69 | 0 |
this(locale, caption, captionShort, firstLetter, new SimpleDateRange( |
70 |
begin, end)); |
|
71 |
} |
|
72 |
|
|
73 |
/**
|
|
74 |
* constructor
|
|
75 |
*
|
|
76 |
* @param locale
|
|
77 |
* @param caption
|
|
78 |
* @param captionShort
|
|
79 |
* @param firstLetter
|
|
80 |
* @param beginYear
|
|
81 |
* @param beginMonth
|
|
82 |
* @param beginDay
|
|
83 |
* @param endYear
|
|
84 |
* @param endMonth
|
|
85 |
* @param endDay
|
|
86 |
*/
|
|
87 | 34 |
public Era(Locale locale, String caption, String captionShort,
|
88 |
String firstLetter, int beginYear, int beginMonth, int beginDay, |
|
89 |
int endYear, int endMonth, int endDay) { |
|
90 | 34 |
this(locale, caption, captionShort, firstLetter, new SimpleDateRange( |
91 |
beginYear, beginMonth, beginDay, endYear, endMonth, endDay)); |
|
92 |
} |
|
93 |
|
|
94 |
/**
|
|
95 |
* @return @see java.lang.Object#toString()
|
|
96 |
*/
|
|
97 | 0 |
public String toString() {
|
98 | 0 |
return caption + "(" + range + ")"; |
99 |
} |
|
100 |
|
|
101 |
/**
|
|
102 |
*
|
|
103 |
* @param obj
|
|
104 |
* @return @see java.lang.Object#equals(java.lang.Object)
|
|
105 |
*/
|
|
106 | 20 |
public boolean equals(Object obj) { |
107 | 20 |
if (obj == null) { |
108 | 0 |
return false; |
109 | 20 |
} else if (obj instanceof Era) { |
110 | 12 |
return (obj == this); |
111 | 8 |
} else if (obj instanceof String) { |
112 | 8 |
return matchCaptions((String) obj);
|
113 |
} else {
|
|
114 | 0 |
return super.equals(obj); |
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
/**
|
|
119 |
* 年号が文字列に該当するかどうかを返す。
|
|
120 |
*
|
|
121 |
* @param str
|
|
122 |
* @return
|
|
123 |
*/
|
|
124 | 8 |
public boolean matchCaptions(String str) { |
125 | 8 |
return (str.equals(caption)) || (str.equals(captionShort))
|
126 |
|| (str.equals(firstLetter)); |
|
127 |
} |
|
128 |
|
|
129 |
/**
|
|
130 |
* 年号を表すアルファベットなどの頭文字
|
|
131 |
*
|
|
132 |
* @return
|
|
133 |
*/
|
|
134 | 4 |
public String getFirstLetter() {
|
135 | 4 |
return firstLetter;
|
136 |
} |
|
137 |
|
|
138 |
/**
|
|
139 |
* 年号を表す文字列
|
|
140 |
*
|
|
141 |
* @return
|
|
142 |
*/
|
|
143 | 5 |
public String getCaption() {
|
144 | 5 |
return caption;
|
145 |
} |
|
146 |
|
|
147 |
/**
|
|
148 |
* 年号を表す文字列の略
|
|
149 |
*
|
|
150 |
* @return
|
|
151 |
*/
|
|
152 | 4 |
public String getCaptionShort() {
|
153 | 4 |
return captionShort;
|
154 |
} |
|
155 |
|
|
156 |
/**
|
|
157 |
* @return
|
|
158 |
*/
|
|
159 | 65 |
public SimpleDateRange getRange() {
|
160 | 65 |
return range;
|
161 |
} |
|
162 |
|
|
163 |
/**
|
|
164 |
* 年号の改元日を表す日付
|
|
165 |
*/
|
|
166 | 0 |
public SimpleDate getBeginDate() {
|
167 | 0 |
return this.range.getFrom(); |
168 |
} |
|
169 |
|
|
170 |
/**
|
|
171 |
* 年号の最終日を表す日付
|
|
172 |
*
|
|
173 |
* @return
|
|
174 |
*/
|
|
175 | 0 |
public SimpleDate getEndDate() {
|
176 | 0 |
return this.range.getTo(); |
177 |
} |
|
178 |
|
|
179 |
/**
|
|
180 |
* @return
|
|
181 |
*/
|
|
182 | 0 |
public int getBeginDay() { |
183 | 0 |
return this.getRange().getFromDay(); |
184 |
} |
|
185 |
|
|
186 |
/**
|
|
187 |
* @return
|
|
188 |
*/
|
|
189 | 0 |
public int getBeginMonth() { |
190 | 0 |
return this.getRange().getFromMonth(); |
191 |
} |
|
192 |
|
|
193 |
/**
|
|
194 |
* @return
|
|
195 |
*/
|
|
196 | 22 |
public int getBeginYear() { |
197 | 22 |
return this.getRange().getFromYear(); |
198 |
} |
|
199 |
|
|
200 |
/**
|
|
201 |
* @return
|
|
202 |
*/
|
|
203 | 0 |
public int getEndDay() { |
204 | 0 |
return this.getRange().getToDay(); |
205 |
} |
|
206 |
|
|
207 |
/**
|
|
208 |
* @return
|
|
209 |
*/
|
|
210 | 0 |
public int getEndMonth() { |
211 | 0 |
return this.getRange().getToMonth(); |
212 |
} |
|
213 |
|
|
214 |
/**
|
|
215 |
* @return
|
|
216 |
*/
|
|
217 | 0 |
public int getEndYear() { |
218 | 0 |
return this.getRange().getToYear(); |
219 |
} |
|
220 |
|
|
221 |
/**
|
|
222 |
* 年号における年を西暦の年に変換する。
|
|
223 |
*/
|
|
224 | 9 |
public int toAnnoDomini(int eraYear) { |
225 | 9 |
return getBeginYear() + eraYear - 1;
|
226 |
} |
|
227 |
|
|
228 |
/**
|
|
229 |
* @return
|
|
230 |
*/
|
|
231 | 74 |
public Locale getLocale() {
|
232 | 74 |
return locale;
|
233 |
} |
|
234 |
|
|
235 |
/**
|
|
236 |
* 日付が年号で何年に当たるのかを返すメソッド。
|
|
237 |
*
|
|
238 |
* @param d
|
|
239 |
* DOCUMENT ME!
|
|
240 |
* @param era
|
|
241 |
* DOCUMENT ME!
|
|
242 |
* @return DOCUMENT ME!
|
|
243 |
*/
|
|
244 | 13 |
public int getYearAt(SimpleDate d) { |
245 | 13 |
return d.getYear() - getBeginYear() + 1;
|
246 |
} |
|
247 |
|
|
248 |
} |
|