Skip to content

Commit

Permalink
Entity.Copy.immutable() removed
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorndarri committed Nov 23, 2024
1 parent 7057f57 commit f4762fd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public interface Entity extends Comparable<Entity> {
<T> Optional<T> optional(Attribute<T> 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 <T> the value type
* @return the original value of the given attribute
Expand Down Expand Up @@ -175,7 +174,7 @@ public interface Entity extends Comparable<Entity> {
* 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);
Expand Down Expand Up @@ -298,24 +297,17 @@ public interface Entity extends Comparable<Entity> {
* Provides ways to create copies of an entity instance.
* <ul>
* <li>{@link #mutable()} returns a mutable copy
* <li>{@link #immutable()} returns an immutable copy
* <li>{@link #builder()} returns a {@link Builder} instance initialized with the values of the entity being copied
* </ul>
*/
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,15 @@ 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()");
assertNotSame(testEntity.entity(Detail.MASTER_FK), test2.entity(Detail.MASTER_FK), "This should be a deep copy");

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
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,7 @@ void copyEntities() {
.build();

Iterator<Entity> copies = Stream.of(dept1, dept2)
.map(Entity::copy)
.map(Entity.Copy::immutable)
.map(Entity::immutable)
.collect(toList())
.iterator();
Entity dept1Copy = copies.next();
Expand All @@ -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));
Expand Down

0 comments on commit f4762fd

Please sign in to comment.