java.lang.Object
de.powerstat.validation.values.Year
All Implemented Interfaces:
IValueObject, Comparable<Year>

public final class Year extends Object implements Comparable<Year>, IValueObject
Year. Not DSGVO relevant. TODO Weeks weeksWithin() = (50, 51,) 52, 53 (CalendarSystem, Country dependend ISO vs US) TODO min, max
  • Field Details

    • UNSUPPORTED_CALENDAR_SYSTEM

      private static final String UNSUPPORTED_CALENDAR_SYSTEM
      Unsupported calendar system constant.
      See Also:
    • BEFORE_GREGORIAN_YEAR

      private static final long BEFORE_GREGORIAN_YEAR
      Year of Gregorian calendar reform. TODO Country dependend.
      See Also:
    • calendarSystem

      private final CalendarSystems calendarSystem
      Calendar system.
    • year

      private final long year
      Year.
  • Constructor Details

  • Method Details

    • of

      public static Year of(CalendarSystems calendarSystem, long year)
      Year factory.
      Parameters:
      calendarSystem - Calendar system
      year - Year != 0
      Returns:
      Year object
    • of

      public static Year of(long year)
      Gregorian calendar year factory.
      Parameters:
      year - Year != 0
      Returns:
      Year object
    • of

      public static Year of(String value)
      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

      public String stringValue()
      Returns the value of this Year as an String.
      Specified by:
      stringValue in interface IValueObject
      Returns:
      The numeric value represented by this object after conversion to type String.
    • monthsWithin

      public static Months 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

      public Days 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.
      Overrides:
      hashCode in class Object
      Returns:
      Hash
      See Also:
    • equals

      public boolean equals(Object obj)
      Is equal with another object.
      Overrides:
      equals in class Object
      Parameters:
      obj - Object
      Returns:
      true when equal, false otherwise
      See Also:
    • toString

      public String 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]"
      Overrides:
      toString in class Object
      Returns:
      String representation of this Year
      See Also:
    • compareTo

      public int compareTo(Year obj)
      Compare with another object.
      Specified by:
      compareTo in interface Comparable<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

      public Year add(Years years)
      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

      public Year subtract(Years years)
      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

      public Year increment()
      Increment this year.
      Returns:
      New year after incrementing this year
      Throws:
      ArithmeticException - In case of an overflow
    • decrement

      public Year decrement()
      Decrement this year.
      Returns:
      New year after decrement this year
      Throws:
      ArithmeticException - In case of an overflow