Based on the string "key", I want to get the latest and previous values assigned without using the Switch case. I need some mapper method that it get the key value as input and map the values for different Data objects and return a list of latest and previous values without using the switch case. Please someone help on this.
switch(key) {
case "pValue" :
latestPValue = getLatestData().getPValue();
previousPValue = getPreviousData().getPValue();
break;
case "aValue" :
latestAValue = getLatestData().getAValue();
previousAValue = getPreviousData().getAValue();
break;
case "tValue" :
latestTValue = getLatestData().getTValue();
previousTValue = getPreviousData().getTValue();
break;
default:
break;
}
public class Data {
public String aValue;
public String pValue;
public String tValue;
---- Constructors, getters and setters---
}
public class MainClass {
public static void main(String args[]) {
Data latestData = new Data("1","2","3");
Data previousData = new Data("4","5","6");
}