dcapwell commented on code in PR #8:
URL: https://github.com/apache/cassandra-accord/pull/8#discussion_r936112712
##########
accord-maelstrom/src/main/java/accord/maelstrom/Packet.java:
##########
@@ -16,33 +17,49 @@
public class Packet implements ReplyContext
{
+
public enum Type
{
init(MaelstromInit.class, MaelstromInit.GSON_ADAPTER),
init_ok(Body.class, Body.GSON_ADAPTER),
txn(MaelstromRequest.class, MaelstromRequest.GSON_ADAPTER),
txn_ok(MaelstromReply.class, MaelstromReply.GSON_ADAPTER),
error(Error.class, Error.GSON_ADAPTER),
- PreAccept(accord.messages.PreAccept.class, Json.DEFAULT_ADAPTER),
- PreAcceptOk(accord.messages.PreAccept.PreAcceptOk.class,
Json.DEFAULT_ADAPTER),
- PreAcceptNack(accord.messages.PreAccept.PreAcceptNack.class,
Json.DEFAULT_ADAPTER),
- Accept(accord.messages.Accept.class, Json.DEFAULT_ADAPTER),
- AcceptOk(accord.messages.Accept.AcceptOk.class, Json.DEFAULT_ADAPTER),
- AcceptNack(accord.messages.Accept.AcceptNack.class,
Json.DEFAULT_ADAPTER),
- Commit(accord.messages.Commit.class, Json.DEFAULT_ADAPTER),
- Apply(Apply.class, Json.DEFAULT_ADAPTER),
- Read(ReadData.class, Json.DEFAULT_ADAPTER),
- ReadOk(ReadData.ReadOk.class, Json.DEFAULT_ADAPTER),
- ReadNack(ReadData.ReadNack.class, Json.DEFAULT_ADAPTER),
- WaitOnCommit(accord.messages.WaitOnCommit.class, Json.DEFAULT_ADAPTER),
- WaitOnCommitOk(accord.messages.WaitOnCommit.WaitOnCommitOk.class,
Json.DEFAULT_ADAPTER),
- Recover(BeginRecovery.class, Json.DEFAULT_ADAPTER),
- RecoverOk(BeginRecovery.RecoverOk.class, Json.DEFAULT_ADAPTER),
- RecoverNack(BeginRecovery.RecoverNack.class, Json.DEFAULT_ADAPTER);
-
- public static final Function<Class<?>, Type> LOOKUP =
Arrays.stream(Type.values())
- .filter(t
-> t.type != null)
-
.<Map<Class<?>, Type>>collect(HashMap::new, (m, t) -> m.put(t.type, t),
Map::putAll)::get;
+ PreAccept(accord.messages.PreAccept.class),
+ PreAcceptOk(accord.messages.PreAccept.PreAcceptOk.class),
+ PreAcceptNack(accord.messages.PreAccept.PreAcceptNack.class),
+ Accept(accord.messages.Accept.class),
+ AcceptOk(accord.messages.Accept.AcceptOk.class),
+ AcceptNack(accord.messages.Accept.AcceptNack.class),
+ Commit(accord.messages.Commit.class),
+ Apply(Apply.class),
+ ApplyOk(Apply.ApplyOk.class),
+ Read(ReadData.class),
+ ReadOk(ReadData.ReadOk.class),
+ ReadNack(ReadData.ReadNack.class),
+ WaitOnCommit(accord.messages.WaitOnCommit.class),
+ WaitOnCommitOk(accord.messages.WaitOnCommit.WaitOnCommitOk.class),
+ Recover(BeginRecovery.class),
+ RecoverOk(BeginRecovery.RecoverOk.class),
+ RecoverNack(BeginRecovery.RecoverNack.class),
+ CheckStatus(CheckStatus.class),
+ CheckStatusOk(CheckStatus.CheckStatusOk.class),
+ CheckStatusOkFull(CheckStatus.CheckStatusOkFull.class),
+ InformOfTxn(InformOfTxn.class),
+ InformOfTxnOk(InformOfTxn.InformOfTxnOk.class),
+ InformOfPersistence(InformOfPersistence.class),
+ SimpleProgressLog_ApplyAndCheck(SimpleProgressLog.ApplyAndCheck.class),
+
SimpleProgressLog_ApplyAndCheckOk(SimpleProgressLog.ApplyAndCheckOk.class);
+
+ private static final Map<Class<?>, Type> LOOKUP =
Arrays.stream(Type.values())
Review Comment:
> Or else could have a static method to transform the prior function
construction to introduce the null check
I did both. Looked and saw this `Function` is only used within this class,
so made it a static function rather than `Function` object where we call
`.apply`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]