Record Class BFSSpecial

java.lang.Object
java.lang.Record
megamek.common.battlefieldSupport.BFSSpecial
Record Components:
code - the Special's abbreviation as authored (never null; blank is tolerated but not expected)
value - the Special's parameter, or null if it has none
All Implemented Interfaces:
Serializable

public record BFSSpecial(String code, String value) extends Record implements Serializable
A single Special ability on a Battlefield Support Asset, stored as an abbreviated code plus an optional parameter value. The value is a String so it can hold either a number (for Specials like IF2, APC1, ECM6) or a type token (for Artillery (LT)).

On the Asset card, a numeric value is appended directly to the code (for example IF2) while a non-numeric value is shown in parentheses (for example Artillery (LT)); Specials without a value are shown as-is (for example TAG, No Turret).

Any code may be stored here, including ones this build does not implement: unknown Specials are preserved verbatim and printed on the card, but ignored during gameplay. Recognized codes can be resolved to a BFSSpecialType via knownType().

See Also:
  • Constructor Details

    • BFSSpecial

      public BFSSpecial(String code, @Nullable String value)
      Creates an instance of a BFSSpecial record class.
      Parameters:
      code - the value for the code record component
      value - the value for the value record component
  • Method Details

    • of

      public static BFSSpecial of(String code)
      Parameters:
      code - the Special's abbreviation
      Returns:
      a Special with no value
    • of

      public static BFSSpecial of(String code, @Nullable String value)
      Parameters:
      code - the Special's abbreviation
      value - the Special's parameter
      Returns:
      a Special with the given code and value
    • of

      public static BFSSpecial of(String code, int value)
      Parameters:
      code - the Special's abbreviation
      value - the Special's integer parameter
      Returns:
      a Special with the given code and value
    • hasValue

      public boolean hasValue()
      Returns:
      true if this Special has a parameter value
    • hasNumericValue

      public boolean hasNumericValue()
      Returns:
      true if this Special's value is present and purely numeric
    • intValue

      public Optional<Integer> intValue()
      Returns:
      the Special's value parsed as an integer, or empty if it is absent or non-numeric
    • knownType

      public Optional<BFSSpecialType> knownType()
      Returns:
      the known-Special registry entry for this code, if it is recognized
    • isKnown

      public boolean isKnown()
      Returns:
      true if this Special's code is recognized in the BFSSpecialType registry
    • displayString

      public String displayString()
      Returns:
      the card display form: the code with a numeric value appended (for example IF2), a non-numeric value in parentheses (for example Artillery (LT)), or just the code when there is no value
    • parse

      @Nullable public static BFSSpecial parse(@Nullable String token)
      Parses a card display token into a BFSSpecial. Handles three forms: a parenthesized value (for example Artillery (LT) yields code Artillery, value LT); a trailing run of digits (for example IF2 yields code IF, value 2); or no value (for example No Turret, TAG).
      Parameters:
      token - the token to parse
      Returns:
      the parsed Special, or null if the token is null or blank
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • code

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

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