I need to modify the 3rd method mapDirectionToTrafficProfileDirection() to display Both. Direction class is an enum class and just has IN and OUT.
public enum Direction {
IN,
OUT;
and TrafficProfileExtension class also has enum for Direction Egress, Ingress, Both;
public class TrafficProfileExtension {
private TrafficProfile entity;
public static enum Direction {
Egress, Ingress, Both;
}
I need to modify the 3rd method to dislay Both is there a way I can add it without changing/adding a new enum in Direction class?
private TrafficProfileExtension.Direction mapDirectionToTrafficProfileDirection (Direction direction){
if (Direction.OUT.equals(direction)){
return TrafficProfileExtension.Direction.Egress;
}
if (Direction.IN.equals(direction)){
return TrafficProfileExtension.Direction.Ingress;
}
if (Direction. ?? .equals(direction)){
return TrafficProfileExtension.Direction.Both;
}
return null;
}
}
We have this method in our code and they were able to add the enum without changing the enum in Direction class.
Example method below:
private List<Direction> mapTrafficProfileDirection (TrafficProfileExtension.Direction direction) throws Exception {
List<Direction> directionList = new ArrayList<Direction>();
if (TrafficProfileExtension.Direction.Egress.equals(direction)){
directionList.add(Direction.OUT);
return directionList;
}
if (TrafficProfileExtension.Direction.Ingress.equals(direction)){
directionList.add(Direction.IN);
return directionList;
}
if (TrafficProfileExtension.Direction.Both.equals(direction)){
directionList.add(Direction.OUT);
directionList.add(Direction.IN);
return directionList;
}
throw new Exception("Illegal direction passed through method " + direction.name());
}
Directionis only used by objects that require just IN and OUT, and you just want to convert it into the second type, then you translate what you have. I'd say the problem would be translating the reverse.