public static @NonNull EnumerationTypeBuilder newEnumerationBuilder(final EnumTypeDefinition baseType, final SchemaPath path) { return new EnumerationTypeBuilder(baseType, path); }
public EnumerationTypeBuilder addEnum(final @NonNull EnumPair item) { // in case we are dealing with a restricted enumeration type, validate if the enum is a subset of its base type final EnumTypeDefinition base = getBaseType(); if (base != null) { validateRestrictedEnum(item, base); } builder.put(item.getName(), item); touch(); return this; }
@Override public EnumTypeDefinition buildType() { final Map<String, EnumPair> map = builder.build(); final Map<Integer, EnumPair> positionMap = new HashMap<>(); for (EnumPair p : map.values()) { final EnumPair conflict = positionMap.put(p.getValue(), p); if (conflict != null) { throw new InvalidEnumDefinitionException(p, "Enum '%s' conflicts on value with enum ", conflict); } } return getBaseType() == null ? new BaseEnumerationType(getPath(), getUnknownSchemaNodes(), map.values()) : new RestrictedEnumerationType(getBaseType(), getPath(), getUnknownSchemaNodes(), map.values()); } }
EnumTypeEffectiveStatementImpl( final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx, final EnumTypeDefinition baseType) { super(ctx); final EnumerationTypeBuilder builder = RestrictedTypes.newEnumerationBuilder(baseType, ctx.getSchemaPath().get()); final YangVersion yangVersion = ctx.getRootVersion(); for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) { if (stmt instanceof EnumEffectiveStatementImpl) { SourceException.throwIf(yangVersion != YangVersion.VERSION_1_1, ctx.getStatementSourceReference(), "Restricted enumeration type is allowed only in YANG 1.1 version."); final EnumEffectiveStatementImpl enumSubStmt = (EnumEffectiveStatementImpl) stmt; final int effectiveValue; if (enumSubStmt.getDeclaredValue() == null) { effectiveValue = getBaseTypeEnumValue(enumSubStmt.getName(), baseType, ctx); } else { effectiveValue = enumSubStmt.getDeclaredValue(); } builder.addEnum(EffectiveTypeUtil.buildEnumPair(enumSubStmt, effectiveValue)); } else if (stmt instanceof UnknownSchemaNode) { builder.addUnknownSchemaNode((UnknownSchemaNode) stmt); } } typeDefinition = builder.build(); }
builder.addEnum(pair); builder.addUnknownSchemaNode((UnknownSchemaNode) stmt); typeDefinition = builder.build();
public EnumerationTypeBuilder addEnum(final @NonNull EnumPair item) { // in case we are dealing with a restricted enumeration type, validate if the enum is a subset of its base type final EnumTypeDefinition base = getBaseType(); if (base != null) { validateRestrictedEnum(item, base); } builder.put(item.getName(), item); touch(); return this; }
@Override public EnumTypeDefinition buildType() { final Map<String, EnumPair> map = builder.build(); final Map<Integer, EnumPair> positionMap = new HashMap<>(); for (EnumPair p : map.values()) { final EnumPair conflict = positionMap.put(p.getValue(), p); if (conflict != null) { throw new InvalidEnumDefinitionException(p, "Enum '%s' conflicts on value with enum ", conflict); } } return getBaseType() == null ? new BaseEnumerationType(getPath(), getUnknownSchemaNodes(), map.values()) : new RestrictedEnumerationType(getBaseType(), getPath(), getUnknownSchemaNodes(), map.values()); } }
public static @NonNull EnumerationTypeBuilder enumerationTypeBuilder(final SchemaPath path) { return new EnumerationTypeBuilder(path); }
public static @NonNull EnumerationTypeBuilder newEnumerationBuilder(final EnumTypeDefinition baseType, final SchemaPath path) { return new EnumerationTypeBuilder(baseType, path); }
public static @NonNull EnumerationTypeBuilder enumerationTypeBuilder(final SchemaPath path) { return new EnumerationTypeBuilder(path); }