-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed descendancy pattern for ActorPlan
- Loading branch information
1 parent
3c78031
commit c6acdc8
Showing
9 changed files
with
160 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 14 additions & 45 deletions
59
simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ActorPlan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,45 @@ | ||
package gov.hhs.aspr.ms.gcm.simulation.nucleus; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import gov.hhs.aspr.ms.util.errors.ContractException; | ||
|
||
public class ActorPlan extends Plan { | ||
public abstract class ActorPlan extends Plan { | ||
|
||
// The actor id is used by the simulation via package access | ||
ActorId actorId; | ||
|
||
private final Consumer<ActorContext> consumer; | ||
|
||
|
||
/** | ||
* Constructs the plan scheduled for the given time active status arrivalId and | ||
* consumer | ||
* | ||
* @throw {@link ContractException} | ||
* <ul> | ||
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is | ||
* null</li> | ||
* </ul> | ||
* Constructs the plan scheduled for the given time, active status and arrivalId. | ||
* | ||
* | ||
*/ | ||
public ActorPlan(double time, boolean active, long arrivalId, Consumer<ActorContext> consumer) { | ||
public ActorPlan(double time, boolean active, long arrivalId) { | ||
super(time, active, arrivalId, Planner.ACTOR); | ||
if (consumer == null) { | ||
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); | ||
} | ||
this.consumer = consumer; | ||
} | ||
|
||
/** | ||
* Constructs the plan scheduled for the given time and consumer. The plan will | ||
* Constructs the plan scheduled for the given time. The plan will | ||
* be active.The arrival id is set to -1L indicating that this is a new, | ||
* non-deserialized plan. | ||
* | ||
* @throw {@link ContractException} | ||
* <ul> | ||
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is | ||
* null</li> | ||
* </ul> | ||
* | ||
*/ | ||
public ActorPlan(double time, Consumer<ActorContext> consumer) { | ||
public ActorPlan(double time) { | ||
super(time, true, -1L, Planner.ACTOR); | ||
if (consumer == null) { | ||
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); | ||
} | ||
this.consumer = consumer; | ||
} | ||
|
||
/** | ||
* Constructs the plan scheduled for the given time, active status and consumer. | ||
* Constructs the plan scheduled for the given time and active status. | ||
* The arrival id is set to -1L indicating that this is a new, non-deserialized | ||
* plan. | ||
* | ||
* @throw {@link ContractException} | ||
* <ul> | ||
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is | ||
* null</li> | ||
* </ul> | ||
* | ||
* | ||
*/ | ||
public ActorPlan(double time, boolean active, Consumer<ActorContext> consumer) { | ||
public ActorPlan(double time, boolean active) { | ||
super(time, active, -1L, Planner.ACTOR); | ||
if (consumer == null) { | ||
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); | ||
} | ||
this.consumer = consumer; | ||
} | ||
|
||
protected void execute(ActorContext context) { | ||
this.consumer.accept(context); | ||
} | ||
/** | ||
* Executes the actor logic associated with the plan. | ||
*/ | ||
protected abstract void execute(ActorContext context); | ||
} |
74 changes: 74 additions & 0 deletions
74
simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package gov.hhs.aspr.ms.gcm.simulation.nucleus; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import gov.hhs.aspr.ms.util.errors.ContractException; | ||
|
||
public final class ConsumerActorPlan extends ActorPlan { | ||
|
||
private final Consumer<ActorContext> consumer; | ||
|
||
/** | ||
* Constructs the plan scheduled for the given time active status arrivalId and | ||
* consumer | ||
* | ||
* @throw {@link ContractException} | ||
* <ul> | ||
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is | ||
* null</li> | ||
* </ul> | ||
* | ||
*/ | ||
public ConsumerActorPlan(double time, boolean active, long arrivalId, Consumer<ActorContext> consumer) { | ||
super(time, active, arrivalId); | ||
if (consumer == null) { | ||
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); | ||
} | ||
this.consumer = consumer; | ||
} | ||
|
||
/** | ||
* Constructs the plan scheduled for the given time and consumer. The plan will | ||
* be active.The arrival id is set to -1L indicating that this is a new, | ||
* non-deserialized plan. | ||
* | ||
* @throw {@link ContractException} | ||
* <ul> | ||
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is | ||
* null</li> | ||
* </ul> | ||
* | ||
*/ | ||
public ConsumerActorPlan(double time, Consumer<ActorContext> consumer) { | ||
super(time, true, -1L); | ||
if (consumer == null) { | ||
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); | ||
} | ||
this.consumer = consumer; | ||
} | ||
|
||
/** | ||
* Constructs the plan scheduled for the given time, active status and consumer. | ||
* The arrival id is set to -1L indicating that this is a new, non-deserialized | ||
* plan. | ||
* | ||
* @throw {@link ContractException} | ||
* <ul> | ||
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is | ||
* null</li> | ||
* </ul> | ||
* | ||
*/ | ||
public ConsumerActorPlan(double time, boolean active, Consumer<ActorContext> consumer) { | ||
super(time, active, -1L); | ||
if (consumer == null) { | ||
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); | ||
} | ||
this.consumer = consumer; | ||
} | ||
|
||
@Override | ||
protected final void execute(ActorContext context) { | ||
this.consumer.accept(context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 6 additions & 27 deletions
33
simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorPlan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,26 @@ | ||
package gov.hhs.aspr.ms.gcm.simulation.nucleus; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor; | ||
import gov.hhs.aspr.ms.util.errors.ContractException; | ||
|
||
public class AT_ActorPlan { | ||
|
||
@Test | ||
@UnitTestConstructor(target = ActorPlan.class, args = { double.class, Consumer.class }) | ||
@UnitTestConstructor(target = ActorPlan.class, args = { double.class }) | ||
public void testActorPlan() { | ||
//precondition test: if the consumer is null | ||
ContractException contractException = assertThrows(ContractException.class, ()->{ | ||
new ActorPlan(0, null); | ||
}); | ||
assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); | ||
//nothing to test | ||
} | ||
|
||
@Test | ||
@UnitTestConstructor(target = ActorPlan.class, args = { double.class, boolean.class, Consumer.class }) | ||
@UnitTestConstructor(target = ActorPlan.class, args = { double.class, boolean.class}) | ||
public void testConstructor_Active() { | ||
for (int i = 0; i < 10; i++) { | ||
ActorPlan actorPlan = new ActorPlan(i, i % 2 == 0, (c) -> { | ||
}); | ||
|
||
assertNotNull(actorPlan); | ||
} | ||
//nothing to test | ||
} | ||
|
||
@Test | ||
@UnitTestConstructor(target = ActorPlan.class, args = { double.class, boolean.class, long.class, Consumer.class }) | ||
@UnitTestConstructor(target = ActorPlan.class, args = { double.class, boolean.class, long.class}) | ||
public void testConstructor_Active_Arrival() { | ||
for (int i = 0; i < 10; i++) { | ||
ActorPlan actorPlan = new ActorPlan(i, i % 2 == 0, (long) i, (c) -> { | ||
}); | ||
|
||
assertNotNull(actorPlan); | ||
} | ||
//nothing to test | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerActorPlan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package gov.hhs.aspr.ms.gcm.simulation.nucleus; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor; | ||
import gov.hhs.aspr.ms.util.errors.ContractException; | ||
|
||
public class AT_ConsumerActorPlan { | ||
|
||
@Test | ||
@UnitTestConstructor(target = ConsumerActorPlan.class, args = { double.class, Consumer.class }) | ||
public void testActorPlan() { | ||
//precondition test: if the consumer is null | ||
ContractException contractException = assertThrows(ContractException.class, ()->{ | ||
new ConsumerActorPlan(0, null); | ||
}); | ||
assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); | ||
} | ||
|
||
@Test | ||
@UnitTestConstructor(target = ConsumerActorPlan.class, args = { double.class, boolean.class, Consumer.class }) | ||
public void testConstructor_Active() { | ||
//precondition test: if the consumer is null | ||
ContractException contractException = assertThrows(ContractException.class, ()->{ | ||
new ConsumerActorPlan(0,true, null); | ||
}); | ||
assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); | ||
} | ||
|
||
@Test | ||
@UnitTestConstructor(target = ConsumerActorPlan.class, args = { double.class, boolean.class, long.class, Consumer.class }) | ||
public void testConstructor_Active_Arrival() { | ||
//precondition test: if the consumer is null | ||
ContractException contractException = assertThrows(ContractException.class, ()->{ | ||
new ConsumerActorPlan(0,true,2345345L, null); | ||
}); | ||
assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); | ||
} | ||
} |