package org.opendaylight.yangtools.yang.model.util.type;
import com.google.common.annotations.Beta;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
}
public static boolean isInt8(final TypeDefinition<?> type) {
- return BaseInt8Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ return BaseInt8Type.INSTANCE.getPath().equals(type.getPath());
}
public static IntegerTypeDefinition int16Type() {
}
public static boolean isInt16(final TypeDefinition<?> type) {
- return BaseInt16Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ return BaseInt16Type.INSTANCE.getPath().equals(type.getPath());
}
public static IntegerTypeDefinition int32Type() {
}
public static boolean isInt32(final TypeDefinition<?> type) {
- return BaseInt32Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ return BaseInt32Type.INSTANCE.getPath().equals(type.getPath());
}
public static IntegerTypeDefinition int64Type() {
}
public static boolean isInt64(final TypeDefinition<?> type) {
- return BaseInt64Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ return BaseInt64Type.INSTANCE.getPath().equals(type.getPath());
}
public static LeafrefTypeBuilder leafrefTypeBuilder(final SchemaPath path) {
return BaseUint8Type.INSTANCE;
}
- public static boolean isUint8(final TypeDefinition<?> type) {
- return BaseUint8Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ /**
+ * Check if a particular type is the base type for uint8. Unlike {@link DerivedTypes#isUint8(TypeDefinition)},
+ * this method does not perform recursive base type lookup.
+ *
+ * @param type The type to check
+ * @return If the type corresponds to the base uint8 type.
+ * @throws NullPointerException if type is null
+ */
+ public static boolean isUint8(@Nonnull final TypeDefinition<?> type) {
+ return BaseUint8Type.INSTANCE.getPath().equals(type.getPath());
}
public static UnsignedIntegerTypeDefinition uint16Type() {
return BaseUint16Type.INSTANCE;
}
- public static boolean isUint16(final TypeDefinition<?> type) {
- return BaseUint16Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ /**
+ * Check if a particular type is the base type for uint16. Unlike {@link DerivedTypes#isUint16(TypeDefinition)},
+ * this method does not perform recursive base type lookup.
+ *
+ * @param type The type to check
+ * @return If the type corresponds to the base uint16 type.
+ * @throws NullPointerException if type is null
+ */
+ public static boolean isUint16(@Nonnull final TypeDefinition<?> type) {
+ return BaseUint16Type.INSTANCE.getPath().equals(type.getPath());
}
public static UnsignedIntegerTypeDefinition uint32Type() {
return BaseUint32Type.INSTANCE;
}
- public static boolean isUint32(final TypeDefinition<?> type) {
- return BaseUint32Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ /**
+ * Check if a particular type is the base type for uint32. Unlike {@link DerivedTypes#isUint32(TypeDefinition)},
+ * this method does not perform recursive base type lookup.
+ *
+ * @param type The type to check
+ * @return If the type corresponds to the base uint32 type.
+ * @throws NullPointerException if type is null
+ */
+ public static boolean isUint32(@Nonnull final TypeDefinition<?> type) {
+ return BaseUint32Type.INSTANCE.getPath().equals(type.getPath());
}
public static UnsignedIntegerTypeDefinition uint64Type() {
return BaseUint64Type.INSTANCE;
}
- public static boolean isUint64(final TypeDefinition<?> type) {
- return BaseUint64Type.INSTANCE.getPath().equals(findBaseTypePath(type));
- }
-
- private static SchemaPath findBaseTypePath(final TypeDefinition<?> type) {
+ /**
+ * Check if a particular type is the base type for uint64. Unlike {@link DerivedTypes#isUint64(TypeDefinition)},
+ * this method does not perform recursive base type lookup.
+ *
+ * @param type The type to check
+ * @return If the type corresponds to the base uint64 type.
+ * @throws NullPointerException if type is null
+ */
+ public static boolean isUint64(@Nonnull final TypeDefinition<?> type) {
+ return BaseUint64Type.INSTANCE.getPath().equals(type.getPath());
+ }
+
+ /**
+ * Return the base type of a particular type. This method performs recursive lookup through the type's base type
+ * until it finds the last element and returns it. If the argument is already the base type, it is returned as is.
+ *
+ * @param type Type for which to find the base type
+ * @return Base type of specified type
+ * @throws NullPointerException if type is null
+ */
+ public static TypeDefinition<?> baseTypeOf(@Nonnull final TypeDefinition<?> type) {
TypeDefinition<?> ret = type;
while (ret.getBaseType() != null) {
ret = ret.getBaseType();
}
- return ret.getPath();
+ return ret;
}
}
}
}
- public static DerivedTypeBuilder<BinaryTypeDefinition> derivedBinaryBuilder(@Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) {
+ /**
+ * Check if a particular type is corresponds to int8. Unlike {@link BaseTypes#isInt8(TypeDefinition)}, this
+ * method performs recursive lookup to find the base type.
+ *
+ * @param type The type to check
+ * @return If the type belongs to the int8 type family.
+ * @throws NullPointerException if type is null
+ */
+ public static boolean isInt8(@Nonnull final TypeDefinition<?> type) {
+ return BaseTypes.isInt8(BaseTypes.baseTypeOf(type));
+ }
+
+ /**
+ * Check if a particular type is corresponds to int16. Unlike {@link BaseTypes#isInt16(TypeDefinition)}, this
+ * method performs recursive lookup to find the base type.
+ *
+ * @param type The type to check
+ * @return If the type belongs to the int16 type family.
+ * @throws NullPointerException if type is null
+ */
+ public static boolean isInt16(@Nonnull final TypeDefinition<?> type) {
+ return BaseTypes.isInt16(BaseTypes.baseTypeOf(type));
+ }
+
+ /**
+ * Check if a particular type is corresponds to int32. Unlike {@link BaseTypes#isInt32(TypeDefinition)}, this
+ * method performs recursive lookup to find the base type.
+ *
+ * @param type The type to check
+ * @return If the type belongs to the int32 type family.
+ * @throws NullPointerException if type is null
+ */
+ public static boolean isInt32(@Nonnull final TypeDefinition<?> type) {
+ return BaseTypes.isInt32(BaseTypes.baseTypeOf(type));
+ }
+
+ /**
+ * Check if a particular type is corresponds to int64. Unlike {@link BaseTypes#isInt64(TypeDefinition)}, this
+ * method performs recursive lookup to find the base type.
+ *
+ * @param type The type to check
+ * @return If the type belongs to the int64 type family.
+ * @throws NullPointerException if type is null
+ */
+ public static boolean isInt64(@Nonnull final TypeDefinition<?> type) {
+ return BaseTypes.isInt64(BaseTypes.baseTypeOf(type));
+ }
+
+ /**
+ * Check if a particular type is corresponds to uint8. Unlike {@link BaseTypes#isUint8(TypeDefinition)}, this
+ * method performs recursive lookup to find the base type.
+ *
+ * @param type The type to check
+ * @return If the type belongs to the uint8 type family.
+ * @throws NullPointerException if type is null
+ */
+ public static boolean isUint8(@Nonnull final TypeDefinition<?> type) {
+ return BaseTypes.isUint8(BaseTypes.baseTypeOf(type));
+ }
+
+ /**
+ * Check if a particular type is corresponds to uint16. Unlike {@link BaseTypes#isUint16(TypeDefinition)}, this
+ * method performs recursive lookup to find the base type.
+ *
+ * @param type The type to check
+ * @return If the type belongs to the uint16 type family.
+ * @throws NullPointerException if type is null
+ */
+ public static boolean isUint16(@Nonnull final TypeDefinition<?> type) {
+ return BaseTypes.isUint16(BaseTypes.baseTypeOf(type));
+ }
+
+ /**
+ * Check if a particular type is corresponds to uint32. Unlike {@link BaseTypes#isUint32(TypeDefinition)}, this
+ * method performs recursive lookup to find the base type.
+ *
+ * @param type The type to check
+ * @return If the type belongs to the uint32 type family.
+ * @throws NullPointerException if type is null
+ */
+ public static boolean isUint32(@Nonnull final TypeDefinition<?> type) {
+ return BaseTypes.isUint32(BaseTypes.baseTypeOf(type));
+ }
+
+ /**
+ * Check if a particular type is corresponds to uint64. Unlike {@link BaseTypes#isUint64(TypeDefinition)}, this
+ * method performs recursive lookup to find the base type.
+ *
+ * @param type The type to check
+ * @return If the type belongs to the uint64 type family.
+ * @throws NullPointerException if type is null
+ */
+ public static boolean isUint64(@Nonnull final TypeDefinition<?> type) {
+ return BaseTypes.isUint64(BaseTypes.baseTypeOf(type));
+ }
+
+ private static DerivedTypeBuilder<BinaryTypeDefinition> derivedBinaryBuilder(@Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) {
return new DerivedTypeBuilder<BinaryTypeDefinition>(baseType, path) {
@Override
public BinaryTypeDefinition build() {
};
}
- public static DerivedTypeBuilder<BitsTypeDefinition> derivedBitsBuilder(final BitsTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<BitsTypeDefinition> derivedBitsBuilder(final BitsTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<BitsTypeDefinition>(baseType, path) {
@Override
public BitsTypeDefinition build() {
};
}
- public static DerivedTypeBuilder<BooleanTypeDefinition> derivedBooleanBuilder(@Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) {
+ private static DerivedTypeBuilder<BooleanTypeDefinition> derivedBooleanBuilder(@Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) {
return new DerivedTypeBuilder<BooleanTypeDefinition>(baseType, path) {
@Override
public BooleanTypeDefinition build() {
};
}
- public static DerivedTypeBuilder<DecimalTypeDefinition> derivedDecimalBuilder(final DecimalTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<DecimalTypeDefinition> derivedDecimalBuilder(final DecimalTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<DecimalTypeDefinition>(baseType, path) {
@Override
public DecimalTypeDefinition build() {
};
}
- public static DerivedTypeBuilder<EmptyTypeDefinition> derivedEmptyBuilder(final EmptyTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<EmptyTypeDefinition> derivedEmptyBuilder(final EmptyTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<EmptyTypeDefinition>(baseType, path) {
@Override
public EmptyTypeDefinition build() {
};
}
- public static DerivedTypeBuilder<EnumTypeDefinition> derivedEnumerationBuilder(final EnumTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<EnumTypeDefinition> derivedEnumerationBuilder(final EnumTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<EnumTypeDefinition>(baseType, path) {
@Override
public EnumTypeDefinition build() {
};
}
- public static DerivedTypeBuilder<IdentityrefTypeDefinition> derivedIdentityrefBuilder(final IdentityrefTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<IdentityrefTypeDefinition> derivedIdentityrefBuilder(final IdentityrefTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<IdentityrefTypeDefinition>(baseType, path) {
@Override
public IdentityrefTypeDefinition build() {
};
}
- public static DerivedTypeBuilder<InstanceIdentifierTypeDefinition> derivedInstanceIdentifierBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<InstanceIdentifierTypeDefinition> derivedInstanceIdentifierBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<InstanceIdentifierTypeDefinition>(baseType, path) {
@Override
public InstanceIdentifierTypeDefinition build() {
};
}
- public static DerivedTypeBuilder<IntegerTypeDefinition> derivedIntegerBuilder(final IntegerTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<IntegerTypeDefinition> derivedIntegerBuilder(final IntegerTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<IntegerTypeDefinition>(baseType, path) {
@Override
public IntegerTypeDefinition build() {
};
}
- public static DerivedTypeBuilder<LeafrefTypeDefinition> derivedLeafrefBuilder(final LeafrefTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<LeafrefTypeDefinition> derivedLeafrefBuilder(final LeafrefTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<LeafrefTypeDefinition>(baseType, path) {
@Override
public LeafrefTypeDefinition build() {
};
}
- public static DerivedTypeBuilder<StringTypeDefinition> derivedStringBuilder(final StringTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<StringTypeDefinition> derivedStringBuilder(final StringTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<StringTypeDefinition>(baseType, path) {
@Override
public StringTypeDefinition build() {
};
}
- public static DerivedTypeBuilder<UnionTypeDefinition> derivedUnionBuilder(final UnionTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<UnionTypeDefinition> derivedUnionBuilder(final UnionTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<UnionTypeDefinition>(baseType, path) {
@Override
public DerivedUnionType build() {
};
}
- public static DerivedTypeBuilder<UnsignedIntegerTypeDefinition> derivedUnsignedBuilder(final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<UnsignedIntegerTypeDefinition> derivedUnsignedBuilder(final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<UnsignedIntegerTypeDefinition>(baseType, path) {
@Override
public UnsignedIntegerTypeDefinition build() {