Removed uneeded generic

This commit is contained in:
Luca Frosini 2024-06-11 11:50:32 +02:00
parent 71e1972aba
commit 880e3157a3
4 changed files with 19 additions and 28 deletions

View File

@ -138,7 +138,7 @@ public class TypeImpl implements Type {
return (Class<?>) t;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({ "unchecked" })
public static Type getInstance(Class<? extends Element> clz) {
Type typeDefinition = null;
try {
@ -150,7 +150,7 @@ public class TypeImpl implements Type {
.getRelationTypeDefinitionInstance((Class<? extends RelationElement<?, ?>>) clz);
return typeDefinition;
} else if (PropertyElement.class.isAssignableFrom(clz)) {
typeDefinition = new PropertyTypeImpl(clz);
typeDefinition = new PropertyTypeImpl((Class<? extends PropertyElement>) clz);
return typeDefinition;
} else if (Type.class.isAssignableFrom(clz)) {
typeDefinition = new TypeImpl(clz);

View File

@ -19,8 +19,8 @@ import org.gcube.informationsystem.types.reference.properties.PropertyType;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value = PropertyType.NAME)
public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
implements PropertyType<P> {
public final class PropertyTypeImpl extends TypeImpl
implements PropertyType {
/**
* Generated Serial Version UID
@ -43,7 +43,7 @@ public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
super();
}
public PropertyTypeImpl(Class<P> clz) {
public PropertyTypeImpl(Class<? extends PropertyElement> clz) {
super(clz);
this.extendedTypes = retrieveSuperClasses(clz, PropertyElement.class,
clz == PropertyElement.class ? null : PropertyElement.NAME);

View File

@ -25,7 +25,7 @@ import org.gcube.informationsystem.utils.Version;
@TypeMetadata(name = PropertyType.NAME, description = "This type provides information for any PropertyType", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@Final
public interface PropertyType<P extends PropertyElement> extends PropertyElement, Type {
public interface PropertyType extends PropertyElement, Type {
public static final String NAME = "PropertyType"; // PropertyType.class.getSimpleName();

View File

@ -79,48 +79,39 @@ public class SerializationTest {
@Test
public void testPropertyTypeDefinition() throws Exception{
@SuppressWarnings("unchecked")
PropertyType<PropertyElement> propertyElement = (PropertyType<PropertyElement>) TypeMapper.createTypeDefinition(PropertyElement.class);
PropertyType propertyElement = (PropertyType) TypeMapper.createTypeDefinition(PropertyElement.class);
Assert.assertTrue(propertyElement.getAccessType()==AccessType.PROPERTY_ELEMENT);
logger.info(ElementMapper.marshal(propertyElement));
@SuppressWarnings({ "unchecked", "rawtypes" })
PropertyType<PropertyType> propertyType = (PropertyType<PropertyType>) TypeMapper.createTypeDefinition(PropertyType.class);
PropertyType propertyType = (PropertyType) TypeMapper.createTypeDefinition(PropertyType.class);
Assert.assertTrue(propertyType.getAccessType()==AccessType.PROPERTY_TYPE);
logger.info(ElementMapper.marshal(propertyType));
@SuppressWarnings("unchecked")
PropertyType<PropertyDefinition> propertyDefinition = (PropertyType<PropertyDefinition>) TypeMapper.createTypeDefinition(PropertyDefinition.class);
PropertyType propertyDefinition = (PropertyType) TypeMapper.createTypeDefinition(PropertyDefinition.class);
Assert.assertTrue(propertyDefinition.getAccessType()==AccessType.PROPERTY_DEFINITION);
logger.info(ElementMapper.marshal(propertyDefinition));
@SuppressWarnings("unchecked")
PropertyType<LinkedEntity> linkedEntity = (PropertyType<LinkedEntity>) TypeMapper.createTypeDefinition(LinkedEntity.class);
PropertyType linkedEntity = (PropertyType) TypeMapper.createTypeDefinition(LinkedEntity.class);
Assert.assertTrue(linkedEntity.getAccessType()==AccessType.PROPERTY_ELEMENT);
logger.info(ElementMapper.marshal(linkedEntity));
@SuppressWarnings("unchecked")
PropertyType<Property> property = (PropertyType<Property>) TypeMapper.createTypeDefinition(Property.class);
PropertyType property = (PropertyType) TypeMapper.createTypeDefinition(Property.class);
Assert.assertTrue(property.getAccessType()==AccessType.PROPERTY);
logger.info(ElementMapper.marshal(property));
@SuppressWarnings("unchecked")
PropertyType<Metadata> metadataType = (PropertyType<Metadata>) TypeMapper.createTypeDefinition(Metadata.class);
PropertyType metadataType = (PropertyType) TypeMapper.createTypeDefinition(Metadata.class);
Assert.assertTrue(metadataType.getAccessType()==AccessType.PROPERTY);
logger.info(ElementMapper.marshal(metadataType));
@SuppressWarnings("unchecked")
PropertyType<PropagationConstraint> propagationConstraint = (PropertyType<PropagationConstraint>) TypeMapper.createTypeDefinition(PropagationConstraint.class);
PropertyType propagationConstraint = (PropertyType) TypeMapper.createTypeDefinition(PropagationConstraint.class);
Assert.assertTrue(propagationConstraint.getAccessType()==AccessType.PROPERTY);
logger.info(ElementMapper.marshal(propagationConstraint));
@SuppressWarnings("unchecked")
PropertyType<Encrypted> encrypted = (PropertyType<Encrypted>) TypeMapper.createTypeDefinition(Encrypted.class);
PropertyType encrypted = (PropertyType) TypeMapper.createTypeDefinition(Encrypted.class);
Assert.assertTrue(encrypted.getAccessType()==AccessType.PROPERTY);
logger.info(ElementMapper.marshal(encrypted));
@SuppressWarnings("unchecked")
PropertyType<TemplateVariable> templateVariable = (PropertyType<TemplateVariable>) TypeMapper.createTypeDefinition(TemplateVariable.class);
PropertyType templateVariable = (PropertyType) TypeMapper.createTypeDefinition(TemplateVariable.class);
Assert.assertTrue(templateVariable.getAccessType()==AccessType.PROPERTY_ELEMENT);
logger.info(ElementMapper.marshal(templateVariable));
}
@ -216,16 +207,16 @@ public class SerializationTest {
public void testTypeSerialization() throws Exception {
String serialized = TypeMapper.serializeType(Metadata.class);
logger.info(serialized);
@SuppressWarnings("unchecked")
PropertyType<Metadata> propertyType = (PropertyType<Metadata>) TypeMapper.deserializeTypeDefinition(serialized);
PropertyType propertyType = (PropertyType) TypeMapper.deserializeTypeDefinition(serialized);
Version typeVersion = propertyType.getVersion();
logger.debug("Version {}", typeVersion.toString());
logger.info(ElementMapper.marshal(propertyType));
String json = "{\"" + Element.TYPE_PROPERTY + "\":\"PropertyType\",\"metadata\":null,\"name\":\"Metadata\",\"description\":\"This class provides metadata per every IdentifiableElement\",\"typeSuperTypes\":[\"Property\"],\"properties\":[{\"" + Element.TYPE_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"creationTime\",\"description\":\"Creation time. It represents the difference, measured in milliseconds, between the creation time and midnight, January 1, 1970, UTC.\",\"mandatory\":true,\"readonly\":true,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"propertyType\":\"Date\"},{\"" + Element.TYPE_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"lastUpdateTime\",\"description\":\"Last Update time. At creation time it assumes the same value of creationTime. It represents the difference, measured in milliseconds, between the creation time and midnight, January 1, 1970, UTC.\",\"mandatory\":true,\"readonly\":false,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"propertyType\":\"Date\"},{\"" + Element.TYPE_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"createdBy\",\"description\":\"The user that created the Entity or the Relation. It is initialized at creation time. \",\"mandatory\":true,\"readonly\":true,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"propertyType\":\"String\"},{\"" + Element.TYPE_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"" + IdentifiableElement.ID_PROPERTY + "\",\"description\":\"This ID is be used to identify the Entity or the Relation univocally.\",\"mandatory\":true,\"readonly\":true,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":\"^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$\",\"propertyType\":\"String\"},{\"" + Element.TYPE_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"lastUpdateBy\",\"description\":\"The user that made the last update to the Entity or the Relation. At creation time, it assumes the same value of creator.\",\"mandatory\":true,\"readonly\":false,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"propertyType\":\"String\"}],\"accessType\":\"PROPERTY\",\"abstract\":false,\"version\":\"1.0.0\",\"changelog\":{\"1.0.0\":\"First Version\"}}";
logger.info(json);
@SuppressWarnings("unchecked")
PropertyType<Metadata> metadataType = (PropertyType<Metadata>) TypeMapper.deserializeTypeDefinition(json);
PropertyType metadataType = (PropertyType) TypeMapper.deserializeTypeDefinition(json);
logger.info(ElementMapper.marshal(metadataType));
}