Class MMUReader

java.lang.Object
megamek.common.jacksonAdapters.MMUReader

public final class MMUReader extends Object
This class has methods for reading objects such as SBF Formations, Units and AlphaStrikeElements from an MMU file which uses YAML formatting.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    disallowCombinedFields(String objectType, com.fasterxml.jackson.databind.JsonNode node, String... fields)
    Tests the given node if it has any combination of at least two of the given fields.
    read(com.fasterxml.jackson.databind.JsonNode node)
    Read a list of objects from a Jackson JsonNode.
    read(com.fasterxml.jackson.databind.JsonNode node, Class<?> objectType)
    Read a list of objects from a Jackson JsonNode.
    read(File file)
    Read a list of objects from a given MMU file (YAML format, see MMUWriter).
    static void
    requireFields(String objectType, com.fasterxml.jackson.databind.JsonNode node, String... fields)
    Tests the given node (which should be an object node that holds a full AS element or SBF Unit) if it has all the given fields.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MMUReader

      public MMUReader()
    • MMUReader

      public MMUReader(File file)
  • Method Details

    • read

      public List<Object> read(File file) throws IOException
      Read a list of objects from a given MMU file (YAML format, see MMUWriter). The list can be empty or contain one or multiple results. If reading any part of the file fails, an exception is thrown.
      Parameters:
      file - The MMU file to read
      Returns:
      A list of objects (AlphaStrikeElements, SBFUnits...) contained in the MMU file
      Throws:
      IOException - When a read error occurs
    • read

      public List<Object> read(com.fasterxml.jackson.databind.JsonNode node) throws IOException
      Read a list of objects from a Jackson JsonNode. Internally used to parse nested objects.
      Parameters:
      node - The node to parse
      Returns:
      A list of objects (AlphaStrikeElements, SBFUnits...) contained in the node
      Throws:
      IOException - When a read error occurs
    • read

      public List<Object> read(com.fasterxml.jackson.databind.JsonNode node, Class<?> objectType) throws IOException
      Read a list of objects from a Jackson JsonNode. Internally used to parse nested objects.
      Parameters:
      node - The node to parse
      Returns:
      A list of objects (AlphaStrikeElements, SBFUnits...) contained in the node
      Throws:
      IOException - When a read error occurs
    • requireFields

      public static void requireFields(String objectType, com.fasterxml.jackson.databind.JsonNode node, String... fields)
      Tests the given node (which should be an object node that holds a full AS element or SBF Unit) if it has all the given fields. If any of the given fields is missing, an IllegalArgumentException is thrown. The given objectType can be any String, it is only used as part of the error message when a field is not found.
      Parameters:
      objectType - The object type such as "ASElement". Only used as part of the exception message
      node - the node containing an object to be deserialized
      fields - The required field names, e.g. "chassis" or "size"
    • disallowCombinedFields

      public static void disallowCombinedFields(String objectType, com.fasterxml.jackson.databind.JsonNode node, String... fields)
      Tests the given node if it has any combination of at least two of the given fields. If that is the case, an IllegalArgumentException is thrown. The given objectType can be any String, it is only used as part of the error message. If none of the fields or only a single one of the fields is found, this method does nothing.
      Parameters:
      objectType - The object type such as "ASElement". Only used as part of the exception message
      node - the node containing an object to be deserialized
      fields - The field names, e.g. "chassis" or "size"