Skip to content

Commit

Permalink
Replace if..else with switch in TypeMessageBuilderImpl (apache#7947)
Browse files Browse the repository at this point in the history
  • Loading branch information
aloyszhang authored Sep 3, 2020
1 parent 452a5f2 commit 7e4ace2
Showing 1 changed file with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,36 @@ public TypedMessageBuilder<T> deliverAt(long timestamp) {
@Override
public TypedMessageBuilder<T> loadConf(Map<String, Object> config) {
config.forEach((key, value) -> {
if (key.equals(CONF_KEY)) {
this.key(checkType(value, String.class));
} else if (key.equals(CONF_PROPERTIES)) {
this.properties(checkType(value, Map.class));
} else if (key.equals(CONF_EVENT_TIME)) {
this.eventTime(checkType(value, Long.class));
} else if (key.equals(CONF_SEQUENCE_ID)) {
this.sequenceId(checkType(value, Long.class));
} else if (key.equals(CONF_REPLICATION_CLUSTERS)) {
this.replicationClusters(checkType(value, List.class));
} else if (key.equals(CONF_DISABLE_REPLICATION)) {
boolean disableReplication = checkType(value, Boolean.class);
if (disableReplication) {
this.disableReplication();
}
} else if (key.equals(CONF_DELIVERY_AFTER_SECONDS)) {
this.deliverAfter(checkType(value, Long.class), TimeUnit.SECONDS);
} else if (key.equals(CONF_DELIVERY_AT)) {
this.deliverAt(checkType(value, Long.class));
} else {
throw new RuntimeException("Invalid message config key '" + key + "'");
switch (key) {
case CONF_KEY:
this.key(checkType(value, String.class));
break;
case CONF_PROPERTIES:
this.properties(checkType(value, Map.class));
break;
case CONF_EVENT_TIME:
this.eventTime(checkType(value, Long.class));
break;
case CONF_SEQUENCE_ID:
this.sequenceId(checkType(value, Long.class));
break;
case CONF_REPLICATION_CLUSTERS:
this.replicationClusters(checkType(value, List.class));
break;
case CONF_DISABLE_REPLICATION:
boolean disableReplication = checkType(value, Boolean.class);
if (disableReplication) {
this.disableReplication();
}
break;
case CONF_DELIVERY_AFTER_SECONDS:
this.deliverAfter(checkType(value, Long.class), TimeUnit.SECONDS);
break;
case CONF_DELIVERY_AT:
this.deliverAt(checkType(value, Long.class));
break;
default:
throw new RuntimeException("Invalid message config key '" + key + "'");
}
});
return this;
Expand Down

0 comments on commit 7e4ace2

Please sign in to comment.