From f4762fd12554c961d2526b121749f3b8199bf77f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Darri=20Sigur=C3=B0sson?= Date: Sat, 23 Nov 2024 15:13:23 +0000 Subject: [PATCH] Entity.Copy.immutable() removed --- changelog.md | 1 + .../framework/domain/entity/DefaultEntity.java | 5 ----- .../is/codion/framework/domain/entity/Entity.java | 14 +++----------- .../framework/domain/entity/DefaultEntityTest.java | 6 +++--- .../framework/domain/entity/EntitiesTest.java | 7 +++---- 5 files changed, 10 insertions(+), 23 deletions(-) diff --git a/changelog.md b/changelog.md index 0e38ec1616..8c4ff5fdd9 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ Codion Change Log - AttributeDefinition.definitionComparator() removed. - Entity.groupKeysByType() moved to Entity.Key and renamed groupByType(). - Entity.Key.copyBuilder() renamed copy(). +- Entity.Copy.immutable() removed. ### is.codion.swing.framework.ui - EntityTableCellRenderer, Item based cells now use the default horizontal alignment instead of the one based on the the item value type. - DefaultEntityApplicationPanelBuilder bug fixed, exception handling during application start improved. diff --git a/framework/domain/src/main/java/is/codion/framework/domain/entity/DefaultEntity.java b/framework/domain/src/main/java/is/codion/framework/domain/entity/DefaultEntity.java index 0841c248fd..3dda6ee3c8 100644 --- a/framework/domain/src/main/java/is/codion/framework/domain/entity/DefaultEntity.java +++ b/framework/domain/src/main/java/is/codion/framework/domain/entity/DefaultEntity.java @@ -903,11 +903,6 @@ public Entity mutable() { return copy; } - @Override - public Entity immutable() { - return new ImmutableEntity(entity.definition, entity.values, entity.originalValues, new HashMap<>()); - } - @Override public Builder builder() { return new DefaultEntityBuilder(entity.definition, entity.values, entity.originalValues); diff --git a/framework/domain/src/main/java/is/codion/framework/domain/entity/Entity.java b/framework/domain/src/main/java/is/codion/framework/domain/entity/Entity.java index 91bc0d2fcf..4d38812102 100644 --- a/framework/domain/src/main/java/is/codion/framework/domain/entity/Entity.java +++ b/framework/domain/src/main/java/is/codion/framework/domain/entity/Entity.java @@ -87,8 +87,7 @@ public interface Entity extends Comparable { Optional optional(Attribute attribute); /** - * Returns the original value associated with {@code attribute}, - * or the current one if it has not been modified.. + * Returns the original value associated with {@code attribute}, or the current one if it is unmodified. * @param attribute the attribute for which to retrieve the original value * @param the value type * @return the original value of the given attribute @@ -175,7 +174,7 @@ public interface Entity extends Comparable { * a foreign key value exists but the actual referenced entity has not * been loaded, an "empty" entity is returned, containing only the referenced * key value(s). Null is returned only if the actual foreign key is null. - * @param foreignKey the foreign key for which to retrieve the value + * @param foreignKey the foreign key for which to retrieve the referenced entity * @return the entity associated with {@code foreignKey} */ Entity entity(ForeignKey foreignKey); @@ -298,7 +297,6 @@ public interface Entity extends Comparable { * Provides ways to create copies of an entity instance. *
    *
  • {@link #mutable()} returns a mutable copy - *
  • {@link #immutable()} returns an immutable copy *
  • {@link #builder()} returns a {@link Builder} instance initialized with the values of the entity being copied *
*/ @@ -306,16 +304,10 @@ interface Copy { /** * Returns a mutable copy of this entity. - * @return a copy of this entity + * @return a mutable copy of this entity */ Entity mutable(); - /** - * Returns a mutable copy of this entity. - * @return a copy of this entity - */ - Entity immutable(); - /** * Returns a new {@link Builder} instance initialized with the values and original values from this entity. * @return a {@link Builder} instance. diff --git a/framework/domain/src/test/java/is/codion/framework/domain/entity/DefaultEntityTest.java b/framework/domain/src/test/java/is/codion/framework/domain/entity/DefaultEntityTest.java index 956455cf15..a23012e99c 100644 --- a/framework/domain/src/test/java/is/codion/framework/domain/entity/DefaultEntityTest.java +++ b/framework/domain/src/test/java/is/codion/framework/domain/entity/DefaultEntityTest.java @@ -414,7 +414,7 @@ void entity() { testEntity.key(Detail.MASTER_FK); //test copy() - Entity test2 = testEntity.copy().immutable().copy().mutable(); + Entity test2 = testEntity.immutable().copy().mutable(); assertNotSame(test2, testEntity, "Entity copy should not be == the original"); assertEquals(test2, testEntity, "Entities should be equal after .getCopy()"); assertTrue(test2.equalValues(testEntity), "Entity attribute values should be equal after deepCopy()"); @@ -422,7 +422,7 @@ void entity() { test2.put(Detail.DOUBLE, 2.1); assertTrue(test2.modified()); - Entity test2Copy = test2.copy().immutable(); + Entity test2Copy = test2.immutable(); assertTrue(test2Copy.modified()); //test propagate entity reference/denormalized values @@ -759,7 +759,7 @@ void foreignKeyModification() { emp.put(Employee.MANAGER_FK, manager); emp.put(Employee.DEPARTMENT_FK, dept2); - Entity copy = emp.copy().immutable(); + Entity copy = emp.immutable(); assertNotSame(emp, copy); assertTrue(emp.equalValues(copy)); assertNotSame(emp.get(Employee.MANAGER_FK), copy.get(Employee.MANAGER_FK)); diff --git a/framework/domain/src/test/java/is/codion/framework/domain/entity/EntitiesTest.java b/framework/domain/src/test/java/is/codion/framework/domain/entity/EntitiesTest.java index d18ba3a125..b905f91a7f 100644 --- a/framework/domain/src/test/java/is/codion/framework/domain/entity/EntitiesTest.java +++ b/framework/domain/src/test/java/is/codion/framework/domain/entity/EntitiesTest.java @@ -464,8 +464,7 @@ void copyEntities() { .build(); Iterator copies = Stream.of(dept1, dept2) - .map(Entity::copy) - .map(Entity.Copy::immutable) + .map(Entity::immutable) .collect(toList()) .iterator(); Entity dept1Copy = copies.next(); @@ -486,10 +485,10 @@ void copyEntities() { assertSame(emp1.get(Employee.DEPARTMENT_FK), copy.get(Employee.DEPARTMENT_FK)); assertFalse(emp1.modified()); - copy = copy.copy().immutable(); + copy = copy.immutable(); assertNotSame(emp1.get(Employee.DEPARTMENT_FK), copy.get(Employee.DEPARTMENT_FK)); - copy = emp1.copy().immutable(); + copy = emp1.immutable(); assertFalse(copy.mutable()); assertTrue(emp1.equalValues(copy)); assertNotSame(emp1.get(Employee.DEPARTMENT_FK), copy.get(Employee.DEPARTMENT_FK));