diff --git a/engine/src/main/java/org/terasology/engine/entitySystem/metadata/EventLibrary.java b/engine/src/main/java/org/terasology/engine/entitySystem/metadata/EventLibrary.java index 2b90088af09..ff7f16582da 100644 --- a/engine/src/main/java/org/terasology/engine/entitySystem/metadata/EventLibrary.java +++ b/engine/src/main/java/org/terasology/engine/entitySystem/metadata/EventLibrary.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.engine.entitySystem.metadata; @@ -49,7 +49,6 @@ public EventMetadata getMetadata(T object) { } @Override - @SuppressWarnings("unchecked") public EventMetadata getMetadata(ResourceUrn uri) { return (EventMetadata) super.getMetadata(uri); } diff --git a/engine/src/main/java/org/terasology/engine/persistence/serializers/ComponentSerializer.java b/engine/src/main/java/org/terasology/engine/persistence/serializers/ComponentSerializer.java index f458f84674b..425e36b1c1b 100644 --- a/engine/src/main/java/org/terasology/engine/persistence/serializers/ComponentSerializer.java +++ b/engine/src/main/java/org/terasology/engine/persistence/serializers/ComponentSerializer.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.engine.persistence.serializers; @@ -10,9 +10,9 @@ import com.google.common.collect.Maps; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.terasology.engine.entitySystem.metadata.ComponentFieldMetadata; import org.terasology.engine.entitySystem.metadata.ComponentLibrary; import org.terasology.engine.entitySystem.metadata.ComponentMetadata; -import org.terasology.engine.entitySystem.metadata.ReplicatedFieldMetadata; import org.terasology.engine.persistence.typeHandling.protobuf.ProtobufPersistedData; import org.terasology.engine.persistence.typeHandling.protobuf.ProtobufPersistedDataSerializer; import org.terasology.gestalt.entitysystem.component.Component; @@ -22,6 +22,7 @@ import org.terasology.persistence.typeHandling.TypeHandlerLibrary; import org.terasology.protobuf.EntityData; import org.terasology.reflection.metadata.FieldMetadata; +import reactor.core.publisher.Flux; import java.util.Map; @@ -35,6 +36,7 @@ * When serializing, a FieldSerializeCheck can be provided to determine whether each field should be serialized or not * */ +@SuppressWarnings("UnusedReturnValue") public class ComponentSerializer { private static final Logger logger = LoggerFactory.getLogger(ComponentSerializer.class); @@ -82,23 +84,21 @@ public void removeIdMapping() { } /** - * @param componentData * @return The component described by the componentData, or null if it couldn't be deserialized */ - public Component deserialize(EntityData.Component componentData) { + public > T deserialize(EntityData.Component componentData) { return deserialize(componentData, null); } /** - * @param componentData * @param context The module this component belongs to, or null if it is not being loaded from a module * @return The component described by the componentData, or null if it couldn't be deserialized */ - public Component deserialize(EntityData.Component componentData, Module context) { - ComponentMetadata componentMetadata = getComponentMetadata(componentData, context); + public > T deserialize(EntityData.Component componentData, Module context) { + ComponentMetadata componentMetadata = getComponentMetadata(componentData, context); if (componentMetadata != null) { - Component component = componentMetadata.newInstance(); - return deserializeOnto(component, componentData, componentMetadata, FieldSerializeCheck.NullCheck.newInstance()); + T component = componentMetadata.newInstance(); + return deserializeOnto(component, componentData, componentMetadata, FieldSerializeCheck.NullCheck.newInstance()); } else { logger.warn("Unable to deserialize unknown component type: {}", componentData.getType()); } @@ -109,37 +109,30 @@ public Component deserialize(EntityData.Component componentData, Module context) * Deserializes the componentData on top of the target component. Any fields that are not present in the componentData, * or which cannot be deserialized, are left unaltered. * - * @param target - * @param componentData * @return The target component. */ - public Component deserializeOnto(Component target, EntityData.Component componentData) { - return deserializeOnto(target, componentData, FieldSerializeCheck.NullCheck.newInstance(), null); + public > T deserializeOnto(T target, EntityData.Component componentData) { + return deserializeOnto(target, componentData, FieldSerializeCheck.NullCheck.newInstance(), null); } /** * Deserializes the componentData on top of the target component. Any fields that are not present in the componentData, * or which cannot be deserialized, are left unaltered. * - * @param target - * @param componentData * @param context The module that contains the component being deserialized. May be null if it is not contained in a module. * @return The target component. */ - public Component deserializeOnto(Component target, EntityData.Component componentData, Module context) { - return deserializeOnto(target, componentData, FieldSerializeCheck.NullCheck.newInstance(), context); + public > T deserializeOnto(T target, EntityData.Component componentData, Module context) { + return deserializeOnto(target, componentData, FieldSerializeCheck.NullCheck.newInstance(), context); } /** * Deserializes the componentData on top of the target component. Any fields that are not present in the componentData, * or which cannot be deserialized, are left unaltered. * - * @param target - * @param componentData - * @param fieldCheck * @return The target component. */ - public Component deserializeOnto(Component target, EntityData.Component componentData, FieldSerializeCheck fieldCheck) { + public > T deserializeOnto(T target, EntityData.Component componentData, FieldSerializeCheck fieldCheck) { return deserializeOnto(target, componentData, fieldCheck, null); } @@ -147,15 +140,12 @@ public Component deserializeOnto(Component target, EntityData.Component componen * Deserializes the componentData on top of the target component. Any fields that are not present in the componentData, * or which cannot be deserialized, are left unaltered. * - * @param target - * @param componentData - * @param fieldCheck * @param context The module this component is being deserialized from, or null if it isn't within a module * @return The target component. */ - public Component deserializeOnto(Component target, EntityData.Component componentData, - FieldSerializeCheck fieldCheck, Module context) { - ComponentMetadata componentMetadata = getComponentMetadata(componentData, context); + public > T deserializeOnto(T target, EntityData.Component componentData, + FieldSerializeCheck fieldCheck, Module context) { + ComponentMetadata componentMetadata = getComponentMetadata(componentData, context); if (componentMetadata != null) { return deserializeOnto(target, componentData, componentMetadata, fieldCheck); } else { @@ -165,12 +155,12 @@ public Component deserializeOnto(Component target, EntityData.Component componen } - private Component deserializeOnto(Component targetComponent, EntityData.Component componentData, - ComponentMetadata componentMetadata, FieldSerializeCheck fieldCheck) { - Serializer serializer = typeHandlerLibrary.getSerializerFor(componentMetadata); - Map, PersistedData> dataMap = Maps.newHashMapWithExpectedSize(componentData.getFieldCount()); + private > T deserializeOnto(T targetComponent, EntityData.Component componentData, + ComponentMetadata componentMetadata, FieldSerializeCheck fieldCheck) { + Serializer serializer = typeHandlerLibrary.getSerializerFor(componentMetadata); + Map, PersistedData> dataMap = Maps.newHashMapWithExpectedSize(componentData.getFieldCount()); for (EntityData.NameValue field : componentData.getFieldList()) { - FieldMetadata fieldInfo = null; + FieldMetadata fieldInfo = null; if (field.hasNameIndex()) { fieldInfo = componentMetadata.getField(field.getNameIndex()); } else if (field.hasName()) { @@ -190,22 +180,21 @@ private Component deserializeOnto(Component targetComponen /** * Serializes a component. * - * @param component * @return The serialized component, or null if it could not be serialized. */ - public EntityData.Component serialize(Component component) { - return serialize(component, FieldSerializeCheck.NullCheck.newInstance()); + public > EntityData.Component serialize(T component) { + return serialize(component, FieldSerializeCheck.NullCheck.newInstance()); } /** * Serializes a component. * - * @param component * @param check A check to use to see if each field should be serialized. * @return The serialized component, or null if it could not be serialized. */ - public EntityData.Component serialize(Component component, FieldSerializeCheck check) { - ComponentMetadata componentMetadata = componentLibrary.getMetadata(component.getClass()); + public > EntityData.Component serialize(T component, FieldSerializeCheck check) { + @SuppressWarnings("unchecked") ComponentMetadata componentMetadata = (ComponentMetadata) + componentLibrary.getMetadata(component.getClass()); if (componentMetadata == null) { logger.error("Unregistered component type: {}", component.getClass()); return null; @@ -213,20 +202,20 @@ public EntityData.Component serialize(Component component, FieldSerializeCheck field : componentMetadata.getFields()) { - if (check.shouldSerializeField(field, component)) { - PersistedData result = serializer.serialize(field, component, serializationContext); - if (!result.isNull()) { - EntityData.Value itemValue = ((ProtobufPersistedData) result).getValue(); - if (usingFieldIds) { - componentMessage.addField(EntityData.NameValue.newBuilder().setNameIndex(field.getId()).setValue(itemValue)); - } else { - componentMessage.addField(EntityData.NameValue.newBuilder().setName(field.getName()).setValue(itemValue)); - } + Serializer serializer = typeHandlerLibrary.getSerializerFor(componentMetadata); + componentMetadata.getFields().stream() + .filter(field -> check.shouldSerializeField(field, component)) + .forEach(field -> { + PersistedData result = serializer.serialize(field, component, serializationContext); + if (!result.isNull()) { + EntityData.Value itemValue = ((ProtobufPersistedData) result).getValue(); + if (usingFieldIds) { + componentMessage.addField(EntityData.NameValue.newBuilder().setNameIndex(field.getId()).setValue(itemValue)); + } else { + componentMessage.addField(EntityData.NameValue.newBuilder().setName(field.getName()).setValue(itemValue)); } } - } + }); return componentMessage.build(); } @@ -247,8 +236,8 @@ private void serializeComponentType(ComponentMetadata componentMetadata, Enti * @param delta The component whose differences will be serialized * @return The serialized component, or null if it could not be serialized */ - public EntityData.Component serialize(Component base, Component delta) { - return serialize(base, delta, FieldSerializeCheck.NullCheck.newInstance()); + public > EntityData.Component serialize(T base, T delta) { + return serialize(base, delta, FieldSerializeCheck.NullCheck.newInstance()); } /** @@ -259,8 +248,8 @@ public EntityData.Component serialize(Component base, Component delta) { * @param check A check to use to see if each field should be serialized. * @return The serialized component, or null if it could not be serialized */ - public EntityData.Component serialize(Component base, Component delta, FieldSerializeCheck check) { - ComponentMetadata componentMetadata = componentLibrary.getMetadata(base.getClass()); + public > EntityData.Component serialize(T base, T delta, FieldSerializeCheck check) { + @SuppressWarnings("unchecked") ComponentMetadata componentMetadata = (ComponentMetadata) componentLibrary.getMetadata(base.getClass()); if (componentMetadata == null) { logger.error("Unregistered component type: {}", base.getClass()); return null; @@ -269,57 +258,66 @@ public EntityData.Component serialize(Component base, Component delta, FieldSeri EntityData.Component.Builder componentMessage = EntityData.Component.newBuilder(); serializeComponentType(componentMetadata, componentMessage); - Serializer serializer = typeHandlerLibrary.getSerializerFor(componentMetadata); - boolean changed = false; - for (ReplicatedFieldMetadata field : componentMetadata.getFields()) { - if (check.shouldSerializeField(field, delta) && serializer.getHandlerFor(field) != null) { - Object origValue = field.getValue(base); - Object deltaValue = field.getValue(delta); - - if (!Objects.equal(origValue, deltaValue)) { - PersistedData value = serializer.serializeValue(field, deltaValue, serializationContext); - if (!value.isNull()) { - EntityData.Value dataValue = ((ProtobufPersistedData) value).getValue(); - if (usingFieldIds) { - componentMessage.addField(EntityData.NameValue.newBuilder().setNameIndex(field.getId()).setValue(dataValue).build()); - } else { - componentMessage.addField(EntityData.NameValue.newBuilder().setName(field.getName()).setValue(dataValue).build()); - } - changed = true; - } - } - } + Serializer serializer = typeHandlerLibrary.getSerializerFor(componentMetadata); + var changedFields = Flux.fromIterable(componentMetadata.getFields()) + .filter(field -> check.shouldSerializeField(field, delta) && serializer.getHandlerFor(field) != null) + .mapNotNull(field -> extracted(base, delta, serializer, field)) + .collectList() + .block(); + if (changedFields == null || changedFields.isEmpty()) { + return null; } + componentMessage.addAllField(changedFields); + return componentMessage.build(); + } - if (changed) { - return componentMessage.build(); + private , F> EntityData.NameValue extracted(T base, T delta, Serializer serializer, + ComponentFieldMetadata field) { + F origValue = field.getValue(base); + F deltaValue = field.getValue(delta); + + if (!Objects.equal(origValue, deltaValue)) { + PersistedData value = serializer.serializeValue(field, deltaValue, serializationContext); + if (!value.isNull()) { + EntityData.Value dataValue = ((ProtobufPersistedData) value).getValue(); + EntityData.NameValue.Builder nameValueBuilder = getNameValueBuilder(field); + nameValueBuilder.setValue(dataValue); + return nameValueBuilder.build(); + } } - return null; } + private , F> EntityData.NameValue.Builder getNameValueBuilder(ComponentFieldMetadata field) { + var nameValueBuilder = EntityData.NameValue.newBuilder(); + if (usingFieldIds) { + nameValueBuilder.setNameIndex(field.getId()); + } else { + nameValueBuilder.setName(field.getName()); + } + return nameValueBuilder; + } + /** * Determines the component class that the serialized component is for. * - * @param componentData * @return The component class the given componentData describes, or null if it is unknown. */ - public ComponentMetadata getComponentMetadata(EntityData.Component componentData) { + public > ComponentMetadata getComponentMetadata(EntityData.Component componentData) { return getComponentMetadata(componentData, null); } /** * Determines the component class that the serialized component is for. * - * @param componentData * @param context the module this component is being loaded from * @return The component class the given componentData describes, or null if it is unknown. */ - public ComponentMetadata getComponentMetadata(EntityData.Component componentData, Module context) { + public > ComponentMetadata getComponentMetadata(EntityData.Component componentData, Module context) { if (componentData.hasTypeIndex()) { - ComponentMetadata metadata = null; + ComponentMetadata metadata = null; if (!idTable.isEmpty()) { - Class componentClass = idTable.inverse().get(componentData.getTypeIndex()); + @SuppressWarnings("unchecked") Class componentClass = (Class) idTable.inverse().get(componentData.getTypeIndex()); if (componentClass != null) { metadata = componentLibrary.getMetadata(componentClass); } @@ -330,11 +328,13 @@ public ComponentMetadata getComponentMetadata(EntityData.Co } return metadata; } else if (componentData.hasType()) { - ComponentMetadata metadata; + ComponentMetadata metadata; if (context != null) { - metadata = componentLibrary.resolve(componentData.getType(), context); + //noinspection unchecked + metadata = (ComponentMetadata) componentLibrary.resolve(componentData.getType(), context); } else { - metadata = componentLibrary.resolve(componentData.getType()); + //noinspection unchecked + metadata = (ComponentMetadata) componentLibrary.resolve(componentData.getType()); } if (metadata == null) { logger.warn("Unable to deserialize unknown component type: {}", componentData.getType()); diff --git a/engine/src/main/java/org/terasology/engine/persistence/serializers/EventSerializer.java b/engine/src/main/java/org/terasology/engine/persistence/serializers/EventSerializer.java index 1700577b67c..d96b3b200b9 100644 --- a/engine/src/main/java/org/terasology/engine/persistence/serializers/EventSerializer.java +++ b/engine/src/main/java/org/terasology/engine/persistence/serializers/EventSerializer.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.engine.persistence.serializers; @@ -61,19 +61,17 @@ public void removeIdMapping() { } /** - * @param eventData * @return The event described by the eventData - * @throws org.terasology.engine.persistence.typeHandling.DeserializationException if an error occurs when deserializing + * @throws org.terasology.persistence.typeHandling.DeserializationException if an error occurs when deserializing */ public Event deserialize(EntityData.Event eventData) { - Class eventClass = getEventClass(eventData); + var eventClass = getEventClass(eventData); if (eventClass != null) { - EventMetadata eventMetadata = eventLibrary.getMetadata(eventClass); + var eventMetadata = eventLibrary.getMetadata(eventClass); if (!eventMetadata.isConstructable()) { throw new DeserializationException("Cannot deserialize " + eventMetadata + " - lacks default constructor"); } else { - Event event = eventMetadata.newInstance(); - return deserializeOnto(event, eventData, eventMetadata); + return deserializeOnto(eventMetadata.newInstance(), eventData, eventMetadata); } } else { throw new DeserializationException("Unable to deserialize unknown event type: " + eventData.getType()); @@ -81,11 +79,11 @@ public Event deserialize(EntityData.Event eventData) { } - private Event deserializeOnto(Event targetEvent, EntityData.Event eventData, EventMetadata eventMetadata) { - Serializer serializer = typeHandlerLibrary.getSerializerFor(eventMetadata); + private Event deserializeOnto(C targetEvent, EntityData.Event eventData, EventMetadata eventMetadata) { + Serializer serializer = typeHandlerLibrary.getSerializerFor(eventMetadata); for (int i = 0; i < eventData.getFieldIds().size(); ++i) { byte fieldId = eventData.getFieldIds().byteAt(i); - ReplicatedFieldMetadata fieldInfo = eventMetadata.getField(fieldId); + var fieldInfo = eventMetadata.getField(fieldId); if (fieldInfo == null) { logger.error("Unable to serialize field {}, out of bounds", fieldId); continue; @@ -100,12 +98,11 @@ private Event deserializeOnto(Event targetEvent, EntityData.Event eventData, Eve /** * Serializes an event. * - * @param event * @return The serialized event - * @throws org.terasology.engine.persistence.typeHandling.SerializationException if an error occurs during serialization + * @throws org.terasology.persistence.typeHandling.SerializationException if an error occurs during serialization */ - public EntityData.Event serialize(Event event) { - EventMetadata eventMetadata = eventLibrary.getMetadata(event.getClass()); + public EntityData.Event serialize(E event) { + @SuppressWarnings("unchecked") var eventMetadata = eventLibrary.getMetadata((Class) event.getClass()); if (eventMetadata == null) { throw new SerializationException("Unregistered event type: " + event.getClass()); } else if (!eventMetadata.isConstructable()) { @@ -115,19 +112,19 @@ public EntityData.Event serialize(Event event) { EntityData.Event.Builder eventData = EntityData.Event.newBuilder(); serializeEventType(event, eventData); - Serializer eventSerializer = typeHandlerLibrary.getSerializerFor(eventMetadata); + Serializer eventSerializer = typeHandlerLibrary.getSerializerFor(eventMetadata); ByteString.Output fieldIds = ByteString.newOutput(); - for (ReplicatedFieldMetadata field : eventMetadata.getFields()) { - if (field.isReplicated()) { - EntityData.Value serializedValue = ((ProtobufPersistedData) eventSerializer - .serialize(field, event, persistedDataSerializer)) - .getValue(); - if (serializedValue != null) { - eventData.addFieldValue(serializedValue); - fieldIds.write(field.getId()); - } + eventMetadata.getFields().stream() + .filter(ReplicatedFieldMetadata::isReplicated) + .forEach(field -> { + EntityData.Value serializedValue = ((ProtobufPersistedData) eventSerializer + .serialize(field, event, persistedDataSerializer)) + .getValue(); + if (serializedValue != null) { + eventData.addFieldValue(serializedValue); + fieldIds.write(field.getId()); } - } + }); eventData.setFieldIds(fieldIds.toByteString()); return eventData.build(); @@ -141,16 +138,16 @@ private void serializeEventType(Event event, EntityData.Event.Builder eventData) /** * Determines the event class that the serialized event is for. * - * @param eventData * @return The event class the given eventData describes, or null if it is unknown. */ - public Class getEventClass(EntityData.Event eventData) { + public Class getEventClass(EntityData.Event eventData) { if (eventData.hasType()) { - EventMetadata metadata = null; + EventMetadata metadata = null; if (!idTable.isEmpty()) { - Class eventClass = idTable.inverse().get(eventData.getType()); + var eventClass = idTable.inverse().get(eventData.getType()); if (eventClass != null) { - metadata = eventLibrary.getMetadata(eventClass); + //noinspection unchecked + metadata = (EventMetadata) eventLibrary.getMetadata(eventClass); } } if (metadata == null) { diff --git a/subsystems/TypeHandlerLibrary/build.gradle.kts b/subsystems/TypeHandlerLibrary/build.gradle.kts index 04d08725f1d..f981e190fe6 100644 --- a/subsystems/TypeHandlerLibrary/build.gradle.kts +++ b/subsystems/TypeHandlerLibrary/build.gradle.kts @@ -13,26 +13,13 @@ group = "org.terasology.subsystems" version = project(":engine").version dependencies { - implementation("org.slf4j:slf4j-api:1.7.32") + implementation("org.slf4j:slf4j-api:1.7.36") implementation("net.sf.trove4j:trove4j:3.0.3") implementation("org.terasology:reflections:0.9.12-MB") implementation("org.terasology.nui:nui-reflect:3.0.0") implementation("org.terasology.gestalt:gestalt-module:7.1.0") implementation("org.terasology.gestalt:gestalt-asset-core:7.1.0") - - testRuntimeOnly("org.slf4j:slf4j-simple:1.7.32") { - because("log output during tests") - } - testImplementation(platform("org.junit:junit-bom:5.8.1")) { - // junit-bom will set version numbers for the other org.junit dependencies. - } - testImplementation("org.junit.jupiter:junit-jupiter-api") - testImplementation("org.junit.jupiter:junit-jupiter-params") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") - testImplementation("org.mockito:mockito-inline:3.12.4") - - testImplementation("org.mockito:mockito-junit-jupiter:3.12.4") } tasks.register("unitTest") { diff --git a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/Serializer.java b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/Serializer.java index 7cd7a19059b..69e803ffa8b 100644 --- a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/Serializer.java +++ b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/Serializer.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.persistence.typeHandling; @@ -14,14 +14,14 @@ * A serializer provides low-level serialization support for a type, using a mapping of type handlers for each field of that type. * */ -public class Serializer { +public class Serializer { private static final Logger logger = LoggerFactory.getLogger(Serializer.class); - private ClassMetadata classMetadata; - private Map, TypeHandler> fieldHandlers; + private final ClassMetadata classMetadata; + private final Map, TypeHandler> fieldHandlers; - public Serializer(ClassMetadata classMetadata, Map, TypeHandler> fieldHandlers) { + public Serializer(ClassMetadata> classMetadata, Map, TypeHandler> fieldHandlers) { this.fieldHandlers = fieldHandlers; this.classMetadata = classMetadata; } @@ -30,8 +30,8 @@ public Serializer(ClassMetadata classMetadata, Map, Ty * @param field The metadata for a field of the type handled by this serializer. * @return The TypeHandler for the given field */ - public TypeHandler getHandlerFor(FieldMetadata field) { - return fieldHandlers.get(field); + public TypeHandler getHandlerFor(FieldMetadata field) { + return (TypeHandler) fieldHandlers.get(field); } /** @@ -42,11 +42,10 @@ public TypeHandler getHandlerFor(FieldMetadata field) { * @param context The current serialization context * @return The serialized value of the field */ - @SuppressWarnings("unchecked") - public PersistedData serialize(FieldMetadata field, Object container, PersistedDataSerializer context) { - Object rawValue = field.getValue(container); + public PersistedData serialize(FieldMetadata field, C container, PersistedDataSerializer context) { + F rawValue = field.getValue(container); if (rawValue != null) { - TypeHandler handler = getHandlerFor(field); + TypeHandler handler = getHandlerFor(field); if (handler != null) { return handler.serialize(rawValue, context); } @@ -62,9 +61,9 @@ public PersistedData serialize(FieldMetadata field, Object container, Pers * @param rawValue The value to serialize * @return The serialized value */ - @SuppressWarnings("unchecked") - public PersistedData serializeValue(FieldMetadata fieldMetadata, Object rawValue, PersistedDataSerializer context) { - return fieldHandlers.get(fieldMetadata).serialize(rawValue, context); + public PersistedData serializeValue(FieldMetadata fieldMetadata, F rawValue, PersistedDataSerializer context) { + @SuppressWarnings("unchecked") TypeHandler handler = (TypeHandler) fieldHandlers.get(fieldMetadata); + return handler.serialize(rawValue, context); } /** @@ -74,13 +73,13 @@ public PersistedData serializeValue(FieldMetadata fieldMetadata, Object ra * @param fieldMetadata The metadata of the field * @param data The serialized value of the field */ - public void deserializeOnto(Object target, FieldMetadata fieldMetadata, PersistedData data) { - TypeHandler handler = getHandlerFor(fieldMetadata); + public void deserializeOnto(C target, FieldMetadata fieldMetadata, PersistedData data) { + TypeHandler handler = getHandlerFor(fieldMetadata); if (handler == null) { logger.error("No type handler for type {} used by {}::{}", fieldMetadata.getType(), target.getClass(), fieldMetadata); } else { try { - Object deserializedValue = handler.deserializeOrNull(data); + F deserializedValue = handler.deserializeOrNull(data); fieldMetadata.setValue(target, deserializedValue); } catch (DeserializationException e) { logger.error("Unable to deserialize field '{}' from '{}'", fieldMetadata.getName(), data.toString(), e); @@ -94,7 +93,7 @@ public void deserializeOnto(Object target, FieldMetadata fieldMetadata, Pe * @param target The object to deserialize onto * @param values The collection of values to apply to the object */ - public void deserializeOnto(Object target, PersistedDataMap values) { + public void deserializeOnto(C target, PersistedDataMap values) { deserializeOnto(target, values, DeserializeFieldCheck.NullCheck.newInstance()); } @@ -105,15 +104,16 @@ public void deserializeOnto(Object target, PersistedDataMap values) { * @param values The collection of values to apply to the object * @param check A check to filter which fields to deserialize */ - public void deserializeOnto(Object target, PersistedDataMap values, DeserializeFieldCheck check) { - for (Map.Entry field : values.entrySet()) { - FieldMetadata fieldInfo = classMetadata.getField(field.getKey()); - - if (fieldInfo != null && check.shouldDeserialize(classMetadata, fieldInfo)) { - deserializeOnto(target, fieldInfo, field.getValue()); - } else if (fieldInfo == null) { - logger.warn("Cannot deserialize unknown field '{}' onto '{}'", field.getKey(), classMetadata.getId()); - } + public void deserializeOnto(C target, PersistedDataMap values, DeserializeFieldCheck check) { + values.entrySet().forEach(field -> goomp(target, check, field.getKey(), field.getValue())); + } + + private void goomp(C target, DeserializeFieldCheck check, String fieldName, PersistedData data) { + var fieldInfo = classMetadata.getField(fieldName); + if (fieldInfo != null && check.shouldDeserialize(classMetadata, fieldInfo)) { + deserializeOnto(target, fieldInfo, data); + } else if (fieldInfo == null) { + logger.warn("Cannot deserialize unknown field '{}' onto '{}'", fieldName, classMetadata.getId()); } } @@ -123,7 +123,7 @@ public void deserializeOnto(Object target, PersistedDataMap values, DeserializeF * @param target The object to deserialize onto * @param values The collection of values to apply to the object */ - public void deserializeOnto(Object target, Map, PersistedData> values) { + public void deserializeOnto(C target, Map, PersistedData> values) { deserializeOnto(target, values, DeserializeFieldCheck.NullCheck.newInstance()); } @@ -134,12 +134,12 @@ public void deserializeOnto(Object target, Map, PersistedDat * @param values The collection of values to apply to the object * @param check A check to filter which fields to deserialize */ - public void deserializeOnto(Object target, Map, PersistedData> values, DeserializeFieldCheck check) { - for (Map.Entry, PersistedData> field : values.entrySet()) { - if (check.shouldDeserialize(classMetadata, field.getKey())) { - deserializeOnto(target, field.getKey(), field.getValue()); + public void deserializeOnto(C target, Map, PersistedData> values, DeserializeFieldCheck check) { + values.forEach((field, data) -> { + if (check.shouldDeserialize(classMetadata, field)) { + deserializeOnto(target, field, data); } - } + }); } diff --git a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/TypeHandlerLibrary.java b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/TypeHandlerLibrary.java index 3395590985b..57e7d831473 100644 --- a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/TypeHandlerLibrary.java +++ b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/TypeHandlerLibrary.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.persistence.typeHandling; @@ -57,14 +57,14 @@ public class TypeHandlerLibrary { private final List typeHandlerFactories = Lists.newArrayList(); private final Map> instanceCreators = Maps.newHashMap(); private final Map, TypeHandler> typeHandlerCache = Maps.newHashMap(); - private final Map, Serializer> serializerMap = Maps.newHashMap(); + private final Map, Serializer> serializerMap = Maps.newHashMap(); protected TypeHandlerLibrary(SerializationSandbox sandbox) { this.sandbox = sandbox; ConstructorLibrary constructorLibrary = new ConstructorLibrary(instanceCreators); addTypeHandlerFactory(new ObjectFieldMapTypeHandlerFactory(constructorLibrary)); TypeHandlerLibrary.populateBuiltInHandlers(this); - addTypeHandlerFactory(new CollectionTypeHandlerFactory(constructorLibrary)); + addTypeHandlerFactory(new CollectionTypeHandlerFactory()); } public TypeHandlerLibrary(Reflections reflections) { @@ -122,11 +122,11 @@ public TypeHandlerLibrary copy() { * @param type The ClassMetadata for the type of interest * @return A serializer for serializing/deserializing the type */ - public Serializer getSerializerFor(ClassMetadata type) { - Serializer serializer = serializerMap.get(type); + public Serializer getSerializerFor(ClassMetadata> type) { + @SuppressWarnings("unchecked") Serializer serializer = (Serializer) serializerMap.get(type); if (serializer == null) { - Map, TypeHandler> fieldHandlerMap = getFieldHandlerMap(type); - serializer = new Serializer(type, fieldHandlerMap); + var fieldHandlerMap = getFieldHandlerMap(type); + serializer = new Serializer<>(type, fieldHandlerMap); serializerMap.put(type, serializer); } return serializer; @@ -209,10 +209,9 @@ public void addInstanceCreator(TypeInfo typeInfo, InstanceCreator inst * @param type The {@link Type} describing the type for which to retrieve the {@link TypeHandler}. * @return The {@link TypeHandler} for the specified type, if available. */ - @SuppressWarnings("unchecked") - public Optional> getTypeHandler(Type type) { - TypeInfo typeInfo = TypeInfo.of(type); - return (Optional>) getTypeHandler(typeInfo); + public Optional> getTypeHandler(Type type) { + TypeInfo typeInfo = TypeInfo.of(type); + return getTypeHandler(typeInfo); } /** @@ -310,17 +309,17 @@ public TypeHandler getBaseTypeHandler(TypeInfo typeInfo) { return new RuntimeDelegatingTypeHandler<>(delegateHandler, typeInfo, context); } - private Map, TypeHandler> getFieldHandlerMap(ClassMetadata type) { - Map, TypeHandler> handlerMap = Maps.newHashMap(); - for (FieldMetadata field : type.getFields()) { - Optional> handler = getTypeHandler(field.getField().getGenericType()); - - if (handler.isPresent()) { - handlerMap.put(field, handler.get()); - } else { - logger.error("Unsupported field: '{}.{}'", type.getId(), field.getName()); - } - } + private Map, TypeHandler> getFieldHandlerMap(ClassMetadata> type) { + Map, TypeHandler> handlerMap = new HashMap<>(); + type.getFields().forEach(field -> + getFmConsumer(field).ifPresentOrElse( + handler -> handlerMap.put(field, handler), + () -> logger.error("Unsupported field: '{}.{}'", type.getId(), field.getName()) + )); return handlerMap; } + + private Optional> getFmConsumer(FieldMetadata field) { + return getTypeHandler(field.getField().getGenericType()); + } } diff --git a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/RuntimeDelegatingTypeHandler.java b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/RuntimeDelegatingTypeHandler.java index db5099d9167..5fc4e6b4ca8 100644 --- a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/RuntimeDelegatingTypeHandler.java +++ b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/RuntimeDelegatingTypeHandler.java @@ -64,7 +64,7 @@ public PersistedData serializeNonNull(T value, PersistedDataSerializer serialize Type runtimeType = getRuntimeTypeIfMoreSpecific(value); if (!typeInfo.getType().equals(runtimeType)) { - Optional> runtimeTypeHandler = typeHandlerLibrary.getTypeHandler(runtimeType); + var runtimeTypeHandler = typeHandlerLibrary.getTypeHandler(runtimeType); chosenHandler = (TypeHandler) diff --git a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/ArrayTypeHandlerFactory.java b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/ArrayTypeHandlerFactory.java index 20dd972d0bf..37928bcdfee 100644 --- a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/ArrayTypeHandlerFactory.java +++ b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/ArrayTypeHandlerFactory.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.persistence.typeHandling.coreTypes.factories; @@ -30,20 +30,17 @@ public Optional> create(TypeInfo typeInfo, TypeHandlerCont ? ((GenericArrayType) type).getGenericComponentType() : ((Class) type).getComponentType(); - TypeInfo elementTypeInfo = TypeInfo.of(elementType); - - Optional> declaredElementTypeHandler = + var declaredElementTypeHandler = context.getTypeHandlerLibrary().getTypeHandler(elementType); - @SuppressWarnings("unchecked") - TypeHandler elementTypeHandler = new RuntimeDelegatingTypeHandler( + var elementTypeHandler = new RuntimeDelegatingTypeHandler<>( declaredElementTypeHandler.orElse(null), - elementTypeInfo, + TypeInfo.of(elementType), context ); - @SuppressWarnings("unchecked") - TypeHandler typeHandler = new ArrayTypeHandler(elementTypeHandler, elementTypeInfo); + @SuppressWarnings("unchecked") TypeHandler typeHandler = (TypeHandler) + new ArrayTypeHandler<>(elementTypeHandler, TypeInfo.of(elementType)); return Optional.of(typeHandler); } diff --git a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/CollectionTypeHandlerFactory.java b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/CollectionTypeHandlerFactory.java index 7d944335574..abf1975a0ee 100644 --- a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/CollectionTypeHandlerFactory.java +++ b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/CollectionTypeHandlerFactory.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.persistence.typeHandling.coreTypes.factories; @@ -11,7 +11,6 @@ import org.terasology.persistence.typeHandling.coreTypes.RuntimeDelegatingTypeHandler; import org.terasology.reflection.ReflectionUtil; import org.terasology.reflection.TypeInfo; -import org.terasology.reflection.reflect.CollectionCopyConstructor; import org.terasology.reflection.reflect.ConstructorLibrary; import java.lang.reflect.Type; @@ -24,11 +23,7 @@ public class CollectionTypeHandlerFactory implements TypeHandlerFactory { private static final Logger LOGGER = LoggerFactory.getLogger(CollectionTypeHandlerFactory.class); - private ConstructorLibrary constructorLibrary; - - public CollectionTypeHandlerFactory(ConstructorLibrary constructorLibrary) { - this.constructorLibrary = constructorLibrary; - } + public CollectionTypeHandlerFactory() { } @Override public Optional> create(TypeInfo typeInfo, TypeHandlerContext context) { @@ -45,22 +40,18 @@ public Optional> create(TypeInfo typeInfo, TypeHandlerCont return Optional.empty(); } - TypeInfo elementTypeInfo = TypeInfo.of(elementType); - - Optional> declaredElementTypeHandler = + var declaredElementTypeHandler = context.getTypeHandlerLibrary().getTypeHandler(elementType); - @SuppressWarnings("unchecked") - TypeHandler elementTypeHandler = new RuntimeDelegatingTypeHandler( + var elementTypeHandler = new RuntimeDelegatingTypeHandler<>( declaredElementTypeHandler.orElse(null), - elementTypeInfo, + TypeInfo.of(elementType), context ); - CollectionCopyConstructor constructor = ConstructorLibrary.getCollectionCopyConstructor((TypeInfo) typeInfo); + var constructor = ConstructorLibrary.getCollectionCopyConstructor((TypeInfo) typeInfo); - @SuppressWarnings("unchecked") - TypeHandler typeHandler = new CollectionTypeHandler(elementTypeHandler, constructor); + TypeHandler typeHandler = new CollectionTypeHandler<>(elementTypeHandler, constructor); return Optional.of(typeHandler); } diff --git a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/MapTypeHandlerFactory.java b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/MapTypeHandlerFactory.java index ee8d6a90482..b1480e47ad2 100644 --- a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/MapTypeHandlerFactory.java +++ b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/MapTypeHandlerFactory.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.persistence.typeHandling.coreTypes.factories; @@ -20,7 +20,6 @@ public class MapTypeHandlerFactory implements TypeHandlerFactory { private static final Logger LOGGER = LoggerFactory.getLogger(StringMapTypeHandler.class); - @SuppressWarnings("unchecked") @Override public Optional> create(TypeInfo typeInfo, TypeHandlerContext context) { if (!Map.class.isAssignableFrom(typeInfo.getRawType())) { @@ -36,31 +35,25 @@ public Optional> create(TypeInfo typeInfo, TypeHandlerCont return Optional.empty(); } - Optional> declaredValueTypeHandler = - context.getTypeHandlerLibrary().getTypeHandler(valueType); - - TypeInfo valueTypeInfo = TypeInfo.of(valueType); - - @SuppressWarnings("unchecked") - TypeHandler valueTypeHandler = new RuntimeDelegatingTypeHandler( - declaredValueTypeHandler.orElse(null), - valueTypeInfo, + TypeHandler valueTypeHandler = new RuntimeDelegatingTypeHandler<>( + context.getTypeHandlerLibrary().getTypeHandler(valueType).orElse(null), + TypeInfo.of(valueType), context ); + TypeHandler result; if (String.class.equals(keyType)) { - return Optional.of((TypeHandler) new StringMapTypeHandler<>(valueTypeHandler)); + //noinspection unchecked + result = (TypeHandler) new StringMapTypeHandler<>(valueTypeHandler); } else { - Optional> declaredKeyTypeHandler = - context.getTypeHandlerLibrary().getTypeHandler(keyType); - TypeInfo keyTypeInfo = TypeInfo.of(keyType); - @SuppressWarnings("unchecked") - TypeHandler keyTypeHandler = new RuntimeDelegatingTypeHandler( - declaredKeyTypeHandler.orElse(null), - keyTypeInfo, + TypeHandler keyTypeHandler = new RuntimeDelegatingTypeHandler<>( + context.getTypeHandlerLibrary().getTypeHandler(keyType).orElse(null), + TypeInfo.of(keyType), context ); - return Optional.of((TypeHandler) new GenericMapTypeHandler<>(keyTypeHandler, valueTypeHandler)); + //noinspection unchecked + result = (TypeHandler) new GenericMapTypeHandler<>(keyTypeHandler, valueTypeHandler); } + return Optional.of(result); } } diff --git a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/ObjectFieldMapTypeHandlerFactory.java b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/ObjectFieldMapTypeHandlerFactory.java index 7da6f3f4851..d5658561a83 100644 --- a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/ObjectFieldMapTypeHandlerFactory.java +++ b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/coreTypes/factories/ObjectFieldMapTypeHandlerFactory.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.persistence.typeHandling.coreTypes.factories; @@ -42,7 +42,7 @@ public Optional> create(TypeInfo typeInfo, TypeHandlerCont getResolvedFields(typeInfo).forEach( (field, fieldType) -> { - Optional> declaredFieldTypeHandler = + var declaredFieldTypeHandler = context.getTypeHandlerLibrary().getTypeHandler(fieldType); TypeInfo fieldTypeInfo = TypeInfo.of(fieldType); diff --git a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/InMemorySerializerTest.java b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/InMemorySerializerTest.java index 8d77751f98b..aafe6396c6c 100644 --- a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/InMemorySerializerTest.java +++ b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/InMemorySerializerTest.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.persistence.typeHandling; @@ -306,7 +306,7 @@ void serializeBytes() { Assertions.assertEquals(PersistedBytes.class, data.getClass()); Assertions.assertTrue(data.isBytes()); - Assertions.assertEquals(value, data.getAsBytes()); + Assertions.assertArrayEquals(value, data.getAsBytes()); Assertions.assertEquals(ByteBuffer.wrap(value), data.getAsByteBuffer()); Assertions.assertFalse(data.isString()); @@ -335,7 +335,7 @@ void serializeByteBuffer() { Assertions.assertEquals(PersistedBytes.class, data.getClass()); Assertions.assertTrue(data.isBytes()); - Assertions.assertEquals(value, data.getAsBytes()); + Assertions.assertArrayEquals(value, data.getAsBytes()); Assertions.assertEquals(ByteBuffer.wrap(value), data.getAsByteBuffer()); Assertions.assertFalse(data.isString()); diff --git a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/RuntimeDelegatingTypeHandlerTest.java b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/RuntimeDelegatingTypeHandlerTest.java index 3fc9caddd06..9e83aa87045 100644 --- a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/RuntimeDelegatingTypeHandlerTest.java +++ b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/RuntimeDelegatingTypeHandlerTest.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.persistence.typeHandling.coreTypes; @@ -7,6 +7,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentMatcher; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.terasology.persistence.typeHandling.PersistedData; import org.terasology.persistence.typeHandling.PersistedDataSerializer; @@ -52,9 +53,9 @@ public class RuntimeDelegatingTypeHandlerTest { this.typeHandlerLibrary = typeHandlerLibrary; // We must mock `getTypeHandler(Type)`, not only `getTypeHandler(Class<>)` - when(typeHandlerLibrary.getTypeHandler((Type) baseType)) + Mockito.>>when(typeHandlerLibrary.getTypeHandler((Type) baseType)) .thenReturn(Optional.of(baseTypeHandler)); - when(typeHandlerLibrary.getTypeHandler((Type) subType)) + Mockito.>>when(typeHandlerLibrary.getTypeHandler((Type) subType)) .thenReturn(Optional.of(subTypeHandler)); when(sandbox.findSubTypeOf(subType.getName(), baseType)) diff --git a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/BytesTypeHandlerTest.java b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/BytesTypeHandlerTest.java index f0d9690bbb7..0d937892555 100644 --- a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/BytesTypeHandlerTest.java +++ b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/BytesTypeHandlerTest.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.persistence.typeHandling.coreTypes.factories; @@ -39,10 +39,10 @@ void byteArraySerializeDeserialize() { byte[] expectedObj = new byte[]{(byte) 0xFF}; PersistedBytes data = serialize(expectedObj, new ByteArrayTypeHandler()); - Assertions.assertEquals(expectedObj, data.getAsBytes()); + Assertions.assertArrayEquals(expectedObj, data.getAsBytes()); byte[] obj = deserialize(data, new ByteArrayTypeHandler()); - Assertions.assertEquals(expectedObj, obj); + Assertions.assertArrayEquals(expectedObj, obj); } private R serialize(T obj, TypeHandler typeHandler) { diff --git a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/CollectionTypeHandlerFactoryTest.java b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/CollectionTypeHandlerFactoryTest.java index 1be029d43cb..2c7f388457e 100644 --- a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/CollectionTypeHandlerFactoryTest.java +++ b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/CollectionTypeHandlerFactoryTest.java @@ -1,8 +1,7 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.persistence.typeHandling.coreTypes.factories; -import com.google.common.collect.Maps; import org.junit.jupiter.api.Test; import org.terasology.persistence.typeHandling.TypeHandler; import org.terasology.persistence.typeHandling.TypeHandlerContext; @@ -10,7 +9,6 @@ import org.terasology.persistence.typeHandling.coreTypes.CollectionTypeHandler; import org.terasology.persistence.typeHandling.reflection.SerializationSandbox; import org.terasology.reflection.TypeInfo; -import org.terasology.reflection.reflect.ConstructorLibrary; import java.util.ArrayList; import java.util.List; @@ -25,7 +23,7 @@ public class CollectionTypeHandlerFactoryTest { private final TypeHandlerLibrary typeHandlerLibrary = mock(TypeHandlerLibrary.class); - private final CollectionTypeHandlerFactory typeHandlerFactory = new CollectionTypeHandlerFactory(new ConstructorLibrary(Maps.newHashMap())); + private final CollectionTypeHandlerFactory typeHandlerFactory = new CollectionTypeHandlerFactory(); private final TypeHandlerContext context = new TypeHandlerContext(typeHandlerLibrary, mock(SerializationSandbox.class));