public static @NonNull BitsTypeBuilder newBitsBuilder(final BitsTypeDefinition baseType, final SchemaPath path) { return new BitsTypeBuilder(baseType, path); }
public BitsTypeBuilder addBit(final @NonNull Bit item) { // in case we are dealing with a restricted bits type, validate if the bit is a subset of its base type if (getBaseType() != null) { validateRestrictedBit(item); } builder.put(item.getName(), item); touch(); return this; }
@Override public BitsTypeDefinition buildType() { final Map<String, Bit> map = builder.build(); final Map<Long, Bit> positionMap = new TreeMap<>(); for (Bit b : map.values()) { final Bit conflict = positionMap.put(b.getPosition(), b); if (conflict != null) { throw new InvalidBitDefinitionException(b, "Bit %s conflicts on position with bit ", conflict); } } return getBaseType() == null ? new BaseBitsType(getPath(), getUnknownSchemaNodes(), positionMap.values()) : new RestrictedBitsType(getBaseType(), getPath(), getUnknownSchemaNodes(), positionMap.values()); } }
BitsTypeEffectiveStatementImpl( final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx, final BitsTypeDefinition baseType) { super(ctx); final BitsTypeBuilder builder = RestrictedTypes.newBitsBuilder(baseType, ctx.getSchemaPath().get()); final YangVersion yangVersion = ctx.getRootVersion(); for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) { if (stmt instanceof BitEffectiveStatementImpl) { SourceException.throwIf(yangVersion != YangVersion.VERSION_1_1, ctx.getStatementSourceReference(), "Restricted bits type is allowed only in YANG 1.1 version."); final BitEffectiveStatementImpl bitSubStmt = (BitEffectiveStatementImpl) stmt; final long effectivePos; if (bitSubStmt.getDeclaredPosition() == null) { effectivePos = getBaseTypeBitPosition(bitSubStmt.getName(), baseType, ctx); } else { effectivePos = bitSubStmt.getDeclaredPosition(); } builder.addBit(EffectiveTypeUtil.buildBit(bitSubStmt, effectivePos)); } else if (stmt instanceof UnknownSchemaNode) { builder.addUnknownSchemaNode((UnknownSchemaNode) stmt); } } typeDefinition = builder.build(); }
private void validateRestrictedBit(final @NonNull Bit item) { boolean isASubsetOfBaseBits = false; for (Bit baseTypeBit : getBaseType().getBits()) { if (item.getName().equals(baseTypeBit.getName())) { if (item.getPosition() != baseTypeBit.getPosition()) { throw new InvalidBitDefinitionException(item, "Position of bit '%s' must be the same as the " + "position of corresponding bit in the base bits type %s.", item.getName(), getBaseType().getQName()); } isASubsetOfBaseBits = true; break; } } if (!isASubsetOfBaseBits) { throw new InvalidBitDefinitionException(item, "Bit '%s' is not a subset of its base bits type %s.", item.getName(), getBaseType().getQName()); } }
builder.addBit(bit); builder.addUnknownSchemaNode((UnknownSchemaNode) stmt); typeDefinition = builder.build();
private void validateRestrictedBit(final @NonNull Bit item) { boolean isASubsetOfBaseBits = false; for (Bit baseTypeBit : getBaseType().getBits()) { if (item.getName().equals(baseTypeBit.getName())) { if (item.getPosition() != baseTypeBit.getPosition()) { throw new InvalidBitDefinitionException(item, "Position of bit '%s' must be the same as the " + "position of corresponding bit in the base bits type %s.", item.getName(), getBaseType().getQName()); } isASubsetOfBaseBits = true; break; } } if (!isASubsetOfBaseBits) { throw new InvalidBitDefinitionException(item, "Bit '%s' is not a subset of its base bits type %s.", item.getName(), getBaseType().getQName()); } }
public BitsTypeBuilder addBit(final @NonNull Bit item) { // in case we are dealing with a restricted bits type, validate if the bit is a subset of its base type if (getBaseType() != null) { validateRestrictedBit(item); } builder.put(item.getName(), item); touch(); return this; }
@Override public BitsTypeDefinition buildType() { final Map<String, Bit> map = builder.build(); final Map<Long, Bit> positionMap = new TreeMap<>(); for (Bit b : map.values()) { final Bit conflict = positionMap.put(b.getPosition(), b); if (conflict != null) { throw new InvalidBitDefinitionException(b, "Bit %s conflicts on position with bit ", conflict); } } return getBaseType() == null ? new BaseBitsType(getPath(), getUnknownSchemaNodes(), positionMap.values()) : new RestrictedBitsType(getBaseType(), getPath(), getUnknownSchemaNodes(), positionMap.values()); } }
public static @NonNull BitsTypeBuilder bitsTypeBuilder(final SchemaPath path) { return new BitsTypeBuilder(path); }
public static @NonNull BitsTypeBuilder newBitsBuilder(final BitsTypeDefinition baseType, final SchemaPath path) { return new BitsTypeBuilder(baseType, path); }
public static @NonNull BitsTypeBuilder bitsTypeBuilder(final SchemaPath path) { return new BitsTypeBuilder(path); }