You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/03/04 17:31:52 UTC

[isis] 04/09: ISIS-439: further work removing dead code re: mutable collections

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-2444
in repository https://gitbox.apache.org/repos/asf/isis.git

commit bb9888db38b75969451ba1429f4e5e9ecdb75829
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Mar 3 07:09:21 2021 +0000

    ISIS-439: further work removing dead code re: mutable collections
---
 .../events/domain/CollectionDomainEvent.java       | 31 -------------------
 .../core/metamodel/facets/DomainEventHelper.java   | 36 ++++++++--------------
 .../modify/CollectionDomainEventFacetAbstract.java | 12 ++++----
 ...HelperTest_newCollectionDomainEvent_forAdd.java |  6 ++--
 ...perTest_newCollectionDomainEvent_forRemove.java |  6 ++--
 5 files changed, 25 insertions(+), 66 deletions(-)

diff --git a/api/applib/src/main/java/org/apache/isis/applib/events/domain/CollectionDomainEvent.java b/api/applib/src/main/java/org/apache/isis/applib/events/domain/CollectionDomainEvent.java
index 7b1c489..a126c76 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/events/domain/CollectionDomainEvent.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/events/domain/CollectionDomainEvent.java
@@ -27,17 +27,6 @@ import lombok.Getter;
  * Subclass of {@link AbstractDomainEvent} for collections.
  *
  * <p>
- * The class has a couple of responsibilities (in addition to those it
- * inherits):
- * </p>
- *
- * <ul>
- *     <li>
- *      capture the target object being interacted with
- *     </li>
- * </ul>
- *
- * <p>
  * The class itself is instantiated automatically by the framework whenever
  * interacting with a rendered object's collection.
  * </p>
@@ -83,31 +72,11 @@ public abstract class CollectionDomainEvent<S,T> extends AbstractDomainEvent<S>
 
 
 
-    /**
-     * The proposed reference to either add or remove (per {@link #getOf()}), populated at
-     * {@link org.apache.isis.applib.events.domain.AbstractDomainEvent.Phase#VALIDATE}
-     * and subsequent phases (is null for
-     * {@link org.apache.isis.applib.events.domain.AbstractDomainEvent.Phase#HIDE hidden}
-     * and {@link org.apache.isis.applib.events.domain.AbstractDomainEvent.Phase#DISABLE disable} phases).
-     */
-    @Getter
-    private T value;
-
-
-    /**
-     * Not API, set by the framework.
-     */
-    public void setValue(T value) {
-        this.value = value;
-    }
-
-
     private static final ToString<CollectionDomainEvent<?,?>> toString =
             ObjectContracts.<CollectionDomainEvent<?,?>>
     toString("source", CollectionDomainEvent::getSource)
     .thenToString("identifier", CollectionDomainEvent::getIdentifier)
     .thenToString("eventPhase", CollectionDomainEvent::getEventPhase)
-    .thenToString("value", CollectionDomainEvent::getValue)
     ;
 
     @Override
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/DomainEventHelper.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/DomainEventHelper.java
index 56cb6d6..2eb6e2c 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/DomainEventHelper.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/DomainEventHelper.java
@@ -306,31 +306,24 @@ public class DomainEventHelper {
     // -- postEventForCollection, newCollectionDomainEvent
 
     public <S, T> CollectionDomainEvent<S, T> postEventForCollection(
-            AbstractDomainEvent.Phase phase,
+            final AbstractDomainEvent.Phase phase,
             final Class<? extends CollectionDomainEvent<S, T>> eventType,
-            final CollectionDomainEvent<S, T> existingEvent,
             final IdentifiedHolder identified,
-            final InteractionHead head,
-            final T reference) {
+            final InteractionHead head) {
 
         _Assert.assertTypeIsInstanceOf(eventType, CollectionDomainEvent.class);
 
         try {
             final CollectionDomainEvent<S, T> event;
-            if (existingEvent != null && phase.isExecuted()) {
-                // reuse existing event from the executing phase
-                event = existingEvent;
-            } else {
-                // all other phases, create a new event
-                final S source = uncheckedCast(UnwrapUtil.single(head.getTarget()));
-                final Identifier identifier = identified.getIdentifier();
-                event = newCollectionDomainEvent(eventType, phase, identifier, source, reference);
 
-                // copy over if have
-                head.getMixedIn()
-                .ifPresent(mixedInAdapter->
-                    event.setMixedIn(mixedInAdapter.getPojo()));
-            }
+            final S source = uncheckedCast(UnwrapUtil.single(head.getTarget()));
+            final Identifier identifier = identified.getIdentifier();
+            event = newCollectionDomainEvent(eventType, phase, identifier, source);
+
+            // copy over if have
+            head.getMixedIn()
+            .ifPresent(mixedInAdapter->
+                event.setMixedIn(mixedInAdapter.getPojo()));
 
             event.setEventPhase(phase);
 
@@ -345,8 +338,7 @@ public class DomainEventHelper {
             final Class<? extends CollectionDomainEvent<S, T>> type,
             final AbstractDomainEvent.Phase phase,
             final Identifier identifier,
-            final S source,
-            final T value)
+            final S source)
             throws NoSuchMethodException, SecurityException,
             IllegalArgumentException {
 
@@ -360,21 +352,19 @@ public class DomainEventHelper {
 
             cde.initSource(source);
             cde.setIdentifier(identifier);
-            cde.setValue(value);
             return cde;
         }
 
         // else
-        // search for constructor accepting source, identifier, type, value
+        // search for constructor accepting source, identifier
         val updateEventConstructors = constructors
                 .filter(paramCount(4)
                         .and(paramAssignableFrom(0, source.getClass()))
                         .and(paramAssignableFrom(1, Identifier.class))
-                        .and(paramAssignableFromValue(2, value))
                         );
 
         for (val constructor : updateEventConstructors) {
-            val event = invokeConstructor(constructor, source, identifier, value);
+            val event = invokeConstructor(constructor, source, identifier);
             return uncheckedCast(event);
         }
 
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetAbstract.java
index e400f70..7046627 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetAbstract.java
@@ -74,9 +74,9 @@ public abstract class CollectionDomainEventFacetAbstract
         final CollectionDomainEvent<?, ?> event =
                 domainEventHelper.postEventForCollection(
                         AbstractDomainEvent.Phase.HIDE,
-                        getEventType(), null,
-                        getIdentified(), ic.getHead(),
-                        null);
+                        getEventType(),
+                        getIdentified(), ic.getHead()
+                );
         if (event != null && event.isHidden()) {
             return "Hidden by subscriber";
         }
@@ -89,9 +89,9 @@ public abstract class CollectionDomainEventFacetAbstract
         final CollectionDomainEvent<?, ?> event =
                 domainEventHelper.postEventForCollection(
                         AbstractDomainEvent.Phase.DISABLE,
-                        getEventType(), null,
-                        getIdentified(), ic.getHead(),
-                        null);
+                        getEventType(),
+                        getIdentified(), ic.getHead()
+                );
         if (event != null && event.isDisabled()) {
             final TranslatableString reasonTranslatable = event.getDisabledReasonTranslatable();
             if(reasonTranslatable != null) {
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forAdd.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forAdd.java
index 5ae89a1..5abc008 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forAdd.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forAdd.java
@@ -48,7 +48,7 @@ public class DomainEventHelperTest_newCollectionDomainEvent_forAdd {
                 LogicalType.fqcn(SomeDomainObject.class), "references");
 
         final CollectionDomainEvent<Object, Object> ev = Utils.domainEventHelper().newCollectionDomainEvent(
-                CollectionDomainEvent.Default.class, null, identifier, sdo, other);
+                CollectionDomainEvent.Default.class, null, identifier, sdo);
         assertSame(ev.getSource(), sdo);
         assertThat(ev.getIdentifier(), is(identifier));
         assertThat(ev.getOf(), is(CollectionDomainEvent.Of.ADD_TO));
@@ -63,7 +63,7 @@ public class DomainEventHelperTest_newCollectionDomainEvent_forAdd {
                 LogicalType.fqcn(SomeDomainObject.class), "references");
 
         final CollectionDomainEvent<Object, Object> ev = Utils.domainEventHelper().newCollectionDomainEvent(
-                CollectionDomainEvent.Default.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, other);
+                CollectionDomainEvent.Default.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo);
         assertSame(ev.getSource(), sdo);
         assertThat(ev.getIdentifier(), is(identifier));
         assertThat(ev.getOf(), is(CollectionDomainEvent.Of.ADD_TO));
@@ -78,7 +78,7 @@ public class DomainEventHelperTest_newCollectionDomainEvent_forAdd {
                 LogicalType.fqcn(SomeDomainObject.class), "references");
 
         final CollectionDomainEvent<SomeDomainObject, SomeReferencedObject> ev = Utils.domainEventHelper().newCollectionDomainEvent(
-                SomeDomainObjectCollectionDomainEvent.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, other);
+                SomeDomainObjectCollectionDomainEvent.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo);
         assertThat(ev.getSource(), is(sdo));
         assertThat(ev.getIdentifier(), is(identifier));
         assertThat(ev.getOf(), is(CollectionDomainEvent.Of.ADD_TO));
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forRemove.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forRemove.java
index dc2c6d0..b4e2a52 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forRemove.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forRemove.java
@@ -48,7 +48,7 @@ public class DomainEventHelperTest_newCollectionDomainEvent_forRemove {
                 LogicalType.fqcn(SomeDomainObject.class), "references");
 
         final CollectionDomainEvent<Object, Object> ev = Utils.domainEventHelper().newCollectionDomainEvent(
-                CollectionDomainEvent.Default.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, other);
+                CollectionDomainEvent.Default.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo);
         assertSame(ev.getSource(), sdo);
         assertThat(ev.getIdentifier(), is(identifier));
         assertThat(ev.getOf(), is(CollectionDomainEvent.Of.REMOVE_FROM));
@@ -63,7 +63,7 @@ public class DomainEventHelperTest_newCollectionDomainEvent_forRemove {
                 LogicalType.fqcn(SomeDomainObject.class), "references");
 
         final CollectionDomainEvent<Object, Object> ev = Utils.domainEventHelper().newCollectionDomainEvent(
-                CollectionDomainEvent.Default.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, other);
+                CollectionDomainEvent.Default.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo);
         assertSame(ev.getSource(), sdo);
         assertThat(ev.getIdentifier(), is(identifier));
         assertThat(ev.getOf(), is(CollectionDomainEvent.Of.REMOVE_FROM));
@@ -78,7 +78,7 @@ public class DomainEventHelperTest_newCollectionDomainEvent_forRemove {
                 LogicalType.fqcn(SomeDomainObject.class), "references");
 
         final CollectionDomainEvent<SomeDomainObject, SomeReferencedObject> ev = Utils.domainEventHelper().newCollectionDomainEvent(
-                SomeDomainObjectCollectionRemovedFromDomainEvent.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, other);
+                SomeDomainObjectCollectionRemovedFromDomainEvent.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo);
         assertThat(ev.getSource(), is(sdo));
         assertThat(ev.getIdentifier(), is(identifier));
         assertThat(ev.getOf(), is(CollectionDomainEvent.Of.REMOVE_FROM));