I have the following class, which is using a switch statement and I'd like to replace it with an enum.
public class FillTable {
private static final int NAME_INDEX = 0;
private static final int DESCRIPTION_INDEX = 1;
private static final int CONTRIBUTION_INDEX = 2;
public Object getValueAt(int row, int col) {
EmployeeData employeeData = (EmployeeData)items.get(row);
switch (col) {
case NAME_INDEX: {
return employeeData.getName();
}
case DESCRIPTION_INDEX: {
return employeeData.getDescription();
}
case ADDRESS_INDEX: {
return employeeData.getAddress();
}
default: {
return "";
}
}
}
}
Here is the enum that I've come up with.
public enum EmployeeTableColumn {
NAME_INDEX {
@Override
public void getData() {
employeeData.getName();
}
}, DESCRIPTION_INDEX {
@Override
public void getData() {
return employeeData.getDescription();
}
}, CONTRIBUTION_INDEX {
@Override
public void getData() {
return employeeData.getAddress();
}
};
public abstract void getData();
}
My problem is that I don't know how to replace the code in the getValueAt()
method to make use of the enum in place of the switch statement. Can someone please show me how I can do this?