-
Notifications
You must be signed in to change notification settings - Fork 62
/
CyclicYear.java
151 lines (117 loc) · 3.95 KB
/
CyclicYear.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* -----------------------------------------------------------------------
* Copyright © 2013-2018 Meno Hochschild, <http://www.menodata.de/>
* -----------------------------------------------------------------------
* This file (CyclicYear.java) is part of project Time4J.
*
* Time4J is free software: You can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* Time4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Time4J. If not, see <http://www.gnu.org/licenses/>.
* -----------------------------------------------------------------------
*/
package net.time4j.calendar;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.Serializable;
/**
* <p>Represents the cyclic year used in East Asian calendars. </p>
*
* @author Meno Hochschild
* @since 3.39/4.34
* @doctags.concurrency {immutable}
*/
/*[deutsch]
* <p>Repräsentiert das zyklische Jahr, das in ostasiatischen Kalendern verwendet wird. </p>
*
* @author Meno Hochschild
* @since 3.39/4.34
* @doctags.concurrency {immutable}
*/
public final class CyclicYear
implements Comparable<CyclicYear>, Serializable {
//~ Statische Felder/Initialisierungen ------------------------------------
//~ Instanzvariablen ------------------------------------------------------
/**
* @serial the number of cyclic year
*/
private final int year;
//~ Konstruktoren ---------------------------------------------------------
private CyclicYear(int year) {
super();
if ((year < 1) || (year > 60)) {
throw new IllegalArgumentException("Out of range: " + year);
}
this.year = year;
}
//~ Methoden --------------------------------------------------------------
/**
* <p>Obtains an instance of cyclic year. </p>
*
* @param yearOfCycle year number in the range 1-60
* @return CyclicYear
* @throws IllegalArgumentException if the parameter is out of range
*/
/*[deutsch]
* <p>Liefert eine Instanz eines zyklischen Jahres. </p>
*
* @param yearOfCycle year number in the range 1-60
* @return CyclicYear
* @throws IllegalArgumentException if the parameter is out of range
*/
public static CyclicYear of(int yearOfCycle) {
return new CyclicYear(yearOfCycle);
}
/**
* <p>Obtains the associated year number in the range 1-60. </p>
*
* @return int
*/
/*[deutsch]
* <p>Liefert die Jahreszahl im Bereich 1-60. </p>
*
* @return int
*/
public int getNumber() {
return this.year;
}
@Override
public int compareTo(CyclicYear other) {
return (this.year - other.year);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof CyclicYear) {
return (this.year == ((CyclicYear) obj).year);
} else {
return false;
}
}
@Override
public int hashCode() {
return Integer.hashCode(this.year);
}
@Override
public String toString() {
return String.valueOf(this.year);
}
/**
* @serialData Checks the consistency of deserialized data
* @param in object input stream
* @throws InvalidObjectException if the year is not in range 1-60
*/
private void readObject(ObjectInputStream in)
throws InvalidObjectException {
if ((year < 1) || (year > 60)) {
throw new InvalidObjectException("Out of range: " + this.year);
}
}
}