Skip to content

Commit 47ead87

Browse files
committed
Refactoring class to avoid casts and raw use.
1 parent b61f86f commit 47ead87

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

src/main/java/io/eigr/spawn/api/actors/Value.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@
1111
import java.util.Objects;
1212
import java.util.Optional;
1313

14-
public final class Value<S extends GeneratedMessageV3, R extends GeneratedMessageV3> {
15-
16-
private S state;
17-
private R response;
14+
public final class Value {
1815

16+
private Object state;
17+
private Object response;
1918
private boolean checkpoint;
2019
private Optional<Broadcast<?>> broadcast;
2120
private Optional<Forward> forward;
2221
private Optional<Pipe> pipe;
23-
private Optional<List<SideEffect>> effects;
24-
25-
private ResponseType type;
22+
private Optional<List<SideEffect<?>>> effects;
23+
private final ResponseType type;
2624

2725
private Value() {
2826
this.state = null;
@@ -36,13 +34,13 @@ private Value() {
3634
}
3735

3836
private Value(
39-
R response,
40-
S state,
37+
Object response,
38+
Object state,
4139
boolean checkpoint,
4240
Optional<Broadcast<?>> broadcast,
4341
Optional<Forward> forward,
4442
Optional<Pipe> pipe,
45-
Optional<List<SideEffect>> effects,
43+
Optional<List<SideEffect<?>>> effects,
4644
ResponseType type) {
4745
this.response = response;
4846
this.state = state;
@@ -54,16 +52,16 @@ private Value(
5452
this.type = type;
5553
}
5654

57-
public static <S, V> Value at() {
55+
public static Value at() {
5856
return new Value();
5957
}
6058

61-
public R getResponse() {
62-
return response;
59+
public <R extends GeneratedMessageV3> R getResponse() {
60+
return (R) response;
6361
}
6462

65-
public S getState() {
66-
return state;
63+
public <S extends GeneratedMessageV3> S getState() {
64+
return (S) state;
6765
}
6866

6967
public boolean getCheckpoint() {
@@ -82,31 +80,31 @@ public Optional<Pipe> getPipe() {
8280
return pipe;
8381
}
8482

85-
public Optional<List<SideEffect>> getEffects() {
83+
public Optional<List<SideEffect<?>>> getEffects() {
8684
return effects;
8785
}
8886

8987
public ResponseType getType() {
9088
return type;
9189
}
9290

93-
public Value response(R value) {
91+
public Value response(Object value) {
9492
this.response = value;
9593
return this;
9694
}
9795

98-
public Value state(S state) {
96+
public <S extends GeneratedMessageV3> Value state(S state) {
9997
this.state = state;
10098
return this;
10199
}
102100

103-
public Value state(S state, boolean checkpoint) {
101+
public <S extends GeneratedMessageV3> Value state(S state, boolean checkpoint) {
104102
this.state = state;
105103
this.checkpoint = checkpoint;
106104
return this;
107105
}
108106

109-
public Value flow(Broadcast broadcast) {
107+
public Value flow(Broadcast<?> broadcast) {
110108
this.broadcast = Optional.of(broadcast);
111109
return this;
112110
}
@@ -121,8 +119,8 @@ public Value flow(Pipe pipe) {
121119
return this;
122120
}
123121

124-
public Value flow(SideEffect effect) {
125-
List<SideEffect> ef;
122+
public Value flow(SideEffect<?> effect) {
123+
List<SideEffect<?>> ef;
126124
if (this.effects.isPresent()) {
127125
ef = this.effects.get();
128126
ef.add(effect);
@@ -135,7 +133,7 @@ public Value flow(SideEffect effect) {
135133
return this;
136134
}
137135

138-
public Value flow(List<SideEffect> effects) {
136+
public Value flow(List<SideEffect<?>> effects) {
139137
this.effects = Optional.of(effects);
140138
return this;
141139
}
@@ -171,7 +169,7 @@ public String toString() {
171169
public boolean equals(Object o) {
172170
if (this == o) return true;
173171
if (o == null || getClass() != o.getClass()) return false;
174-
Value<?, ?> value = (Value<?, ?>) o;
172+
Value value = (Value) o;
175173
return Objects.equals(state, value.state) &&
176174
Objects.equals(response, value.response) &&
177175
Objects.equals(checkpoint, value.checkpoint) &&

src/main/java/io/eigr/spawn/internal/transport/server/ActorServiceHandler.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
import io.eigr.spawn.api.actors.Value;
1313
import io.eigr.spawn.api.actors.ActorContext;
1414
import io.eigr.spawn.api.actors.ActorFactory;
15-
import io.eigr.spawn.api.actors.workflows.Broadcast;
16-
import io.eigr.spawn.api.actors.workflows.Forward;
17-
import io.eigr.spawn.api.actors.workflows.Pipe;
1815
import io.eigr.spawn.api.actors.workflows.SideEffect;
1916
import io.eigr.spawn.api.exceptions.ActorInvocationException;
2017
import io.eigr.spawn.internal.Entity;
@@ -210,29 +207,29 @@ private Protocol.Workflow buildWorkflow(Value valueResponse) {
210207
Protocol.Workflow.Builder workflowBuilder = Protocol.Workflow.newBuilder();
211208

212209
if (valueResponse.getBroadcast().isPresent()) {
213-
Protocol.Broadcast b = ((Broadcast) valueResponse.getBroadcast().get()).build();
210+
Protocol.Broadcast b = valueResponse.getBroadcast().get().build();
214211
workflowBuilder.setBroadcast(b);
215212
}
216213

217214
if (valueResponse.getForward().isPresent()) {
218-
Protocol.Forward f = ((Forward) valueResponse.getForward().get()).build();
215+
Protocol.Forward f = valueResponse.getForward().get().build();
219216
workflowBuilder.setForward(f);
220217
}
221218

222219
if (valueResponse.getPipe().isPresent()) {
223-
Protocol.Pipe p = ((Pipe) valueResponse.getPipe().get()).build();
220+
Protocol.Pipe p = valueResponse.getPipe().get().build();
224221
workflowBuilder.setPipe(p);
225222
}
226223

227224
if (valueResponse.getEffects().isPresent()) {
228-
List<SideEffect> efs = ((List<SideEffect>) valueResponse.getEffects().get());
225+
List<SideEffect<?>> efs = valueResponse.getEffects().get();
229226
workflowBuilder.addAllEffects(getProtocolEffects(efs));
230227
}
231228

232229
return workflowBuilder.build();
233230
}
234231

235-
private List<Protocol.SideEffect> getProtocolEffects(List<SideEffect> effects) {
232+
private List<Protocol.SideEffect> getProtocolEffects(List<SideEffect<?>> effects) {
236233
return effects.stream()
237234
.map(SideEffect::build)
238235
.collect(Collectors.toList());

0 commit comments

Comments
 (0)