Class Eras

java.lang.Object
megamek.common.eras.Eras

public final class Eras extends Object
This singleton class is a handler for the Eras of the BT Universe like the Civil War or the Succession Wars. The Eras are read from the eras.xml definition file and are thus moddable. The class therefore has a few methods that deal with validation and is supposed to be resistant to wrong data.
  • Method Details

    • getInstance

      public static Eras getInstance()
      Returns:
      The sole instance of Eras. Calling this also initialises and loads the eras.
    • getEra

      public static Era getEra(LocalDate date)
      Returns the Era of the given date. For the canon eras the day makes no difference but the eras definition xml allows eras to be defined with day resolution.
      Parameters:
      date - The date to get the Era for
      Returns:
      The Era of the given date, e.g. IlClan on March 25, 3153
    • getEra

      public static Era getEra(int year)
      Returns the Era of the first day of the given year (January 1st). For the canon eras the day makes no difference but the eras definition xml allows eras to be defined with day resolution. Therefore it is preferable to use getEra(LocalDate) when a date is available.
      Parameters:
      year - The year to get the Era for
      Returns:
      The Era on January 1st of the given year
    • isThisEra

      public static boolean isThisEra(LocalDate date, Era era)
      Returns true when the given date is in the given Era.
      Parameters:
      date - The date to test
      era - The Era to check against the date
      Returns:
      True when the date is in the Era's date range
    • getEras

      public static List<Era> getEras()
      Returns a list of all Eras, ordered by their end dates, i.e. in their natural order with the oldest being first.
      Returns:
      All Eras
    • isFirstEra

      public static boolean isFirstEra(@Nullable Era era)
      Returns:
      True if the given Era is the first (earliest) of all eras.
    • previousEra

      @Nullable public static Era previousEra(@Nullable Era era)
      Returns:
      The era directly preceding the given Era, if any, null if the given Era is the first era (or null).
    • nextEra

      @Nullable public static Era nextEra(@Nullable Era era)
      Returns:
      The era directly following the given Era, if any, null if the given Era is the last era (or null).
    • startDate

      public static LocalDate startDate(Era era)
      Returns:
      The starting date of the given Era or LocalDate.MIN if the given Era is the first era.