Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] #4270

Merged
merged 4 commits into from
Jul 25, 2023
Merged

[ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] #4270

merged 4 commits into from
Jul 25, 2023

Conversation

devCod3r
Copy link
Contributor

Fixes #4269

Motivation

Replaced the if-else conditions with switch cases.
ISSUE #4269

Modifications

Describe the modifications you've done.
Replaced the if-else conditions with switch cases.

Documentation

  • Does this pull request introduce a new feature?
  • Ans: no
  • If a feature is not applicable for documentation, explain why?
  • Ans: Replaced the if-else conditions with switch cases.

Comment on lines 123 to 124
}
map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new String(cloudEvent.getData().toBytes(), StandardCharsets.UTF_8));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StandardCharsets.UTF_8 replace with Constants.DEFAULT_CHARSET

@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Merging #4270 (5d8ff20) into master (6c94d9d) will increase coverage by 0.00%.
The diff coverage is 0.00%.

❗ Current head 5d8ff20 differs from pull request most recent head 42cc3fe. Consider uploading reports for the commit 42cc3fe to get more accurate results

@@            Coverage Diff            @@
##             master    #4270   +/-   ##
=========================================
  Coverage     16.86%   16.87%           
  Complexity     1426     1426           
=========================================
  Files           593      593           
  Lines         26073    26068    -5     
  Branches       2401     2396    -5     
=========================================
  Hits           4398     4398           
+ Misses        21234    21229    -5     
  Partials        441      441           
Impacted Files Coverage Δ
...otocol/meshmessage/MeshMessageProtocolAdaptor.java 4.34% <0.00%> (+0.42%) ⬆️
...he/eventmesh/runtime/boot/EventMeshHTTPServer.java 0.52% <0.00%> (ø)
.../protocol/http/processor/CreateTopicProcessor.java 0.00% <0.00%> (ø)
.../protocol/http/processor/DeleteTopicProcessor.java 0.00% <0.00%> (ø)
...col/http/processor/QuerySubscriptionProcessor.java 0.00% <0.00%> (ø)
...nt/tcp/impl/cloudevent/CloudEventTCPPubClient.java 6.06% <ø> (ø)
...nt/tcp/impl/cloudevent/CloudEventTCPSubClient.java 5.88% <ø> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

case MSG_BATCH_SEND_V2:
return SendMessageBatchV2ProtocolResolver.buildEvent(header, body);
case MSG_SEND_SYNC:
return SendMessageRequestProtocolResolver.buildEvent(header, body);
Copy link
Member

@Pil0tXia Pil0tXia Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 87 is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged both the Cases.

@Override
public Map<String, Object> toMap() {
if (cloudEvent.getData() == null) {
cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change needs to be made in this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted back the changes (Removed few white spaces).

Comment on lines 123 to 124
map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new String(cloudEvent.getData().toBytes(),
Constants.DEFAULT_CHARSET));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider putting the second argument on the same line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second argument is on the same line but when I tried to put all the 3 arguments in the same line, I got the warning as shown below:
image

Copy link
Member

@Pil0tXia Pil0tXia Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this:

map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT,
        new String(cloudEvent.getData().toBytes(), Constants.DEFAULT_CHARSET));

Because new String(cloudEvent.getData().toBytes(), Constants.DEFAULT_CHARSET) is the second argument of map.put.

Put method doesn't have three arguments; it's the original line breaks that make it look like it has three arguments .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have put the whole second argument in the next line as suggested, thank you for the info :)

@mxsm
Copy link
Member

mxsm commented Jul 22, 2023

@devCod3r devCod3r requested review from Pil0tXia and mxsm July 24, 2023 12:28
Copy link
Member

@Pil0tXia Pil0tXia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xwm1992 xwm1992 merged commit 2cb5aa9 into apache:master Jul 25, 2023
fabian4 pushed a commit to fabian4/eventmesh that referenced this pull request Jul 25, 2023
…rotocolAdaptor] (apache#4270)

* [ISSUE apache#4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE apache#4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE apache#4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE apache#4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]
xwm1992 pushed a commit that referenced this pull request Jul 27, 2023
* feat: add redis connector.

* feat: add redis connector.

* feat: add redis connector.

* feat: add redis connector.

* feat: add redis connector.

* [ISSUE #4023]Comparison using reference equality instead of value equality.[Operation] (#4276)

* [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (#4270)

* [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE #4099]Refactor re-used constant's usage from dedicated file (#4257)

* [ISSUE #4099]: Refactor re-used constant's usage from dedicated file

* [ISSUE #4099] Rename some constants for mongodb storage plugin

* [ISSUE #4099] Refactor constant imports in mongodb cloud event util

* [ISSUE #4099]: Replace contants imports to class import in mongo cloud event util

* fix import order.

* fix import order.

* fix import order.

* fix import order.

---------

Co-authored-by: Fabian Bao <fabian.bao@agfa.com>
Co-authored-by: kyooosukedn <87076947+kyooosukedn@users.noreply.github.com>
Co-authored-by: Sam V Jose <124816912+devCod3r@users.noreply.github.com>
Co-authored-by: ruhshan <ruhshan.ahmed@gmail.com>
hhuang1231 added a commit to hhuang1231/eventmesh that referenced this pull request Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Use switch to replace the if-else.[MeshMessageProtocolAdaptor]
4 participants