Package com.hedera.pbj.compiler.impl
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.hedera.pbj.compiler.impl.Field
Field.FieldType -
Field Summary
Fields inherited from interface com.hedera.pbj.compiler.impl.Field
DEFAULT_MAX_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionMapField(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 aMapFieldrecord class.MapField(Protobuf3Parser.MapFieldContext mapContext, ContextualLookupHelper lookupHelper) Construct a MapField instance out of a MapFieldContext and a lookup helper. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllNeededImports(Set<String> imports, boolean modelImports, boolean codecImports, boolean testImports) Add all the needed imports for this field to the supplied set.comment()Returns the value of thecommentrecord component.booleanReturns the value of thedeprecatedrecord component.final booleanIndicates whether some other object is "equal to" this one.intReturns the value of thefieldNumberrecord component.final inthashCode()Returns a hash code value for this object.Returns the value of thejavaDefaultrecord component.Get the Java field type for this fieldReturns the value of thejavaFieldTypeBaserecord component.Composes the Java generic type of the map field, e.g.keyField()Returns the value of thekeyFieldrecord component.Returns the value of themethodNameTyperecord component.name()Returns the value of thenamerecord component.Returns the value of theparseCoderecord component.Returns the value of theparserFieldsSetMethodCaserecord component.Returns the value of theprotobufFieldTyperecord component.booleanrepeated()Returns the value of therepeatedrecord component.Get the field definitions line of code for schema file for this field.Get the schema case statement for getting the field definition by field numberfinal StringtoString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.Returns the value of thevalueFieldrecord component.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.hedera.pbj.compiler.impl.Field
maxSize, messageType, nameCamelFirstLower, nameCamelFirstUpper, optionalValueType, parent
-
Constructor Details
-
MapField
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 aMapFieldrecord class.- Parameters:
keyField- the value for thekeyFieldrecord componentvalueField- the value for thevalueFieldrecord componentrepeated- the value for therepeatedrecord componentfieldNumber- the value for thefieldNumberrecord componentname- the value for thenamerecord componenttype- the value for thetyperecord componentprotobufFieldType- the value for theprotobufFieldTyperecord componentjavaFieldTypeBase- the value for thejavaFieldTypeBaserecord componentmethodNameType- the value for themethodNameTyperecord componentparseCode- the value for theparseCoderecord componentjavaDefault- the value for thejavaDefaultrecord componentparserFieldsSetMethodCase- the value for theparserFieldsSetMethodCaserecord componentcomment- the value for thecommentrecord componentdeprecated- the value for thedeprecatedrecord component
-
-
Method Details
-
javaGenericType
Composes the Java generic type of the map field, e.g. "<Integer, String>" for a Map<Integer, String>. -
javaFieldType
Get the Java field type for this field- Specified by:
javaFieldTypein interfaceField- Returns:
- this fields type in Java format
-
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:
schemaFieldsDefin interfaceField- Returns:
- field definition lines of code
-
schemaGetFieldsDefCase
Get the schema case statement for getting the field definition by field number- Specified by:
schemaGetFieldsDefCasein interfaceField- 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:
addAllNeededImportsin interfaceField- 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 addedcodecImports- if imports for this field's generated codec classes should be addedtestImports- if imports for this field's generated test classes should be added
-
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
keyField
Returns the value of thekeyFieldrecord component.- Returns:
- the value of the
keyFieldrecord component
-
valueField
Returns the value of thevalueFieldrecord component.- Returns:
- the value of the
valueFieldrecord component
-
repeated
public boolean repeated()Returns the value of therepeatedrecord component. -
fieldNumber
public int fieldNumber()Returns the value of thefieldNumberrecord component.- Specified by:
fieldNumberin interfaceField- Returns:
- the value of the
fieldNumberrecord component
-
name
Returns the value of thenamerecord component. -
type
Returns the value of thetyperecord component. -
protobufFieldType
Returns the value of theprotobufFieldTyperecord component.- Specified by:
protobufFieldTypein interfaceField- Returns:
- the value of the
protobufFieldTyperecord component
-
javaFieldTypeBase
Returns the value of thejavaFieldTypeBaserecord component.- Specified by:
javaFieldTypeBasein interfaceField- Returns:
- the value of the
javaFieldTypeBaserecord component
-
methodNameType
Returns the value of themethodNameTyperecord component.- Specified by:
methodNameTypein interfaceField- Returns:
- the value of the
methodNameTyperecord component
-
parseCode
Returns the value of theparseCoderecord component. -
javaDefault
Returns the value of thejavaDefaultrecord component.- Specified by:
javaDefaultin interfaceField- Returns:
- the value of the
javaDefaultrecord component
-
parserFieldsSetMethodCase
Returns the value of theparserFieldsSetMethodCaserecord component.- Specified by:
parserFieldsSetMethodCasein interfaceField- Returns:
- the value of the
parserFieldsSetMethodCaserecord component
-
comment
Returns the value of thecommentrecord component. -
deprecated
public boolean deprecated()Returns the value of thedeprecatedrecord component.- Specified by:
deprecatedin interfaceField- Returns:
- the value of the
deprecatedrecord component
-