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

rythm-android.recordConstructor.txt Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
@args String className, com.linkedin.pegasus.generator.spec.RecordTemplateSpec record, org.coursera.courier.android.JavaSyntax syntax
@import com.linkedin.pegasus.generator.spec.RecordTemplateSpec.Field
@import com.linkedin.data.schema.DataSchema
@import com.linkedin.data.schema.DataSchema.Type

public @(className)(@syntax.fieldAndTypeList(record.getFields())) {
  @for(Field field: record.getFields()) {
    @{ String fieldName = syntax.escapeKeyword(field.getSchemaField().getName()) }
    @{ boolean required = !field.getSchemaField().getOptional() }
    @{ DataSchema fieldSchema = field.getSchemaField().getType() }
    @{ Type fieldType = field.getSchemaField().getType().getType() }

    @* DISABLED. To support projections, we allow required fields to be absent so cannot include these preconditions.
    @if(required && !field.getSchemaField().getType().isPrimitive()) {
      if (@fieldName == null) throw new IllegalArgumentException("Field @fieldName is required.");
    }
    *@

    @if(fieldType == Type.ARRAY) {
      this.@fieldName = (@fieldName == null) ? null : Collections.unmodifiableList(new ArrayList<>(@fieldName));
    } else if (fieldType == Type.MAP) {
      this.@fieldName = (@fieldName == null) ? null : Collections.unmodifiableMap(new HashMap<>(@fieldName));
    } else {
      this.@fieldName = @fieldName;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy