java.lang.Object
de.powerstat.validation.values.Year
- All Implemented Interfaces:
IValueObject
,Comparable<Year>
Year.
Not DSGVO relevant.
TODO Weeks weeksWithin() = (50, 51,) 52, 53 (CalendarSystem, Country dependend ISO vs US)
TODO min, max
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final long
Year of Gregorian calendar reform.private final CalendarSystems
Calendar system.private static final String
Unsupported calendar system constant.private final long
Year. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Year
(CalendarSystems calendarSystem, long year) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionAdd years to this year.int
Compare with another object.Leap year dependent days within year.Decrement this year.boolean
Is equal with another object.int
hashCode()
Calculate hash code.Increment this year.private static boolean
isGregorianLeapYear
(long year) Is gregorian calendar leap year.private static boolean
isJulianLeapYear
(long year) Is julian calendar leap year.boolean
Calendar system dependent leap year.long
Returns the value of this Year as an long.static Months
Months within year.static Year
of
(long year) Gregorian calendar year factory.static Year
of
(CalendarSystems calendarSystem, long year) Year factory.static Year
Gregorian calendar year factory.Returns the value of this Year as an String.Subtract years from this year.toString()
Returns the string representation of this Year.
-
Field Details
-
UNSUPPORTED_CALENDAR_SYSTEM
Unsupported calendar system constant.- See Also:
-
BEFORE_GREGORIAN_YEAR
private static final long BEFORE_GREGORIAN_YEARYear of Gregorian calendar reform. TODO Country dependend.- See Also:
-
calendarSystem
Calendar system. -
year
private final long yearYear.
-
-
Constructor Details
-
Year
Constructor.- Parameters:
calendarSystem
- Calendar systemyear
- Year != 0- Throws:
NullPointerException
- When calendarSystem is nullIndexOutOfBoundsException
- When the year is 0
-
-
Method Details
-
of
Year factory.- Parameters:
calendarSystem
- Calendar systemyear
- Year != 0- Returns:
- Year object
-
of
Gregorian calendar year factory.- Parameters:
year
- Year != 0- Returns:
- Year object
-
of
Gregorian calendar year factory.- Parameters:
value
- Year != 0 string- Returns:
- Year object
-
longValue
public long longValue()Returns the value of this Year as an long.- Returns:
- The numeric value represented by this object after conversion to type long.
-
stringValue
Returns the value of this Year as an String.- Specified by:
stringValue
in interfaceIValueObject
- Returns:
- The numeric value represented by this object after conversion to type String.
-
monthsWithin
Months within year.- Returns:
- Months (12) within year
-
isJulianLeapYear
private static boolean isJulianLeapYear(long year) Is julian calendar leap year.- Parameters:
year
- Julian calendar year- Returns:
- true: is leap year; false otherwise
-
isGregorianLeapYear
private static boolean isGregorianLeapYear(long year) Is gregorian calendar leap year.- Parameters:
year
- Gregorian calendar year- Returns:
- true: is leap year; false otherwise
-
isLeapYear
public boolean isLeapYear()Calendar system dependent leap year.- Returns:
- true: is leap year; false otherwise
- Throws:
IllegalStateException
- When an unsupported calendar system is used
-
daysWithin
Leap year dependent days within year.- Returns:
- Days within year
- Throws:
IllegalStateException
- When an unsupported calendar system is used
-
hashCode
public int hashCode()Calculate hash code. -
equals
Is equal with another object. -
toString
Returns the string representation of this Year. The exact details of this representation are unspecified and subject to change, but the following may be regarded as typical: "Year[calendarSystem=GREGORIAN, year=2020]" -
compareTo
Compare with another object.- Specified by:
compareTo
in interfaceComparable<Year>
- Parameters:
obj
- Object to compare with- Returns:
- 0: equal; 1: greater; -1: smaller
- Throws:
IllegalStateException
- When the calendarSystems of the two years are not equal- See Also:
-
add
Add years to this year.- Parameters:
years
- Years to add to this year- Returns:
- New year after adding the years to this year with same calendarSystem
- Throws:
ArithmeticException
- In case of an overflow
-
subtract
Subtract years from this year.- Parameters:
years
- Years to subtract from this year- Returns:
- New year after subtracting years from this year with same calendarSystem
- Throws:
ArithmeticException
- In case of an underflow
-
increment
Increment this year.- Returns:
- New year after incrementing this year
- Throws:
ArithmeticException
- In case of an overflow
-
decrement
Decrement this year.- Returns:
- New year after decrement this year
- Throws:
ArithmeticException
- In case of an overflow
-