Class Nengo

java.lang.Object
net.time4j.calendar.Nengo
All Implemented Interfaces:
Serializable, CalendarEra

public final class Nengo extends Object implements CalendarEra, Serializable
The system of Japanese eras from AD 701 until today.

It is possible to register a new nengo by setting the system property "net.time4j.calendar.japanese.supplemental.era". Its value is a sequence of key-value-pairs (without any space or tab). The keys "name" (given in romaji), "kanji" (japanese - 2 chars) and "since" (ISO-8601-date) are mandatory. If necessary, the optional keys "chinese" (2 chars), "korean" or "russian" can be specified, too. Example:

"-Dnet.time4j.calendar.japanese.supplemental.era name=newEra,kanji=KK,since=9999-12-31"

Since:
3.32/4.27
Author:
Meno Hochschild
See Also:
Serialized Form
  • Field Details

    • MEIJI

      public static final Nengo MEIJI

      Meji is valid from year 1868 until 1912-07-29.

      It uses the lunisolar calendar until end of year 1872.

    • TAISHO

      public static final Nengo TAISHO

      Taishō is valid from 1912-07-30 until 1926-12-24.

    • SHOWA

      public static final Nengo SHOWA

      Shōwa is valid from 1926-12-25 until 1989-01-07.

    • HEISEI

      public static final Nengo HEISEI

      Heisei is valid from 1989-01-08 until 2019-04-30 (emperor Akihito).

    • REIWA

      public static final Nengo REIWA

      Reiwa is valid from 2019-05-01 onwards (emperor Naruhito).

      Since:
      5.3
    • NEWEST

      public static final Nengo NEWEST

      The newest known nengo.

    • SELECTOR

      public static final AttributeKey<Nengo.Selector> SELECTOR
      Format attribute which helps to resolve possible ambivalences in parsing.

      Standard value is: Nengo.Selector.OFFICIAL

  • Method Details

    • ofRelatedGregorianYear

      public static Nengo ofRelatedGregorianYear(int year)

      Obtains the official nengo for given related gregorian year.

      In case two or more nengos happen for one given year, Time4J will choose the latest nengo whose first related gregorian year is still smaller than or equal to given year.

      Parameters:
      year - the gregorian year which relates to the first day of any Japanese year (New Year)
      Returns:
      found nengo
      Throws:
      IllegalArgumentException - if no suitable nengo could be found for given year
      See Also:
      Nengo.Selector.OFFICIAL, ofRelatedGregorianYear(int, Selector)
    • ofRelatedGregorianYear

      public static Nengo ofRelatedGregorianYear(int year, Nengo.Selector selector)

      Obtains the nengo for given related gregorian year and selector strategy.

      In case two or more nengos happen for one given year, Time4J will choose the latest nengo whose first related gregorian year is still smaller than or equal to given year.

      Parameters:
      year - the gregorian year which relates to the first day of any Japanese year (New Year)
      selector - strategy how to select nengos
      Returns:
      found nengo
      Throws:
      IllegalArgumentException - if no suitable nengo could be found for given parameters
    • ofKanji

      public static Nengo ofKanji(String kanji)

      Tries to find a suitable nengo for given japanese kanji representation.

      Parameters:
      kanji - the representation in japanese kanji
      Returns:
      suitable nengo with same kanji
      Throws:
      IllegalArgumentException - if no suitable nengo could be found for given kanji representation
    • parseRomaji

      public static List<Nengo> parseRomaji(String romaji)

      Tries to find suitable nengos for given representation in romaji.

      The internal parser is case-insensitive and able to translate vowels with circumflex into vowels with macron. Some labels are ambivalent. One single nengo can even have more than one romaji representation. For example, the label "Shōwa" has existed three times in history (for different nengos). Here the first nengo "Jōwa" (year 834) was also read as "Shōwa".

      Parameters:
      romaji - the representation in romaji (hepburn variant)
      Returns:
      unmodifiable list of suitable nengos maybe empty
    • stream

      public static Stream<Nengo> stream()

      Obtains a stream of all official nengos in chronological ascending order.

      Returns:
      stream of nengos
      See Also:
      Nengo.Selector.OFFICIAL, stream(Selector)
    • stream

      public static Stream<Nengo> stream(Nengo.Selector selector)

      Obtains a stream of all nengos in chronological ascending order selected by given selector.

      Parameters:
      selector - strategy how to select nengos
      Returns:
      stream of nengos
    • list

      public static List<Nengo> list()

      Obtains a list of all official nengos in chronological ascending order.

      Returns:
      unmodifiable list of nengos
      See Also:
      Nengo.Selector.OFFICIAL, list(Selector)
    • list

      public static List<Nengo> list(Nengo.Selector selector)

      Obtains a list of all nengos in chronological ascending order selected by given selector.

      Parameters:
      selector - strategy how to select nengos
      Returns:
      unmodifiable list of nengos
    • matches

      public boolean matches(Nengo.Selector selector)

      Does this nengo match given selector?

      Parameters:
      selector - strategy how to select nengos
      Returns:
      true if given selector would select this nengo else false
    • getFirstRelatedGregorianYear

      public int getFirstRelatedGregorianYear()

      Obtains the gregorian year which relates to the first day of associated Japanese year where this nengo was used the first time.

      Returns:
      related gregorian year
      See Also:
      getStart()
    • getStart

      public PlainDate getStart()

      Obtains the first date when this nengo took effect.

      Due to the differences between old Japanese calendar and modern gregorian variant, it is possible that the year of start date deviates from the related gregorian year. An example is the nengo Eichō with the related gregorian year 1096 although it started first on AD-1096-01-03 (julian).

      Returns:
      gregorian date of first introduction of this nengo
      See Also:
      getFirstRelatedGregorianYear()
    • isModern

      public boolean isModern()

      Determines if this nengo is used by modern Japan (since Meiji).

      Returns:
      boolean
    • getDisplayName

      public String getDisplayName(Locale locale)

      Equivalent to getDisplayName(locale, TextWidth.WIDE).

      Parameters:
      locale - the language which determines the name to be displayed
      Returns:
      localized display name
      See Also:
      getDisplayName(Locale, TextWidth)
    • getDisplayName

      public String getDisplayName(Locale locale, TextWidth width)

      Obtains the localized name.

      For all modern nengos (Meiji or later), the display name will be determined on base of best efforts, possibly in narrow or abbreviated notation, too. However, older nengos are localized in a simplified manner: There is no support for abbreviated or narrow text forms, and the localization is limited to the languages Japanese, Chinese, Korean and Russian (based on Wikipedia). All other languages will be printed using the hebonshiki romaji system.

      Parameters:
      locale - the language which determines the name to be displayed
      width - text width (not relevant for older nengos)
      Returns:
      localized display name
    • findNext

      public Optional<Nengo> findNext()

      Tries to find the next nengo in chronological order.

      Note: If this nengo represents a nengo of northern court in the Nanboku-chō period (1336-1392) then the next nengo will be the next one of northern court only but not of southern court. If this nengo is the last one of northern court then the next nengo will be Ōei (1394).

      Returns:
      next nengo which is only present if this nengo is not the newest nengo
    • findPrevious

      public Optional<Nengo> findPrevious()

      Tries to find the previous nengo in chronological order.

      Note: If this nengo represents a nengo of northern court in the Nanboku-chō period (1336-1392) then the previous nengo will be the previous one of northern court only but not of southern court. If this nengo is the first one of northern court then the previous nengo will be Genkō: (1391).

      Returns:
      previous nengo which is only present if this nengo is not the first nengo
    • name

      public String name()

      Obtains a descriptive text with romaji and the relevant year interval.

      Specified by:
      name in interface CalendarEra
      Returns:
      String
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object