Refactor: specify the generic type for protobuf enum translator
Change-Id: I5a1df0cc2ab2372b68d5851b7b2a449c5d958bfe
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationEnumsProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationEnumsProtoTranslator.java
index d82f93e..6fe0319 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationEnumsProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationEnumsProtoTranslator.java
@@ -59,7 +59,7 @@
* @param roleProto gRPC message
* @return {@link ApplicationRole}
*/
- public static Optional<Object> translate(ApplicationRoleProto roleProto) {
+ public static Optional<ApplicationRole> translate(ApplicationRoleProto roleProto) {
switch (roleProto) {
case USER:
@@ -101,7 +101,7 @@
* @param stateProto gRPC message
* @return {@link ApplicationState}
*/
- public static Optional<Object> translate(ApplicationStateProto stateProto) {
+ public static Optional<ApplicationState> translate(ApplicationStateProto stateProto) {
switch (stateProto) {
case ACTIVE:
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationProtoTranslator.java
index 568be18..25a95e4 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationProtoTranslator.java
@@ -17,7 +17,6 @@
import com.google.common.collect.Sets;
import org.onosproject.core.Application;
-import org.onosproject.core.ApplicationRole;
import org.onosproject.core.DefaultApplication;
import org.onosproject.grpc.core.models.ApplicationProtoOuterClass.ApplicationProto;
import org.onosproject.incubator.protobuf.models.security.PermissionProtoTranslator;
@@ -57,7 +56,7 @@
.withUrl(app.getUrl())
.withReadme(app.getReadme())
.withIcon(app.toByteArray())
- .withRole((ApplicationRole) ApplicationEnumsProtoTranslator.translate(app.getRole()).get())
+ .withRole(ApplicationEnumsProtoTranslator.translate(app.getRole()).get())
.withPermissions(permissions)
.withFeatures(app.getFeaturesList())
.withFeaturesRepo(Optional.empty()) // TODO: need to add features repo
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/RegionProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/RegionProtoTranslator.java
index bd43c0b..7512ebf 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/RegionProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/RegionProtoTranslator.java
@@ -76,9 +76,8 @@
.stream()
.map(s -> RegionProtoOuterClass.RegionProto.NodeIdSet
.newBuilder()
- .addAllNodeId(s.stream().map(id -> {
- return id.toString();
- }).collect(Collectors.toList()))
+ .addAllNodeId(s.stream().map(id ->
+ id.toString()).collect(Collectors.toList()))
.build())
.collect(Collectors.toList()))
.build();
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/PortProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/PortProtoTranslator.java
index 046cedf..ff39987 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/PortProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/PortProtoTranslator.java
@@ -30,6 +30,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Optional;
+
/**
* gRPC message conversion related utilities for port service.
*/
@@ -46,7 +48,7 @@
public static PortDescription translate(PortDescriptionProto portDescription) {
PortNumber number = PortNumber.fromString(portDescription.getPortNumber());
boolean isEnabled = portDescription.getIsEnabled();
- Port.Type type = translate(portDescription.getType());
+ Port.Type type = translate(portDescription.getType()).get();
long portSpeed = portDescription.getPortSpeed();
SparseAnnotations annotations = AnnotationsTranslator.asAnnotations(portDescription.getAnnotationsMap());
// TODO How to deal with more specific Port...
@@ -77,27 +79,26 @@
* @param type gRPC message
* @return {@link Port.Type}
*/
- public static Port.Type translate(PortEnumsProto.PortTypeProto type) {
+ public static Optional<Port.Type> translate(PortEnumsProto.PortTypeProto type) {
switch (type) {
case COPPER:
- return Port.Type.COPPER;
+ return Optional.of(Port.Type.COPPER);
case FIBER:
- return Port.Type.FIBER;
+ return Optional.of(Port.Type.FIBER);
case OCH:
- return Port.Type.OCH;
+ return Optional.of(Port.Type.OCH);
case ODUCLT:
- return Port.Type.ODUCLT;
+ return Optional.of(Port.Type.ODUCLT);
case OMS:
- return Port.Type.OMS;
+ return Optional.of(Port.Type.OMS);
case PACKET:
- return Port.Type.PACKET;
+ return Optional.of(Port.Type.PACKET);
case VIRTUAL_PORT:
- return Port.Type.VIRTUAL;
+ return Optional.of(Port.Type.VIRTUAL);
- case UNRECOGNIZED:
default:
log.warn("Unexpected PortType: {}", type);
- return Port.Type.COPPER;
+ return Optional.empty();
}
}
@@ -126,7 +127,7 @@
default:
log.warn("Unexpected Port.Type: {}", type);
- return PortEnumsProto.PortTypeProto.COPPER;
+ return PortEnumsProto.PortTypeProto.UNRECOGNIZED;
}
}
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryEnumsProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryEnumsProtoTranslator.java
index 2c7d51e..f6c590b 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryEnumsProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryEnumsProtoTranslator.java
@@ -63,7 +63,7 @@
* @param flowEntryState gRPC message
* @return {@link FlowEntryState}
*/
- public static Optional<Object> translate(FlowEntryEnumsProto.FlowEntryStateProto flowEntryState) {
+ public static Optional<FlowEntryState> translate(FlowEntryEnumsProto.FlowEntryStateProto flowEntryState) {
switch (flowEntryState) {
case PENDING_ADD:
@@ -115,7 +115,7 @@
* @param flowLiveType gRPC message
* @return {@link FlowLiveType}
*/
- public static Optional<Object> translate(FlowEntryEnumsProto.FlowLiveTypeProto flowLiveType) {
+ public static Optional<FlowLiveType> translate(FlowEntryEnumsProto.FlowLiveTypeProto flowLiveType) {
switch (flowLiveType) {
case IMMEDIATE:
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryProtoTranslator.java
index dfbbdf8..80ec629 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryProtoTranslator.java
@@ -63,9 +63,9 @@
return null;
}
- FlowEntry.FlowEntryState state = (FlowEntry.FlowEntryState)
+ FlowEntry.FlowEntryState state =
FlowEntryEnumsProtoTranslator.translate(flowEntry.getState()).get();
- FlowEntry.FlowLiveType liveType = (FlowEntry.FlowLiveType)
+ FlowEntry.FlowLiveType liveType =
FlowEntryEnumsProtoTranslator.translate(flowEntry.getLiveType()).get();
// TODO: need to instantiate FlowRule later
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleEnumsProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleEnumsProtoTranslator.java
index dcb2038..12ddf29 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleEnumsProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleEnumsProtoTranslator.java
@@ -64,7 +64,7 @@
* @param flowRemoveReason gRPC message
* @return {@link FlowRemoveReason}
*/
- public static Optional<Object> translate(FlowRuleEnumsProto.FlowRemoveReasonProto flowRemoveReason) {
+ public static Optional<FlowRemoveReason> translate(FlowRuleEnumsProto.FlowRemoveReasonProto flowRemoveReason) {
switch (flowRemoveReason) {
case DELETE:
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleProtoTranslator.java
index 2babd83..76046e7 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleProtoTranslator.java
@@ -71,7 +71,7 @@
// TODO: to register AppId need to find a way to get CoreService
- FlowRule.FlowRemoveReason reason = (FlowRule.FlowRemoveReason)
+ FlowRule.FlowRemoveReason reason =
FlowRuleEnumsProtoTranslator.translate(flowRule.getReason()).get();
FlowRule.Builder resultBuilder = new DefaultFlowRule.Builder();
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandEnumsProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandEnumsProtoTranslator.java
index b607e1a..f0825fb 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandEnumsProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandEnumsProtoTranslator.java
@@ -35,7 +35,7 @@
* @param bandType BandType in gRPC enum
* @return equivalent in ONOS enum
*/
- public static Optional<Object> translate(BandEnumsProto.BandTypeProto bandType) {
+ public static Optional<Band.Type> translate(BandEnumsProto.BandTypeProto bandType) {
switch (bandType) {
case DROP:
return Optional.of(Band.Type.DROP);
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandProtoTranslator.java
index c5448f1..ba4460d 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandProtoTranslator.java
@@ -40,7 +40,7 @@
* @return {@link Band}
*/
public static Band translate(BandProto gBand) {
- Band.Type type = (Band.Type) BandEnumsProtoTranslator.translate(gBand.getType()).get();
+ Band.Type type = BandEnumsProtoTranslator.translate(gBand.getType()).get();
long rate = gBand.getRate();
long burstSize = gBand.getBurst();
short prec = (short) gBand.getDropPrecedence();
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterEnumsProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterEnumsProtoTranslator.java
index 6b7fb3e..b73117c 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterEnumsProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterEnumsProtoTranslator.java
@@ -36,7 +36,7 @@
* @param unit meterUnit in gRPC enum
* @return equivalent in ONOS enum
*/
- public static Optional<Object> translate(MeterEnumsProto.MeterUnitProto unit) {
+ public static Optional<Meter.Unit> translate(MeterEnumsProto.MeterUnitProto unit) {
switch (unit) {
case PKTS_PER_SEC:
return Optional.of(Meter.Unit.PKTS_PER_SEC);
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterRequestProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterRequestProtoTranslator.java
index e63f35e..dd6c5fb 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterRequestProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterRequestProtoTranslator.java
@@ -67,7 +67,7 @@
DeviceId deviceid = DeviceId.deviceId(meterRequest.getDeviceId());
ApplicationId appId = ApplicationIdProtoTranslator.translate(meterRequest.getApplicationId());
- Meter.Unit unit = (Meter.Unit) MeterEnumsProtoTranslator.translate(meterRequest.getUnit()).get();
+ Meter.Unit unit = MeterEnumsProtoTranslator.translate(meterRequest.getUnit()).get();
boolean burst = meterRequest.getIsBurst();
Collection<Band> bands = BandProtoTranslator.translate(meterRequest.getBandsList());
MeterRequest.Type type = (MeterRequest.Type) translate(meterRequest.getType()).get();