yescobar01
asked on
How can I modify my java method to also display cosModel without modifying the enums?
Hello, I need help writing my method mapDirectionToTrafficProfi leDirectio n() I need to add CosModel to my method, I cannot change the enum values, so that's out of the question. Cos6 will always be Both for Direction. Cos4 has in and out or Egress and Ingress. How can I modify my code mapDirectionToTrafficProfi leDirectio n() to do this?
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:
public class TrafficProfileExtension {
public static enum Direction {
Egress, Ingress, Both;
}
public static enum CosModel {
cos6,cos4;
}
public enum Direction
implements EnumValue<String>
{
IN,
OUT;
}
@XmlType(name = "CosModel")
@XmlEnum
public enum CosModel implements EnumValue<String>
{
COS_4("Cos4"),
@XmlEnumValue("Cos6")
COS_6("Cos6"),
}
private TrafficProfileExtension.Direction mapDirectionToTrafficProfileDirection (Direction direction, CosModel cosModel){
if (Direction.OUT.equals(direction)){
return TrafficProfileExtension.Direction.Egress;
}
if (Direction.IN.equals(direction)){
return TrafficProfileExtension.Direction.Ingress;
}
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());
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.