Some users, like the java binding, need to distriguish the various
integer base types in order to produce the correct type specification.
Add utility methods which check the concrete integer base type
(uint{8,16,32,64} and int{8,16,32,64}.
Change-Id: Idf4c71be6b135d68715fe095e1cc1f5033c4824c
Signed-off-by: Robert Varga <robert.varga@pantheon.sk>
import com.google.common.annotations.Beta;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import com.google.common.annotations.Beta;
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;
import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
return BaseInt8Type.INSTANCE;
}
return BaseInt8Type.INSTANCE;
}
+ public static boolean isInt8(final TypeDefinition<?> type) {
+ return BaseInt8Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ }
+
public static IntegerTypeDefinition int16Type() {
return BaseInt16Type.INSTANCE;
}
public static IntegerTypeDefinition int16Type() {
return BaseInt16Type.INSTANCE;
}
+ public static boolean isInt16(final TypeDefinition<?> type) {
+ return BaseInt16Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ }
+
public static IntegerTypeDefinition int32Type() {
return BaseInt32Type.INSTANCE;
}
public static IntegerTypeDefinition int32Type() {
return BaseInt32Type.INSTANCE;
}
+ public static boolean isInt32(final TypeDefinition<?> type) {
+ return BaseInt32Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ }
+
public static IntegerTypeDefinition int64Type() {
return BaseInt64Type.INSTANCE;
}
public static IntegerTypeDefinition int64Type() {
return BaseInt64Type.INSTANCE;
}
+ public static boolean isInt64(final TypeDefinition<?> type) {
+ return BaseInt64Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ }
+
public static LeafrefTypeBuilder leafrefTypeBuilder(final SchemaPath path) {
return new LeafrefTypeBuilder(path);
}
public static LeafrefTypeBuilder leafrefTypeBuilder(final SchemaPath path) {
return new LeafrefTypeBuilder(path);
}
return BaseUint8Type.INSTANCE;
}
return BaseUint8Type.INSTANCE;
}
+ public static boolean isUint8(final TypeDefinition<?> type) {
+ return BaseUint8Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ }
+
public static UnsignedIntegerTypeDefinition uint16Type() {
return BaseUint16Type.INSTANCE;
}
public static UnsignedIntegerTypeDefinition uint16Type() {
return BaseUint16Type.INSTANCE;
}
+ public static boolean isUint16(final TypeDefinition<?> type) {
+ return BaseUint16Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ }
+
public static UnsignedIntegerTypeDefinition uint32Type() {
return BaseUint32Type.INSTANCE;
}
public static UnsignedIntegerTypeDefinition uint32Type() {
return BaseUint32Type.INSTANCE;
}
+ public static boolean isUint32(final TypeDefinition<?> type) {
+ return BaseUint32Type.INSTANCE.getPath().equals(findBaseTypePath(type));
+ }
+
public static UnsignedIntegerTypeDefinition uint64Type() {
return BaseUint64Type.INSTANCE;
}
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) {
+ TypeDefinition<?> ret = type;
+ while (ret.getBaseType() != null) {
+ ret = ret.getBaseType();
+ }
+ return ret.getPath();
+ }