Record Class MapField

java.lang.Object
java.lang.Record
com.hedera.pbj.compiler.impl.MapField
All Implemented Interfaces:
Field

public record MapField(Field keyField, Field valueField, boolean repeated, int fieldNumber, String name, Field.FieldType type, String protobufFieldType, String javaFieldTypeBase, String methodNameType, String parseCode, String javaDefault, String parserFieldsSetMethodCase, String comment, boolean deprecated) extends Record implements Field
A field of type map.

In protobuf, a map is essentially a repeated map entry message with two fields: key and value. However, we don't model the map entry message explicitly for performance reasons. Instead, we deal with the keys and values directly, and define synthetic Field objects for them here for convenience, so that we can reuse the majority of the code generation code.

In model implementations we use a custom implementation of the Map interface named PbjMap which is an immutable map that exposes a SortedKeys list which allows one to iterate the map deterministically which is useful for serializing, computing the hash code, etc.

  • Constructor Details

    • MapField

      public MapField(Protobuf3Parser.MapFieldContext mapContext, ContextualLookupHelper lookupHelper)
      Construct a MapField instance out of a MapFieldContext and a lookup helper.
    • MapField

      public MapField(Field keyField, Field valueField, boolean repeated, int fieldNumber, String name, Field.FieldType type, String protobufFieldType, String javaFieldTypeBase, String methodNameType, String parseCode, String javaDefault, String parserFieldsSetMethodCase, String comment, boolean deprecated)
      Creates an instance of a MapField record class.
      Parameters:
      keyField - the value for the keyField record component
      valueField - the value for the valueField record component
      repeated - the value for the repeated record component
      fieldNumber - the value for the fieldNumber record component
      name - the value for the name record component
      type - the value for the type record component
      protobufFieldType - the value for the protobufFieldType record component
      javaFieldTypeBase - the value for the javaFieldTypeBase record component
      methodNameType - the value for the methodNameType record component
      parseCode - the value for the parseCode record component
      javaDefault - the value for the javaDefault record component
      parserFieldsSetMethodCase - the value for the parserFieldsSetMethodCase record component
      comment - the value for the comment record component
      deprecated - the value for the deprecated record component
  • Method Details

    • javaGenericType

      public String javaGenericType()
      Composes the Java generic type of the map field, e.g. "<Integer, String>" for a Map<Integer, String>.
    • javaFieldType

      public String javaFieldType()
      Get the Java field type for this field
      Specified by:
      javaFieldType in interface Field
      Returns:
      this fields type in Java format
    • schemaFieldsDef

      public String schemaFieldsDef()
      Get the field definitions line of code for schema file for this field. One line for single fields and multiple for oneofs.
      Specified by:
      schemaFieldsDef in interface Field
      Returns:
      field definition lines of code
    • schemaGetFieldsDefCase

      public String schemaGetFieldsDefCase()
      Get the schema case statement for getting the field definition by field number
      Specified by:
      schemaGetFieldsDefCase in interface Field
      Returns:
      java source code for case statement to get field def for field number
    • addAllNeededImports

      public void addAllNeededImports(Set<String> imports, boolean modelImports, boolean codecImports, boolean testImports)
      Add all the needed imports for this field to the supplied set.
      Specified by:
      addAllNeededImports in interface Field
      Parameters:
      imports - set of imports to add to, this contains packages not classes. They are always imported as ".*".
      modelImports - if imports for this field's generated model classes should be added
      codecImports - if imports for this field's generated codec classes should be added
      testImports - if imports for this field's generated test classes should be added
    • 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.
    • keyField

      public Field keyField()
      Returns the value of the keyField record component.
      Returns:
      the value of the keyField record component
    • valueField

      public Field valueField()
      Returns the value of the valueField record component.
      Returns:
      the value of the valueField record component
    • repeated

      public boolean repeated()
      Returns the value of the repeated record component.
      Specified by:
      repeated in interface Field
      Returns:
      the value of the repeated record component
    • fieldNumber

      public int fieldNumber()
      Returns the value of the fieldNumber record component.
      Specified by:
      fieldNumber in interface Field
      Returns:
      the value of the fieldNumber record component
    • name

      public String name()
      Returns the value of the name record component.
      Specified by:
      name in interface Field
      Returns:
      the value of the name record component
    • type

      public Field.FieldType type()
      Returns the value of the type record component.
      Specified by:
      type in interface Field
      Returns:
      the value of the type record component
    • protobufFieldType

      public String protobufFieldType()
      Returns the value of the protobufFieldType record component.
      Specified by:
      protobufFieldType in interface Field
      Returns:
      the value of the protobufFieldType record component
    • javaFieldTypeBase

      public String javaFieldTypeBase()
      Returns the value of the javaFieldTypeBase record component.
      Specified by:
      javaFieldTypeBase in interface Field
      Returns:
      the value of the javaFieldTypeBase record component
    • methodNameType

      public String methodNameType()
      Returns the value of the methodNameType record component.
      Specified by:
      methodNameType in interface Field
      Returns:
      the value of the methodNameType record component
    • parseCode

      public String parseCode()
      Returns the value of the parseCode record component.
      Specified by:
      parseCode in interface Field
      Returns:
      the value of the parseCode record component
    • javaDefault

      public String javaDefault()
      Returns the value of the javaDefault record component.
      Specified by:
      javaDefault in interface Field
      Returns:
      the value of the javaDefault record component
    • parserFieldsSetMethodCase

      public String parserFieldsSetMethodCase()
      Returns the value of the parserFieldsSetMethodCase record component.
      Specified by:
      parserFieldsSetMethodCase in interface Field
      Returns:
      the value of the parserFieldsSetMethodCase record component
    • comment

      public String comment()
      Returns the value of the comment record component.
      Specified by:
      comment in interface Field
      Returns:
      the value of the comment record component
    • deprecated

      public boolean deprecated()
      Returns the value of the deprecated record component.
      Specified by:
      deprecated in interface Field
      Returns:
      the value of the deprecated record component