All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rythm.record.txt Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
@args com.linkedin.pegasus.generator.spec.RecordTemplateSpec record
@import com.linkedin.pegasus.generator.spec.ClassTemplateSpec
@import com.linkedin.pegasus.generator.spec.RecordTemplateSpec.Field
@import com.linkedin.pegasus.generator.spec.PrimitiveTemplateSpec
@import com.linkedin.pegasus.generator.spec.MapTemplateSpec
@import com.linkedin.pegasus.generator.spec.UnionTemplateSpec
@import com.linkedin.pegasus.generator.spec.ArrayTemplateSpec
@import org.coursera.courier.android.JavaSyntax
@import org.coursera.courier.api.ClassTemplateSpecs
@import org.coursera.courier.android.TypedDefinitions

@maybePackageAndImports(record)

@{ String className = JavaSyntax.escapeKeyword(record.getClassName()) }

@classAnnotations(record.getSchema())
public final class @className {
  @for(Field field: record.getFields()) {
    @{ String fieldName = JavaSyntax.escapeKeyword(field.getSchemaField().getName()) }

    @if(field.getCustomInfo() != null) {
      @@JsonAdapter(@(JavaSyntax.toType(field.getCustomInfo().getCoercerClass())).class)
    }
    @fieldAnnotations(field)
    @if(!fieldName.equals(field.getSchemaField().getName())) { @@SerializedName("@field.getSchemaField().getName()") }
    public @JavaSyntax.toType(field.getType()) @fieldName;
  }

  @for(ClassTemplateSpec enclosed: ClassTemplateSpecs.allContainedTypes(record)) {
    @if (enclosed instanceof UnionTemplateSpec) {
      @if (TypedDefinitions.isTypedDefinition((UnionTemplateSpec)enclosed)) {
        @typedDefinition(enclosed, TypedDefinitions.getTypedDefinitionMapping((UnionTemplateSpec)enclosed, false))
      } else if (TypedDefinitions.isFlatTypedDefinition((UnionTemplateSpec)enclosed)) {
        @flatTypedDefinition(enclosed, TypedDefinitions.getTypedDefinitionMapping((UnionTemplateSpec)enclosed, true))
      } else {
        @union(enclosed)
      }
    }
  }

  @@Override
  public int hashCode() {
    @if(record.getFields().size() == 0) {
      return Objects.hashCode(this.getClass());
    } else {
      return Objects.hash(this.getClass(), @JavaSyntax.fieldList(record.getFields()));
    }
  }

  @@Override
  public boolean equals(Object obj) {
    if (!(obj instanceof @className)) return false;
    @className other = (@className)obj;
    if (other == this) return true;
    return @for(Field field: record.getFields()) {@{ String fieldName = JavaSyntax.escapeKeyword(field.getSchemaField().getName())} Objects.deepEquals(this.@fieldName, other.@fieldName) &&} true;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy