Search in sources :

Example 1 with Int16TypeDefinition

use of org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition in project yangtools by opendaylight.

the class TypeTest method integerTypeTest.

@Test
public void integerTypeTest() {
    final Int8TypeDefinition integerTypeDefinition8 = BaseTypes.int8Type();
    final Int16TypeDefinition integerTypeDefinition16 = BaseTypes.int16Type();
    final Int32TypeDefinition integerTypeDefinition32 = BaseTypes.int32Type();
    final Int64TypeDefinition integerTypeDefinition64 = BaseTypes.int64Type();
    testInstance(BaseInt8Type.INSTANCE, integerTypeDefinition8);
    testInstance(BaseInt16Type.INSTANCE, integerTypeDefinition16);
    testInstance(BaseInt32Type.INSTANCE, integerTypeDefinition32);
    testInstance(BaseInt64Type.INSTANCE, integerTypeDefinition64);
    final RestrictedInt8Type restrictedIntegerType1 = (RestrictedInt8Type) RestrictedTypes.newInt8Builder(integerTypeDefinition8, Q_NAME).buildType();
    final RestrictedInt8Type restrictedIntegerType2 = (RestrictedInt8Type) RestrictedTypes.newInt8Builder(BaseInt8Type.INSTANCE, Q_NAME).buildType();
    hashCodeEqualsToStringTest(restrictedIntegerType1, restrictedIntegerType2);
    final Uint8TypeDefinition integerTypeDefinitionu8 = BaseTypes.uint8Type();
    final Uint16TypeDefinition integerTypeDefinitionu16 = BaseTypes.uint16Type();
    final Uint32TypeDefinition integerTypeDefinitionu32 = BaseTypes.uint32Type();
    final Uint64TypeDefinition integerTypeDefinitionu64 = BaseTypes.uint64Type();
    testInstance(BaseUint8Type.INSTANCE, integerTypeDefinitionu8);
    testInstance(BaseUint16Type.INSTANCE, integerTypeDefinitionu16);
    testInstance(BaseUint32Type.INSTANCE, integerTypeDefinitionu32);
    testInstance(BaseUint64Type.INSTANCE, BaseTypes.baseTypeOf(integerTypeDefinitionu64));
    final DerivedInt8Type derivedIntegerType1 = (DerivedInt8Type) DerivedTypes.derivedTypeBuilder(integerTypeDefinition8, Q_NAME).build();
    final DerivedInt8Type derivedIntegerType2 = (DerivedInt8Type) DerivedTypes.derivedTypeBuilder(BaseInt8Type.INSTANCE, Q_NAME).build();
    hashCodeEqualsToStringTest(derivedIntegerType1, derivedIntegerType2);
    final DerivedUint8Type derivedUnsignedType1 = (DerivedUint8Type) DerivedTypes.derivedTypeBuilder(integerTypeDefinitionu8, Q_NAME).build();
    final DerivedUint8Type derivedUnsignedType2 = (DerivedUint8Type) DerivedTypes.derivedTypeBuilder(BaseUint8Type.INSTANCE, Q_NAME).build();
    hashCodeEqualsToStringTest(derivedUnsignedType1, derivedUnsignedType2);
    final RestrictedUint8Type restrictedUnsignedType1 = (RestrictedUint8Type) RestrictedTypes.newUint8Builder(integerTypeDefinitionu8, Q_NAME).buildType();
    final RestrictedUint8Type restrictedUnsignedType2 = (RestrictedUint8Type) RestrictedTypes.newUint8Builder(BaseUint8Type.INSTANCE, Q_NAME).buildType();
    hashCodeEqualsToStringTest(restrictedUnsignedType1, restrictedUnsignedType2);
    concreteBuilderTest(integerTypeDefinition8, derivedIntegerType1);
    concreteBuilderTest(integerTypeDefinitionu8, derivedUnsignedType2);
    final DerivedTypeBuilder<?> derivedTypeBuilder = DerivedTypes.derivedTypeBuilder(integerTypeDefinition8, Q_NAME);
    derivedTypeBuilder.setDefaultValue(1);
    derivedTypeBuilder.setDescription("test-description");
    derivedTypeBuilder.setReference("test-reference");
    derivedTypeBuilder.setUnits("Int");
    derivedTypeBuilder.setStatus(Status.CURRENT);
    assertEquals(derivedTypeBuilder.getStatus(), Status.CURRENT);
    assertEquals(derivedTypeBuilder.getDescription(), "test-description");
    assertEquals(derivedTypeBuilder.getReference(), "test-reference");
    assertEquals(derivedTypeBuilder.getUnits(), "Int");
}
Also used : Int8TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int8TypeDefinition) Int64TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int64TypeDefinition) Uint16TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Uint16TypeDefinition) Int16TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition) Int32TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition) Uint8TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition) Uint32TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition) Uint64TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Uint64TypeDefinition) Test(org.junit.Test)

Example 2 with Int16TypeDefinition

use of org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition in project yangtools by opendaylight.

the class AbstractTypeStatementSupport method createEffective.

@Override
protected EffectiveStatement<QName, TypeStatement> createEffective(final Current<QName, TypeStatement> stmt, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
    // First look up the proper base type
    final TypeEffectiveStatement<TypeStatement> typeStmt = resolveType(stmt);
    if (substatements.isEmpty()) {
        return typeStmt;
    }
    // Now instantiate the proper effective statement for that type
    final TypeDefinition<?> baseType = typeStmt.getTypeDefinition();
    final TypeStatement declared = stmt.declared();
    if (baseType instanceof BinaryTypeDefinition) {
        return createBinary(stmt, (BinaryTypeDefinition) baseType, declared, substatements);
    } else if (baseType instanceof BitsTypeDefinition) {
        return createBits(stmt, (BitsTypeDefinition) baseType, declared, substatements);
    } else if (baseType instanceof BooleanTypeDefinition) {
        return createBoolean(stmt, (BooleanTypeDefinition) baseType, declared, substatements);
    } else if (baseType instanceof DecimalTypeDefinition) {
        return createDecimal(stmt, (DecimalTypeDefinition) baseType, declared, substatements);
    } else if (baseType instanceof EmptyTypeDefinition) {
        return createEmpty(stmt, (EmptyTypeDefinition) baseType, declared, substatements);
    } else if (baseType instanceof EnumTypeDefinition) {
        return createEnum(stmt, (EnumTypeDefinition) baseType, declared, substatements);
    } else if (baseType instanceof IdentityrefTypeDefinition) {
        return createIdentityref(stmt, (IdentityrefTypeDefinition) baseType, declared, substatements);
    } else if (baseType instanceof InstanceIdentifierTypeDefinition) {
        return createInstanceIdentifier(stmt, (InstanceIdentifierTypeDefinition) baseType, declared, substatements);
    } else if (baseType instanceof Int8TypeDefinition) {
        return createIntegral(stmt, declared, substatements, RestrictedTypes.newInt8Builder((Int8TypeDefinition) baseType, typeEffectiveQName(stmt)));
    } else if (baseType instanceof Int16TypeDefinition) {
        return createIntegral(stmt, declared, substatements, RestrictedTypes.newInt16Builder((Int16TypeDefinition) baseType, typeEffectiveQName(stmt)));
    } else if (baseType instanceof Int32TypeDefinition) {
        return createIntegral(stmt, declared, substatements, RestrictedTypes.newInt32Builder((Int32TypeDefinition) baseType, typeEffectiveQName(stmt)));
    } else if (baseType instanceof Int64TypeDefinition) {
        return createIntegral(stmt, declared, substatements, RestrictedTypes.newInt64Builder((Int64TypeDefinition) baseType, typeEffectiveQName(stmt)));
    } else if (baseType instanceof LeafrefTypeDefinition) {
        return createLeafref(stmt, (LeafrefTypeDefinition) baseType, declared, substatements);
    } else if (baseType instanceof StringTypeDefinition) {
        return createString(stmt, (StringTypeDefinition) baseType, declared, substatements);
    } else if (baseType instanceof Uint8TypeDefinition) {
        return createIntegral(stmt, declared, substatements, RestrictedTypes.newUint8Builder((Uint8TypeDefinition) baseType, typeEffectiveQName(stmt)));
    } else if (baseType instanceof Uint16TypeDefinition) {
        return createIntegral(stmt, declared, substatements, RestrictedTypes.newUint16Builder((Uint16TypeDefinition) baseType, typeEffectiveQName(stmt)));
    } else if (baseType instanceof Uint32TypeDefinition) {
        return createIntegral(stmt, declared, substatements, RestrictedTypes.newUint32Builder((Uint32TypeDefinition) baseType, typeEffectiveQName(stmt)));
    } else if (baseType instanceof Uint64TypeDefinition) {
        return createIntegral(stmt, declared, substatements, RestrictedTypes.newUint64Builder((Uint64TypeDefinition) baseType, typeEffectiveQName(stmt)));
    } else if (baseType instanceof UnionTypeDefinition) {
        return createUnion(stmt, (UnionTypeDefinition) baseType, declared, substatements);
    } else {
        throw new IllegalStateException("Unhandled base type " + baseType);
    }
}
Also used : BitsTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition) DecimalTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition) IdentityrefTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition) EnumTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition) Int8TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int8TypeDefinition) UnionTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition) Int64TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int64TypeDefinition) BooleanTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition) InstanceIdentifierTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition) EmptyTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition) Uint16TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Uint16TypeDefinition) Int16TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition) Int32TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition) TypeStatement(org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement) LeafrefTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition) Uint8TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition) Uint32TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition) StringTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition) Uint64TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Uint64TypeDefinition) BinaryTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition)

Example 3 with Int16TypeDefinition

use of org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition in project yangtools by opendaylight.

the class YangParserTest method testNestedUnionResolving.

@Test
public void testNestedUnionResolving() {
    final LeafSchemaNode testleaf = (LeafSchemaNode) FOO.getDataChildByName(fooQName("custom-union-leaf"));
    assertTrue(testleaf.getType() instanceof UnionTypeDefinition);
    final UnionTypeDefinition type = (UnionTypeDefinition) testleaf.getType();
    assertEquals(bazQName("union1"), type.getQName());
    assertEquals(Optional.empty(), type.getUnits());
    assertEquals(Optional.empty(), type.getDefaultValue());
    final UnionTypeDefinition typeBase = type.getBaseType();
    assertEquals(bazQName("union2"), typeBase.getQName());
    assertEquals(Optional.empty(), typeBase.getUnits());
    assertEquals(Optional.empty(), typeBase.getDefaultValue());
    final UnionTypeDefinition union = typeBase.getBaseType();
    final List<TypeDefinition<?>> unionTypes = union.getTypes();
    assertEquals(2, unionTypes.size());
    assertEquals(BaseTypes.int32Type(), unionTypes.get(0));
    assertTrue(unionTypes.get(1) instanceof UnionTypeDefinition);
    final UnionTypeDefinition unionType1 = (UnionTypeDefinition) unionTypes.get(1);
    assertEquals(barQName("nested-union2"), unionType1.getQName());
    assertEquals(Optional.empty(), unionType1.getUnits());
    assertEquals(Optional.empty(), unionType1.getDefaultValue());
    final UnionTypeDefinition nestedUnion = unionType1.getBaseType();
    final List<TypeDefinition<?>> nestedUnion2Types = nestedUnion.getTypes();
    assertEquals(2, nestedUnion2Types.size());
    assertTrue(nestedUnion2Types.get(1) instanceof StringTypeDefinition);
    assertTrue(nestedUnion2Types.get(0) instanceof UnionTypeDefinition);
    final UnionTypeDefinition myUnionExt = (UnionTypeDefinition) nestedUnion2Types.get(0);
    assertEquals(barQName("my-union-ext"), myUnionExt.getQName());
    assertEquals(Optional.empty(), myUnionExt.getUnits());
    assertEquals(Optional.empty(), myUnionExt.getDefaultValue());
    final UnionTypeDefinition myUnion = myUnionExt.getBaseType();
    assertEquals(barQName("my-union"), myUnion.getQName());
    assertEquals(Optional.empty(), myUnion.getUnits());
    assertEquals(Optional.empty(), myUnion.getDefaultValue());
    final UnionTypeDefinition myUnionBase = myUnion.getBaseType();
    final List<TypeDefinition<?>> myUnionBaseTypes = myUnionBase.getTypes();
    assertEquals(2, myUnionBaseTypes.size());
    assertTrue(myUnionBaseTypes.get(0) instanceof Int16TypeDefinition);
    assertEquals(BaseTypes.int32Type(), myUnionBaseTypes.get(1));
    final Int16TypeDefinition int16Ext = (Int16TypeDefinition) myUnionBaseTypes.get(0);
    assertEquals(TypeDefinitions.INT16, int16Ext.getQName());
    assertEquals(Optional.empty(), int16Ext.getUnits());
    assertEquals(Optional.empty(), int16Ext.getDefaultValue());
    final Set<? extends Range<? extends Number>> ranges = int16Ext.getRangeConstraint().get().getAllowedRanges().asRanges();
    assertEquals(1, ranges.size());
    final Range<? extends Number> range = ranges.iterator().next();
    assertEquals(1, range.lowerEndpoint().intValue());
    assertEquals(100, range.upperEndpoint().intValue());
    assertEquals(BaseTypes.int16Type(), int16Ext.getBaseType());
}
Also used : Int16TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition) StringTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition) UnionTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) DecimalTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition) TypeDefinition(org.opendaylight.yangtools.yang.model.api.TypeDefinition) StringTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition) UnionTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition) Uint32TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition) Int16TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition) Int32TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition) Test(org.junit.Test)

Example 4 with Int16TypeDefinition

use of org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition in project yangtools by opendaylight.

the class YangParserTest method testTypedefUnion.

@Test
public void testTypedefUnion() {
    final LeafSchemaNode unionleaf = (LeafSchemaNode) FOO.getDataChildByName(fooQName("union-leaf"));
    assertTrue(unionleaf.getType() instanceof UnionTypeDefinition);
    final UnionTypeDefinition type = (UnionTypeDefinition) unionleaf.getType();
    assertEquals(barQName("my-union-ext"), type.getQName());
    assertEquals(Optional.empty(), type.getUnits());
    assertEquals(Optional.empty(), type.getDefaultValue());
    final UnionTypeDefinition baseType = type.getBaseType();
    assertEquals(barQName("my-union"), baseType.getQName());
    assertEquals(Optional.empty(), baseType.getUnits());
    assertEquals(Optional.empty(), baseType.getDefaultValue());
    final UnionTypeDefinition unionType = baseType.getBaseType();
    final List<TypeDefinition<?>> unionTypes = unionType.getTypes();
    assertEquals(2, unionTypes.size());
    final Int16TypeDefinition unionType1 = (Int16TypeDefinition) unionTypes.get(0);
    assertEquals(barQName("my-union"), baseType.getQName());
    assertEquals(Optional.empty(), unionType1.getUnits());
    assertEquals(Optional.empty(), unionType1.getDefaultValue());
    final RangeConstraint<?> ranges = unionType1.getRangeConstraint().get();
    assertEquals(1, ranges.getAllowedRanges().asRanges().size());
    final Range<?> range = ranges.getAllowedRanges().span();
    assertEquals((short) 1, range.lowerEndpoint());
    assertEquals((short) 100, range.upperEndpoint());
    assertEquals(BaseTypes.int16Type(), unionType1.getBaseType());
    assertEquals(BaseTypes.int32Type(), unionTypes.get(1));
}
Also used : Int16TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition) UnionTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) DecimalTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition) TypeDefinition(org.opendaylight.yangtools.yang.model.api.TypeDefinition) StringTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition) UnionTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition) Uint32TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition) Int16TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition) Int32TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition) Test(org.junit.Test)

Aggregations

Int16TypeDefinition (org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition)4 Int32TypeDefinition (org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition)4 Uint32TypeDefinition (org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition)4 Test (org.junit.Test)3 DecimalTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition)3 StringTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition)3 UnionTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition)3 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)2 TypeDefinition (org.opendaylight.yangtools.yang.model.api.TypeDefinition)2 Int64TypeDefinition (org.opendaylight.yangtools.yang.model.api.type.Int64TypeDefinition)2 Int8TypeDefinition (org.opendaylight.yangtools.yang.model.api.type.Int8TypeDefinition)2 Uint16TypeDefinition (org.opendaylight.yangtools.yang.model.api.type.Uint16TypeDefinition)2 Uint64TypeDefinition (org.opendaylight.yangtools.yang.model.api.type.Uint64TypeDefinition)2 Uint8TypeDefinition (org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition)2 TypeStatement (org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement)1 BinaryTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition)1 BitsTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition)1 BooleanTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition)1 EmptyTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition)1 EnumTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition)1