当前位置: 首页>>代码示例>>Java>>正文


Java EnumTypeDefinition类代码示例

本文整理汇总了Java中org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition的典型用法代码示例。如果您正苦于以下问题:Java EnumTypeDefinition类的具体用法?Java EnumTypeDefinition怎么用?Java EnumTypeDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EnumTypeDefinition类属于org.opendaylight.yangtools.yang.model.api.type包,在下文中一共展示了EnumTypeDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
@Test
public void test() throws Exception {
    final SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug2872");
    assertNotNull(schema);

    final QNameModule bug2872module = QNameModule.create(URI.create("bug2872"), Revision.of("2016-06-08"));
    final QName foo = QName.create(bug2872module, "bar");

    final DataSchemaNode dataSchemaNode = schema.getDataChildByName(foo);
    assertTrue(dataSchemaNode instanceof LeafSchemaNode);
    final LeafSchemaNode myLeaf = (LeafSchemaNode) dataSchemaNode;

    final TypeDefinition<?> type = myLeaf.getType();
    assertTrue(type instanceof EnumTypeDefinition);
    final EnumTypeDefinition myEnum = (EnumTypeDefinition) type;

    final List<EnumTypeDefinition.EnumPair> values = myEnum.getValues();
    assertEquals(2, values.size());

    final List<String> valueNames = new ArrayList<>();
    for (EnumTypeDefinition.EnumPair pair : values) {
        valueNames.add(pair.getName());
    }
    assertTrue(valueNames.contains("value-one"));
    assertTrue(valueNames.contains("value-two"));
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:27,代码来源:Bug2872Test.java

示例2: buildType

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
@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);
        }
    }

    if (getBaseType() == null) {
        return new BaseEnumerationType(getPath(), getUnknownSchemaNodes(), map.values());
    } else {
        return new RestrictedEnumerationType(getBaseType(), getPath(), getUnknownSchemaNodes(), map.values());
    }
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:19,代码来源:EnumerationTypeBuilder.java

示例3: resolveEnumFromTypeDefinition

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
private Enumeration resolveEnumFromTypeDefinition(final EnumTypeDefinition enumTypeDef, final String enumName) {
    if (enumTypeDef == null) {
        throw new IllegalArgumentException("EnumTypeDefinition reference cannot be NULL!");
    }
    if (enumTypeDef.getValues() == null) {
        throw new IllegalArgumentException("EnumTypeDefinition MUST contain at least ONE value definition!");
    }
    if (enumTypeDef.getQName() == null) {
        throw new IllegalArgumentException("EnumTypeDefinition MUST contain NON-NULL QName!");
    }
    if (enumTypeDef.getQName().getLocalName() == null) {
        throw new IllegalArgumentException("Local Name in EnumTypeDefinition QName cannot be NULL!");
    }

    final String enumerationName = parseToClassName(enumName);

    Module module = findParentModuleForTypeDefinition(schemaContext, enumTypeDef);
    final String basePackageName = moduleNamespaceToPackageName(module);

    final EnumBuilder enumBuilder = new EnumerationBuilderImpl(basePackageName, enumerationName);
    updateEnumPairsFromEnumTypeDef(enumTypeDef, enumBuilder);
    return enumBuilder.toInstance(null);
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:24,代码来源:TypeProviderImpl.java

示例4: resolveInnerEnumFromTypeDefinition

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
private EnumBuilder resolveInnerEnumFromTypeDefinition(final EnumTypeDefinition enumTypeDef, final String enumName,
        final GeneratedTypeBuilder typeBuilder) {
    if (enumTypeDef == null) {
        throw new IllegalArgumentException("EnumTypeDefinition reference cannot be NULL!");
    }
    if (enumTypeDef.getValues() == null) {
        throw new IllegalArgumentException("EnumTypeDefinition MUST contain at least ONE value definition!");
    }
    if (enumTypeDef.getQName() == null) {
        throw new IllegalArgumentException("EnumTypeDefinition MUST contain NON-NULL QName!");
    }
    if (enumTypeDef.getQName().getLocalName() == null) {
        throw new IllegalArgumentException("Local Name in EnumTypeDefinition QName cannot be NULL!");
    }
    if (typeBuilder == null) {
        throw new IllegalArgumentException("Generated Type Builder reference cannot be NULL!");
    }

    final String enumerationName = parseToClassName(enumName);
    final EnumBuilder enumBuilder = typeBuilder.addEnumeration(enumerationName);

    updateEnumPairsFromEnumTypeDef(enumTypeDef, enumBuilder);

    return enumBuilder;
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:26,代码来源:TypeProviderImpl.java

示例5: updateEnumPairsFromEnumTypeDef

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
private void updateEnumPairsFromEnumTypeDef(final EnumTypeDefinition enumTypeDef, final EnumBuilder enumBuilder) {
    if (enumBuilder != null) {
        final List<EnumPair> enums = enumTypeDef.getValues();
        if (enums != null) {
            int listIndex = 0;
            for (final EnumPair enumPair : enums) {
                if (enumPair != null) {
                    final String enumPairName = parseToClassName(enumPair.getName());
                    Integer enumPairValue = enumPair.getValue();

                    if (enumPairValue == null) {
                        enumPairValue = listIndex;
                    }
                    enumBuilder.addValue(enumPairName, enumPairValue);
                    listIndex++;
                }
            }
        }
    }
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:21,代码来源:TypeProviderImpl.java

示例6: emitTypeBodyNodes

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
private void emitTypeBodyNodes(final TypeDefinition<?> typeDef) {
    if (typeDef instanceof DecimalTypeDefinition) {
        emitDecimal64Specification((DecimalTypeDefinition) typeDef);
    } else if (typeDef instanceof RangeRestrictedTypeDefinition) {
        emitRangeRestrictedSpecification((RangeRestrictedTypeDefinition<?, ?>) typeDef);
    } else if (typeDef instanceof StringTypeDefinition) {
        emitStringRestrictions((StringTypeDefinition) typeDef);
    } else if (typeDef instanceof EnumTypeDefinition) {
        emitEnumSpecification((EnumTypeDefinition) typeDef);
    } else if (typeDef instanceof LeafrefTypeDefinition) {
        emitLeafrefSpecification((LeafrefTypeDefinition) typeDef);
    } else if (typeDef instanceof IdentityrefTypeDefinition) {
        emitIdentityrefSpecification((IdentityrefTypeDefinition) typeDef);
    } else if (typeDef instanceof InstanceIdentifierTypeDefinition) {
        emitInstanceIdentifierSpecification((InstanceIdentifierTypeDefinition) typeDef);
    } else if (typeDef instanceof BitsTypeDefinition) {
        emitBitsSpecification((BitsTypeDefinition) typeDef);
    } else if (typeDef instanceof UnionTypeDefinition) {
        emitUnionSpecification((UnionTypeDefinition) typeDef);
    } else if (typeDef instanceof BinaryTypeDefinition) {
        ((BinaryTypeDefinition) typeDef).getLengthConstraint().ifPresent(this::emitLength);
    } else if (typeDef instanceof BooleanTypeDefinition || typeDef instanceof EmptyTypeDefinition) {
        // NOOP
    } else {
        throw new IllegalArgumentException("Not supported type " + typeDef.getClass());
    }
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:28,代码来源:SchemaContextEmitter.java

示例7: EnumStringCodec

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
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;
    }
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:15,代码来源:EnumStringCodec.java

示例8: fromType

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
public static TypeDefinitionAwareCodec<?, ?> fromType(final TypeDefinition<?> typeDefinition) {
    final TypeDefinitionAwareCodec<?, ?> codec;

    if (typeDefinition instanceof BinaryTypeDefinition) {
        codec = BinaryStringCodec.from((BinaryTypeDefinition)typeDefinition);
    } else if (typeDefinition instanceof BitsTypeDefinition) {
        codec = BitsStringCodec.from((BitsTypeDefinition)typeDefinition);
    } else if (typeDefinition instanceof BooleanTypeDefinition) {
        codec = BooleanStringCodec.from((BooleanTypeDefinition)typeDefinition);
    } else if (typeDefinition instanceof DecimalTypeDefinition) {
        codec = DecimalStringCodec.from((DecimalTypeDefinition)typeDefinition);
    } else if (typeDefinition instanceof EmptyTypeDefinition) {
        codec = EmptyStringCodec.INSTANCE;
    } else if (typeDefinition instanceof EnumTypeDefinition) {
        codec = EnumStringCodec.from((EnumTypeDefinition)typeDefinition);
    } else if (typeDefinition instanceof Int8TypeDefinition) {
        codec = AbstractIntegerStringCodec.from((Int8TypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof Int16TypeDefinition) {
        codec = AbstractIntegerStringCodec.from((Int16TypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof Int32TypeDefinition) {
        codec = AbstractIntegerStringCodec.from((Int32TypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof Int64TypeDefinition) {
        codec = AbstractIntegerStringCodec.from((Int64TypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof StringTypeDefinition) {
        codec = StringStringCodec.from((StringTypeDefinition)typeDefinition);
    } else if (typeDefinition instanceof UnionTypeDefinition) {
        codec = UnionStringCodec.from((UnionTypeDefinition)typeDefinition);
    } else if (typeDefinition instanceof Uint8TypeDefinition) {
        codec = AbstractIntegerStringCodec.from((Uint8TypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof Uint16TypeDefinition) {
        codec = AbstractIntegerStringCodec.from((Uint16TypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof Uint32TypeDefinition) {
        codec = AbstractIntegerStringCodec.from((Uint32TypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof Uint64TypeDefinition) {
        codec = AbstractIntegerStringCodec.from((Uint64TypeDefinition) typeDefinition);
    } else {
        codec = null;
    }
    return codec;
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:41,代码来源:TypeDefinitionAwareCodec.java

示例9: toEnumTypeDefinition

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
public static EnumTypeDefinition toEnumTypeDefinition(final String... enums) {
    final EnumerationTypeBuilder b = BaseTypes.enumerationTypeBuilder(mock(SchemaPath.class));
    int val = 0;
    for (String en : enums) {
        EnumTypeDefinition.EnumPair mockEnum = mock(EnumTypeDefinition.EnumPair.class);
        when(mockEnum.getName()).thenReturn(en);
        when(mockEnum.getValue()).thenReturn(val);
        b.addEnum(mockEnum);
        val++;
    }

    return b.build();
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:14,代码来源:TypeDefinitionAwareCodecTestHelper.java

示例10: EnumTypeEffectiveStatementImpl

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
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();
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:32,代码来源:EnumTypeEffectiveStatementImpl.java

示例11: getBaseTypeEnumValue

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
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());
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:12,代码来源:EnumTypeEffectiveStatementImpl.java

示例12: testEnum

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
@Test
public void testEnum() {
    currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-enum"));
    assertNotNull(currentLeaf.getType());
    final List<EnumTypeDefinition.EnumPair> enumEffIter = ((EnumTypeDefinition) currentLeaf.getType()).getValues();
    final EnumPair enumEff = enumEffIter.iterator().next();

    final EnumTypeDefinition enumSpecEff = ((EnumSpecificationEffectiveStatement)
            ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
            .getTypeDefinition();

    assertEquals("enumeration", enumSpecEff.getQName().getLocalName());
    assertEquals("enumeration", enumSpecEff.getPath().getLastComponent().getLocalName());
    assertEquals(Optional.empty(), enumSpecEff.getDefaultValue());
    assertEquals(3, enumSpecEff.getValues().size());
    assertNull(enumSpecEff.getBaseType());
    assertNotNull(enumSpecEff.getUnknownSchemaNodes());
    assertEquals(Status.CURRENT, enumSpecEff.getStatus());
    assertFalse(enumSpecEff.getDescription().isPresent());
    assertFalse(enumSpecEff.getReference().isPresent());
    assertEquals(Optional.empty(), enumSpecEff.getUnits());
    assertNotNull(enumSpecEff.toString());
    assertNotNull(enumSpecEff.hashCode());
    assertFalse(enumSpecEff.equals(null));
    assertFalse(enumSpecEff.equals("test"));
    assertTrue(enumSpecEff.equals(enumSpecEff));

    assertEquals("zero", enumEff.getName());
    assertNotNull(enumEff.getUnknownSchemaNodes());
    assertEquals(Optional.of("test enum"), enumEff.getDescription());
    assertEquals(Optional.of("test enum ref"), enumEff.getReference());
    assertEquals(Status.CURRENT, enumEff.getStatus());
    assertEquals(0, enumEff.getValue());
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:35,代码来源:EffectiveStatementTypeTest.java

示例13: testIPVersion

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
@Test
public void testIPVersion() {
    Module tested = TestUtils.findModule(context, "ietf-inet-types").get();
    Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
    assertEquals(14, typedefs.size());

    TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-version");
    assertTrue(type.getDescription().get().contains("This value represents the version of the IP protocol."));
    assertTrue(type.getReference().get().contains("RFC 2460: Internet Protocol, Version 6 (IPv6) Specification"));

    EnumTypeDefinition enumType = (EnumTypeDefinition) type.getBaseType();
    List<EnumPair> values = enumType.getValues();
    assertEquals(3, values.size());

    EnumPair value0 = values.get(0);
    assertEquals("unknown", value0.getName());
    assertEquals(0, value0.getValue());
    assertEquals(Optional.of("An unknown or unspecified version of the Internet protocol."),
        value0.getDescription());

    EnumPair value1 = values.get(1);
    assertEquals("ipv4", value1.getName());
    assertEquals(1, value1.getValue());
    assertEquals(Optional.of("The IPv4 protocol as defined in RFC 791."), value1.getDescription());

    EnumPair value2 = values.get(2);
    assertEquals("ipv6", value2.getName());
    assertEquals(2, value2.getValue());
    assertEquals(Optional.of("The IPv6 protocol as defined in RFC 2460."), value2.getDescription());
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:31,代码来源:TypesResolutionTest.java

示例14: testEnumeration

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
@Test
public void testEnumeration() {
    Module tested = TestUtils.findModule(context, "custom-types-test").get();
    Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();

    TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-version");
    EnumTypeDefinition enumType = (EnumTypeDefinition) type.getBaseType();
    List<EnumPair> values = enumType.getValues();
    assertEquals(4, values.size());

    EnumPair value0 = values.get(0);
    assertEquals("unknown", value0.getName());
    assertEquals(0, value0.getValue());
    assertEquals(Optional.of("An unknown or unspecified version of the Internet protocol."),
        value0.getDescription());

    EnumPair value1 = values.get(1);
    assertEquals("ipv4", value1.getName());
    assertEquals(19, value1.getValue());
    assertEquals(Optional.of("The IPv4 protocol as defined in RFC 791."), value1.getDescription());

    EnumPair value2 = values.get(2);
    assertEquals("ipv6", value2.getName());
    assertEquals(7, value2.getValue());
    assertEquals(Optional.of("The IPv6 protocol as defined in RFC 2460."), value2.getDescription());

    EnumPair value3 = values.get(3);
    assertEquals("default", value3.getName());
    assertEquals(20, value3.getValue());
    assertEquals(Optional.of("default ip"), value3.getDescription());
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:32,代码来源:TypesResolutionTest.java

示例15: testIanaTimezones

import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; //导入依赖的package包/类
@Test
public void testIanaTimezones() {
    Module tested = TestUtils.findModule(context, "iana-timezones").get();
    Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
    TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "iana-timezone");

    String expectedDesc = "A timezone location as defined by the IANA timezone";
    assertTrue(testedType.getDescription().get().contains(expectedDesc));
    assertFalse(testedType.getReference().isPresent());
    assertEquals(Status.CURRENT, testedType.getStatus());

    QName testedTypeQName = testedType.getQName();
    assertEquals(URI.create("urn:ietf:params:xml:ns:yang:iana-timezones"), testedTypeQName.getNamespace());
    assertEquals(Revision.ofNullable("2012-07-09"), testedTypeQName.getRevision());
    assertEquals("iana-timezone", testedTypeQName.getLocalName());

    EnumTypeDefinition enumType = (EnumTypeDefinition) testedType.getBaseType();
    List<EnumPair> values = enumType.getValues();
    // 0-414
    assertEquals(415, values.size());

    EnumPair enum168 = values.get(168);
    assertEquals("America/Danmarkshavn", enum168.getName());
    assertEquals(168, enum168.getValue());
    assertEquals(Optional.of("east coast, north of Scoresbysund"), enum168.getDescription());

    EnumPair enum374 = values.get(374);
    assertEquals("America/Indiana/Winamac", enum374.getName());
    assertEquals(374, enum374.getValue());
    assertEquals(Optional.of("Eastern Time - Indiana - Pulaski County"), enum374.getDescription());
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:32,代码来源:TypesResolutionTest.java


注:本文中的org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。