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

yescobar01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

girionisCommented:
I don't quite understand what you're trying to achieve. But if you also want to return the CosModel from the mapDirectionToTrafficProfileDirection method then you could add a new wrapper class for both Direction and CosModel. Something along the lines

public class DirectionAndModel {
	private Direction direction;
	private CosModel model;
	
	public DirectionAndModel(Direction direction, CosModel model) {
		super();
		this.direction = direction;
		this.model = model;
	}
	
	public Direction getDirection() {
		return direction;
	}

	public CosModel getModel() {
		return model;
	}
}


private DirectionAndModel mapDirectionToTrafficProfileDirection (Direction direction, CosModel cosModel){

		if (direction == Direction.OUT){
			return new DirectionAndModel(TrafficProfileExtension.Direction.Egress, cosModel);
		}
		if (direction == Direction.IN){
			return new DirectionAndModel(TrafficProfileExtension.Direction.Ingress, cosModel);
		}
		return null;
	}

Open in new window


Something like this?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.