Skip to content

Commit

Permalink
[SCB-2031] optimize code as review opinion
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0092 authored and wujimin committed Jul 6, 2020
1 parent 51f0c50 commit 0d1af3f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Expand Up @@ -19,6 +19,7 @@
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.OperationMeta;
Expand All @@ -29,6 +30,8 @@
import org.apache.servicecomb.swagger.generator.OperationGenerator;
import org.apache.servicecomb.swagger.generator.SwaggerGenerator;

import com.google.common.annotations.VisibleForTesting;

public class PojoConsumerMeta {
private MicroserviceReferenceConfig microserviceReferenceConfig;

Expand Down Expand Up @@ -75,8 +78,14 @@ public SchemaMeta getSchemaMeta() {
return schemaMeta;
}

@VisibleForTesting
public PojoConsumerOperationMeta findOperationMeta(String consumerMethodName) {
return operationMetas.get(consumerMethodName);
for (Entry<Method, PojoConsumerOperationMeta> operationMetaEntry : operationMetas.entrySet()) {
if (operationMetaEntry.getKey().getName().equals(consumerMethodName)) {
return operationMetaEntry.getValue();
}
}
return null;
}

public PojoConsumerOperationMeta findOperationMeta(Method consumerMethod) {
Expand Down
Expand Up @@ -19,6 +19,9 @@
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import com.google.common.annotations.VisibleForTesting;

public class SwaggerConsumer {
private Class<?> consumerIntf;
Expand All @@ -38,8 +41,18 @@ public void addOperation(SwaggerConsumerOperation op) {
operations.put(op.getConsumerMethod(), op);
}

@VisibleForTesting
public SwaggerConsumerOperation findOperation(String consumerMethodName) {
return operations.get(consumerMethodName);
for (Entry<Method, SwaggerConsumerOperation> operationEntry : operations.entrySet()) {
if (operationEntry.getKey().getName().equals(consumerMethodName)) {
return operationEntry.getValue();
}
}
return null;
}

public SwaggerConsumerOperation findOperation(Method consumerMethod) {
return operations.get(consumerMethod);
}

public Map<Method, SwaggerConsumerOperation> getOperations() {
Expand Down

0 comments on commit 0d1af3f

Please sign in to comment.