private void emitEnumSpecification(final EnumTypeDefinition typeDefinition) { for (final EnumPair enumValue : typeDefinition.getValues()) { emitEnumNode(enumValue); } }
@Override public List<EnumPair> getValues() { return baseType().getValues(); }
private EnumStringCodec(final Optional<EnumTypeDefinition> typeDef) { super(typeDef, String.class); if (typeDef.isPresent()) { final Builder<String, String> b = ImmutableMap.builder(); for (final EnumPair pair : typeDef.get().getValues()) { // Intern the String to get wide reuse final String v = pair.getName().intern(); b.put(v, v); } values = b.build(); } else { values = null; } }
private EnumStringCodec(final Optional<EnumTypeDefinition> typeDef) { super(typeDef, String.class); if (typeDef.isPresent()) { final Builder<String, String> b = ImmutableMap.builder(); for (final EnumPair pair : typeDef.get().getValues()) { // Intern the String to get wide reuse final String v = pair.getName().intern(); b.put(v, v); } values = b.build(); } else { values = null; } }
@Override public List<EnumPair> getValues() { return baseType().getValues(); }
private static int getEnumValue(final EnumTypeDefinition enumerationType, final String enumName) { for (final EnumTypeDefinition.EnumPair enumPair : enumerationType.getValues()) { if (enumName.equals(enumPair.getName())) { return enumPair.getValue(); } } throw new IllegalStateException(String.format("Enum %s does not belong to enumeration %s.", enumName, enumerationType)); }
private static void processEnumType(final EnumTypeDefinition enumLeafType, final JSONObject property) throws JSONException { List<EnumPair> enumPairs = enumLeafType.getValues(); List<String> enumNames = new ArrayList<>(); for (EnumPair enumPair : enumPairs) { enumNames.add(enumPair.getName()); } property.putOpt(ENUM, new JSONArray(enumNames)); }
private static int getEnumValue(final EnumTypeDefinition enumerationType, final String enumName) { for (final EnumTypeDefinition.EnumPair enumPair : enumerationType.getValues()) { if (enumName.equals(enumPair.getName())) { return enumPair.getValue(); } } throw new IllegalStateException(String.format("Enum %s does not belong to enumeration %s.", enumName, enumerationType)); }
static String toString(final @NonNull EnumTypeDefinition type) { return TypeDefinitions.toStringHelper(type).add("values", type.getValues()).toString(); } }
static String toString(final @NonNull EnumTypeDefinition type) { return TypeDefinitions.toStringHelper(type).add("values", type.getValues()).toString(); } }
private static BiMap<String, String> getEnumMapping(final Entry<GeneratedType, WithStatus> typeWithSchema) { final TypeDefinition<?> typeDef = (TypeDefinition<?>) typeWithSchema.getValue(); Preconditions.checkArgument(typeDef instanceof EnumTypeDefinition); final EnumTypeDefinition enumType = (EnumTypeDefinition) typeDef; final HashBiMap<String, String> mappedEnums = HashBiMap.create(); for (final EnumTypeDefinition.EnumPair enumPair : enumType.getValues()) { mappedEnums.put(enumPair.getName(), BindingMapping.getClassName(enumPair.getName())); } // TODO cache these maps for future use return mappedEnums; }
private static BiMap<String, String> getEnumMapping(final Entry<GeneratedType, Object> typeWithSchema) { final TypeDefinition<?> typeDef = (TypeDefinition<?>) typeWithSchema.getValue(); Preconditions.checkArgument(typeDef instanceof EnumTypeDefinition); final EnumTypeDefinition enumType = (EnumTypeDefinition) typeDef; final HashBiMap<String, String> mappedEnums = HashBiMap.create(); for (final EnumTypeDefinition.EnumPair enumPair : enumType.getValues()) { mappedEnums.put(enumPair.getName(), JavaIdentifierNormalizer.normalizeSpecificIdentifier(enumPair.getName(), JavaIdentifier.CLASS)); } // TODO cache these maps for future use return mappedEnums; }
@Override public void updateEnumPairsFromEnumTypeDef(final EnumTypeDefinition enumTypeDef) { enumTypeDef.getValues().stream().filter(Objects::nonNull).forEach(enumPair -> this.addValue(enumPair.getName(), enumPair.getValue(), enumPair.getDescription().orElse(null), enumPair.getReference().orElse(null), enumPair.getStatus())); }
@Override public final void updateEnumPairsFromEnumTypeDef(final EnumTypeDefinition enumTypeDef) { final List<EnumPair> enums = enumTypeDef.getValues(); final Map<String, String> valueIds = BindingMapping.mapEnumAssignedNames(enums.stream().map(EnumPair::getName) .collect(Collectors.toList())); for (EnumPair enumPair : enums) { addValue(enumPair.getName(), valueIds.get(enumPair.getName()), enumPair.getValue(), enumPair.getStatus(), enumPair.getDescription().orElse(null), enumPair.getReference().orElse(null)); } }
static int hashCode(final @NonNull EnumTypeDefinition type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits().orElse(null), type.getDefaultValue(), type.getValues()); }
private static int getBaseTypeEnumValue(final String enumName, final EnumTypeDefinition baseType, final StmtContext<?, ?, ?> ctx) { for (EnumPair baseTypeEnumPair : baseType.getValues()) { if (enumName.equals(baseTypeEnumPair.getName())) { return baseTypeEnumPair.getValue(); } } throw new SourceException(ctx.getStatementSourceReference(), "Enum '%s' is not a subset of its base enumeration type %s.", enumName, baseType.getQName()); }
static int hashCode(final @NonNull EnumTypeDefinition type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits().orElse(null), type.getDefaultValue(), type.getValues()); }
private static void validateRestrictedEnum(final @NonNull EnumPair item, final @NonNull EnumTypeDefinition base) { boolean isASubsetOfBaseEnums = false; for (EnumPair baseTypeEnumPair : base.getValues()) { if (item.getName().equals(baseTypeEnumPair.getName())) { if (item.getValue() != baseTypeEnumPair.getValue()) { throw new InvalidEnumDefinitionException(item, "Value of enum '%s' must be the same as the value" + " of corresponding enum in the base enumeration type %s.", item.getName(), base.getQName()); } isASubsetOfBaseEnums = true; break; } } if (!isASubsetOfBaseEnums) { throw new InvalidEnumDefinitionException(item, "Enum '%s' is not a subset of its base enumeration type %s.", item.getName(), base.getQName()); } }