import static java.util.Objects.requireNonNull;
+import com.google.common.annotations.Beta;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.mdsal.binding.model.api.AbstractBaseType;
import org.opendaylight.mdsal.binding.model.api.BaseTypeWithRestrictions;
import org.opendaylight.mdsal.binding.model.api.ConcreteType;
import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
import org.opendaylight.mdsal.binding.model.api.Type;
import org.opendaylight.mdsal.binding.model.api.WildcardType;
import org.opendaylight.yangtools.concepts.Builder;
-import org.opendaylight.yangtools.yang.binding.Augmentable;
-import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
CacheBuilder.newBuilder().weakKeys().build(TYPE_LOADER);
public static final @NonNull ConcreteType BOOLEAN = typeForClass(Boolean.class);
+ public static final @NonNull ConcreteType BYTE_ARRAY = typeForClass(byte[].class);
+ public static final @NonNull ConcreteType CLASS = typeForClass(Class.class);
public static final @NonNull ConcreteType STRING = typeForClass(String.class);
public static final @NonNull ConcreteType VOID = typeForClass(Void.class);
- public static final @NonNull ConcreteType BYTE_ARRAY = typeForClass(byte[].class);
private static final @NonNull ConcreteType BUILDER = typeForClass(Builder.class);
- private static final @NonNull ConcreteType CLASS = typeForClass(Class.class);
private static final @NonNull ConcreteType LIST_TYPE = typeForClass(List.class);
private static final @NonNull ConcreteType LISTENABLE_FUTURE = typeForClass(ListenableFuture.class);
private static final @NonNull ConcreteType MAP_TYPE = typeForClass(Map.class);
private static final @NonNull ConcreteType OBJECT = typeForClass(Object.class);
+ private static final @NonNull ConcreteType PRIMITIVE_BOOLEAN = typeForClass(boolean.class);
+ private static final @NonNull ConcreteType PRIMITIVE_INT = typeForClass(int.class);
private static final @NonNull ConcreteType PRIMITIVE_VOID = typeForClass(void.class);
private static final @NonNull ConcreteType SERIALIZABLE = typeForClass(Serializable.class);
private static final @NonNull ConcreteType SET_TYPE = typeForClass(Set.class);
-
- private static final @NonNull ConcreteType AUGMENTABLE = typeForClass(Augmentable.class);
- private static final @NonNull ConcreteType AUGMENTATION = typeForClass(Augmentation.class);
+ private static final @NonNull ParameterizedType LIST_TYPE_WILDCARD = parameterizedTypeFor(LIST_TYPE);
/**
* It is not desirable to create instance of this class.
return OBJECT;
}
+ /**
+ * Returns an instance of {@link ConcreteType} which represents JAVA <code>boolean</code> type.
+ *
+ * @return <code>ConcreteType</code> instance which represents JAVA <code>boolean</code>
+ */
+ public static @NonNull ConcreteType primitiveBooleanType() {
+ return PRIMITIVE_BOOLEAN;
+ }
+
+ /**
+ * Returns an instance of {@link ConcreteType} which represents JAVA <code>int</code> type.
+ *
+ * @return <code>ConcreteType</code> instance which represents JAVA <code>int</code>
+ */
+ public static @NonNull ConcreteType primitiveIntType() {
+ return PRIMITIVE_INT;
+ }
+
/**
* Returns an instance of {@link ConcreteType} which represents JAVA <code>void</code> type.
*
public static @NonNull ConcreteType typeForClass(final @NonNull Class<?> cls,
final @Nullable Restrictions restrictions) {
- if (restrictions == null) {
- return typeForClass(cls);
- }
+ return restrictions == null ? typeForClass(cls) : restrictedType(JavaTypeName.create(cls), restrictions);
+ }
- final JavaTypeName identifier = JavaTypeName.create(cls);
- if (restrictions instanceof DefaultRestrictions) {
- return new ConcreteTypeImpl(identifier, restrictions);
- }
- return new BaseTypeWithRestrictionsImpl(identifier, restrictions);
+ @Beta
+ public static @NonNull ConcreteType restrictedType(final Type type, final @NonNull Restrictions restrictions) {
+ return restrictedType(type.getIdentifier(), restrictions);
+ }
+
+ private static @NonNull ConcreteType restrictedType(final JavaTypeName identifier,
+ final @NonNull Restrictions restrictions) {
+ return restrictions instanceof DefaultRestrictions ? new ConcreteTypeImpl(identifier, restrictions)
+ : new BaseTypeWithRestrictionsImpl(identifier, restrictions);
}
/**
return parameterizedTypeFor(MAP_TYPE, keyType, valueType);
}
+ public static boolean isMapType(final ParameterizedType type) {
+ return MAP_TYPE.equals(type.getRawType());
+ }
+
+ public static boolean isMapType(final Type type) {
+ return type instanceof ParameterizedType && isMapType((ParameterizedType) type);
+ }
+
/**
* Returns an instance of {@link ParameterizedType} describing the typed {@link Set}<V> with concrete type
* of value.
return parameterizedTypeFor(LIST_TYPE, valueType);
}
+ /**
+ * Returns an instance of {@link ParameterizedType} describing the typed {@link List}<?>.
+ *
+ * @return Description of type instance of List
+ */
+ public static @NonNull ParameterizedType listTypeWildcard() {
+ return LIST_TYPE_WILDCARD;
+ }
+
public static boolean isListType(final ParameterizedType type) {
return LIST_TYPE.equals(type.getRawType());
}
return new WildcardTypeImpl(identifier);
}
- /**
- * Creates instance of
- * {@link org.opendaylight.mdsal.binding.model.api.ParameterizedType
- * ParameterizedType} where raw type is
- * {@link org.opendaylight.yangtools.yang.binding.Augmentable} and actual
- * parameter is <code>valueType</code>.
- *
- * @param valueType JAVA <code>Type</code> with actual parameter
- * @return <code>ParametrizedType</code> representation of raw type
- * <code>Augmentable</code> with actual parameter
- * <code>valueType</code>
- */
- public static @NonNull ParameterizedType augmentableTypeFor(final Type valueType) {
- return parameterizedTypeFor(AUGMENTABLE, valueType);
- }
-
- /**
- * Creates instance of {@link org.opendaylight.mdsal.binding.model.api.ParameterizedType ParameterizedType} where
- * raw type is {@link org.opendaylight.yangtools.yang.binding.Augmentation} and actual parameter
- * is <code>valueType</code>.
- *
- * @param valueType JAVA <code>Type</code> with actual parameter
- * @return <code>ParametrizedType</code> reprezentation of raw type
- * <code>Augmentation</code> with actual parameter
- * <code>valueType</code>
- */
- public static @NonNull ParameterizedType augmentationTypeFor(final Type valueType) {
- return parameterizedTypeFor(AUGMENTATION, valueType);
+ public static boolean strictTypeEquals(final Type type1, final Type type2) {
+ if (!type1.equals(type2)) {
+ return false;
+ }
+ if (type1 instanceof ParameterizedType) {
+ if (type2 instanceof ParameterizedType) {
+ return Arrays.equals(((ParameterizedType) type1).getActualTypeArguments(),
+ ((ParameterizedType) type2).getActualTypeArguments());
+ }
+ return false;
+ }
+ return !(type2 instanceof ParameterizedType);
}
public static @Nullable String getOuterClassName(final Type valueType) {