@Test public void testBuildEnumType() { EnumType categoryType = factory.build(Category.class); assertThat(categoryType.getMembers().size(), is(3)); assertThat(categoryType.getUnderlyingType(), is(PrimitiveType.INT32)); assertFalse(categoryType.isFlags()); EnumMember booksMember = categoryType.getMember(Category.BOOKS.name()); assertThat(booksMember.getName(), is(Category.BOOKS.name())); assertThat(booksMember.getValue(), is(0L)); EnumMember electronicsMember = categoryType.getMember(Category.ELECTRONICS.name()); assertThat(electronicsMember.getName(), is(Category.ELECTRONICS.name())); assertThat(electronicsMember.getValue(), is(1L)); EnumMember householdMember = categoryType.getMember(Category.HOUSEHOLD.name()); assertThat(householdMember.getName(), is(Category.HOUSEHOLD.name())); assertThat(householdMember.getValue(), is(2L)); }
public EnumType build(Class<?> cls) { EdmEnum enumAnno = cls.getAnnotation(EdmEnum.class); boolean isFlags = enumAnno.flags(); List<EnumMember> members = new ArrayList<>(); long value = isFlags ? 1L : 0L; for (Field field : cls.getDeclaredFields()) { if (field.isEnumConstant()) { members.add(new EnumMemberImpl(field.getName(), value)); if (isFlags) { value <<= 1; } else { value++; } } } return new EnumTypeImpl.Builder() .setName(getTypeName(enumAnno, cls)) .setNamespace(getNamespace(enumAnno, cls)) .setJavaType(cls) .setUnderlyingType(enumAnno.underlyingType()) .setIsFlags(isFlags) .addMembers(members) .build(); }
AnnotationEnumTypeFactory { public EnumType build(Class<?> cls) { EdmEnum enumAnno = cls.getAnnotation(EdmEnum.class); boolean isFlags = enumAnno.flags(); List<EnumMember> members = new ArrayList<>(); long value = isFlags ? 1L : 0L; for (Field field : cls.getDeclaredFields()) { if (field.isEnumConstant()) { members.add(new EnumMemberImpl(field.getName(), value)); if (isFlags) { value <<= 1; } else { value++; } } } return new EnumTypeImpl.Builder() .setName(getTypeName(enumAnno, cls)) .setNamespace(getNamespace(enumAnno, cls)) .setJavaType(cls) .setUnderlyingType(enumAnno.underlyingType()) .setIsFlags(isFlags) .addMembers(members) .build(); } }
AnnotationEnumTypeFactory { public EnumType build(Class<?> cls) { EdmEnum enumAnno = cls.getAnnotation(EdmEnum.class); boolean isFlags = enumAnno.flags(); List<EnumMember> members = new ArrayList<>(); long value = isFlags ? 1L : 0L; for (Field field : cls.getDeclaredFields()) { if (field.isEnumConstant()) { members.add(new EnumMemberImpl(field.getName(), value)); if (isFlags) { value <<= 1; } else { value++; } } } return new EnumTypeImpl.Builder() .setName(getTypeName(enumAnno, cls)) .setNamespace(getNamespace(enumAnno, cls)) .setJavaType(cls) .setUnderlyingType(enumAnno.underlyingType()) .setIsFlags(isFlags) .addMembers(members) .build(); }  }
AnnotationEnumTypeFactory { public EnumType build(Class<?> cls) { EdmEnum enumAnno = cls.getAnnotation(EdmEnum.class); boolean isFlags = enumAnno.flags(); List<EnumMember> members = new ArrayList<>(); long value = isFlags ? 1L : 0L; for (Field field : cls.getDeclaredFields()) { if (field.isEnumConstant()) { members.add(new EnumMemberImpl(field.getName(), value)); if (isFlags) { value <<= 1; } else { value++; } } } return new EnumTypeImpl.Builder() .setName(getTypeName(enumAnno, cls)) .setNamespace(getNamespace(enumAnno, cls)) .setJavaType(cls) .setUnderlyingType(enumAnno.underlyingType()) .setIsFlags(isFlags) .addMembers(members) .build(); }  EnumType build(Class<?> cls); static String getFullyQualifiedTypeName(EdmEnum enumAnno, Class<?> enumClass); }
AnnotationEnumTypeFactory { public EnumType build(Class<?> cls) { EdmEnum enumAnno = cls.getAnnotation(EdmEnum.class); boolean isFlags = enumAnno.flags(); List<EnumMember> members = new ArrayList<>(); long value = isFlags ? 1L : 0L; for (Field field : cls.getDeclaredFields()) { if (field.isEnumConstant()) { members.add(new EnumMemberImpl(field.getName(), value)); if (isFlags) { value <<= 1; } else { value++; } } } return new EnumTypeImpl.Builder() .setName(getTypeName(enumAnno, cls)) .setNamespace(getNamespace(enumAnno, cls)) .setJavaType(cls) .setUnderlyingType(enumAnno.underlyingType()) .setIsFlags(isFlags) .addMembers(members) .build(); }  EnumType build(Class<?> cls); static String getFullyQualifiedTypeName(EdmEnum enumAnno, Class<?> enumClass);  }