Link to home
Start Free TrialLog in
Avatar of yescobar01
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 mapDirectionToTrafficProfileDirection() 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  mapDirectionToTrafficProfileDirection() to do this?

public class TrafficProfileExtension {
	public static enum Direction {
		Egress, Ingress, Both;
	}
	public static enum CosModel {
		cos6,cos4;
	}

Open in new window

public enum Direction
    implements EnumValue<String>
{
    IN,
    OUT;
	}

Open in new window

     
@XmlType(name = "CosModel")
@XmlEnum
public enum CosModel implements EnumValue<String>
{
    COS_4("Cos4"),
    @XmlEnumValue("Cos6")
    COS_6("Cos6"),
	}

Open in new window


      
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;
	}

Open in new window



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());

}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial