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

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

There is a newer version: 3.0.0
Show newest version
@args com.linkedin.pegasus.generator.spec.UnionTemplateSpec union, org.coursera.courier.android.JavaSyntax syntax
@import com.linkedin.pegasus.generator.spec.UnionTemplateSpec.Member
@import org.coursera.courier.android.JavaSyntax

@maybePackageAndImports(union)

@{ String className = syntax.escapeKeyword(union.getClassName()) }

@if (union.getTyperefClass() != null) {
  @classAnnotations(union.getTyperefClass().getSchema())
}
@@JsonAdapter(@(className).Adapter.class)
public interface @className {
  @for(Member member: union.getMembers()) {
    @{ String unionMemberName = syntax.toUnionMemberName(member.getClassTemplateSpec()) }
    public @if (union.getEnclosingClass() != null) {static} class @unionMemberName implements @className {
      private static final String MEMBER_KEY = "@member.getSchema().getUnionMemberKey()";

      public @(unionMemberName)(@syntax.toType(member.getClassTemplateSpec()) member) {
        this.member = member;
      }

      @@SerializedName(MEMBER_KEY)
      public final @syntax.toType(member.getClassTemplateSpec()) member;

      @@Override
      public int hashCode() {
        return Objects.hash(this.getClass(), member);
      }

      @@Override
      public boolean equals(Object obj) {
        if (!(obj instanceof @unionMemberName)) return false;
        @unionMemberName other = (@unionMemberName)obj;
        if (other == this) return true;
        return Objects.deepEquals(this.member, other.member);
      }
    }
  }

  public final class $UnknownMember implements @className {
    private $UnknownMember() { }
  }

  final class Adapter extends UnionAdapterFactory<@className> {
    Adapter() {
      super(@(className).class, new UnionAdapterFactory.Resolver<@className>() {
        @@Override
        public Class resolve(String memberKey) {
          switch(memberKey) {
            @for(Member member: union.getMembers()) {
              @{String unionMemberName = syntax.toUnionMemberName(member.getClassTemplateSpec())} case @(unionMemberName).MEMBER_KEY: return @(unionMemberName).class;
            }
            default: return $UnknownMember.class;
          }
        }
      });
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy