Record Class GenerationContext

java.lang.Object
java.lang.Record
megamek.client.ratgenerator.GenerationContext
Record Components:
faction - the FactionRecord key, dotted for a sub-command; never blank
year - the year the units were rolled for
rating - the equipment rating ("A" to "F", "Keshik", "SL"), or null when none chosen
source - which generator produced the units, so a report can say where this came from

public record GenerationContext(String faction, int year, String rating, GenerationContext.Source source) extends Record
What a player chose when they generated a force: the faction and command it was rolled for, the year, and the equipment rating. The army generators put all of this on screen and then drop it the moment the units are added, which leaves the lobby holding a pile of units with no idea what they were meant to be. Capturing it lets later work organize those units the way the faction actually organizes its units.

The faction key carries the command as well: a sub-command is written as a dotted key - "FS.CH" is the Ceti Hussars of the Federated Suns, "CC.SIJ" the St. Ives Janissaries - so one string answers both "which faction" and "which command". The plain key ("FS") is the faction at large.

  • Constructor Details

    • GenerationContext

      public GenerationContext(String faction, int year, @Nullable String rating, GenerationContext.Source source)
      Creates an instance of a GenerationContext record class.
      Parameters:
      faction - the value for the faction record component
      year - the value for the year record component
      rating - the value for the rating record component
      source - the value for the source record component
  • Method Details

    • defaultFor

      public static GenerationContext defaultFor(int year)
      The fallback when a player generated units without choosing a faction: the Inner Sphere at large, which is what every faction lookup in this package already falls back to.
      Parameters:
      year - the year to record
      Returns:
      a context naming no particular command
    • of

      public static GenerationContext of(@Nullable FactionRecord factionRecord, int year, @Nullable String rating, GenerationContext.Source source)
      Builds a context from what a generator tab holds, falling back to the Inner Sphere when the tab has no faction selected.
      Parameters:
      factionRecord - the chosen faction, may be null
      year - the chosen year
      rating - the chosen equipment rating, may be null or blank
      source - which generator this is
      Returns:
      the context, never null
    • hasSubCommand

      public boolean hasSubCommand()
      Returns:
      true when the faction key names a command rather than a faction at large
    • parentFaction

      public String parentFaction()
      Returns:
      the parent faction key: "FS" for "FS.CH", unchanged when there is none
    • factionDisplayName

      public String factionDisplayName()
      Returns:
      the faction's display name for the recorded year, falling back to the raw key when the generator data does not know it
    • describe

      public String describe()
      A one-line summary for logs and diagnostics, e.g. "Ceti Hussars, 3067, rating A". Not for display: anything a player reads is built from the parts through Messages so it can be translated.
      Returns:
      the summary
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • faction

      public String faction()
      Returns the value of the faction record component.
      Returns:
      the value of the faction record component
    • year

      public int year()
      Returns the value of the year record component.
      Returns:
      the value of the year record component
    • rating

      @Nullable public String rating()
      Returns the value of the rating record component.
      Returns:
      the value of the rating record component
    • source

      public GenerationContext.Source source()
      Returns the value of the source record component.
      Returns:
      the value of the source record component