Skip to main content
added 62 characters in body
Source Link
default locale
  • 468
  • 1
  • 4
  • 13

If you want to create an object from Excel row you can change the method's signature to accept an array of values:

private WHTApps createModelFromValues(Object[] values) {
    WHTApps whtApp = new WHTApps();
    whtApp.setVendorCode((int) values[0]);
    whtApp.setVendorName((String) values[1]);
    ....
    whtApp.setCategory((String) values[17]);
    return whtApp;
}

This method is not as complex as the first one and is easier to test. Client code will have to populate an array of values to pass.

You should consider adding some kind of error checking: validate values array before processing it. Check for length and data type errors. You can create a custom exception class that will clearly show where the problem is.

Probably, you can make this code more flexible by adding a separate mapper class that will set properties using reflection. I'm not sure if it's worth the effort in this particular case, though.

If you want to create an object from Excel row you can change the method's signature to accept an array of values:

private WHTApps createModelFromValues(Object[] values) {
    WHTApps whtApp = new WHTApps();
    whtApp.setVendorCode((int) values[0]);
    whtApp.setVendorName((String) values[1]);
    ....
    whtApp.setCategory((String) values[17]);
    return whtApp;
}

This method is not as complex as the first one and is easier to test.

You should consider adding some kind of error checking: validate values array before processing it. Check for length and data type errors. You can create a custom exception class that will clearly show where the problem is.

Probably, you can make this code more flexible by adding a separate mapper class that will set properties using reflection. I'm not sure if it's worth the effort in this particular case, though.

If you want to create an object from Excel row you can change the method's signature to accept an array of values:

private WHTApps createModelFromValues(Object[] values) {
    WHTApps whtApp = new WHTApps();
    whtApp.setVendorCode((int) values[0]);
    whtApp.setVendorName((String) values[1]);
    ....
    whtApp.setCategory((String) values[17]);
    return whtApp;
}

This method is not as complex as the first one and is easier to test. Client code will have to populate an array of values to pass.

You should consider adding some kind of error checking: validate values array before processing it. Check for length and data type errors. You can create a custom exception class that will clearly show where the problem is.

Probably, you can make this code more flexible by adding a separate mapper class that will set properties using reflection. I'm not sure if it's worth the effort in this particular case, though.

Source Link
default locale
  • 468
  • 1
  • 4
  • 13

If you want to create an object from Excel row you can change the method's signature to accept an array of values:

private WHTApps createModelFromValues(Object[] values) {
    WHTApps whtApp = new WHTApps();
    whtApp.setVendorCode((int) values[0]);
    whtApp.setVendorName((String) values[1]);
    ....
    whtApp.setCategory((String) values[17]);
    return whtApp;
}

This method is not as complex as the first one and is easier to test.

You should consider adding some kind of error checking: validate values array before processing it. Check for length and data type errors. You can create a custom exception class that will clearly show where the problem is.

Probably, you can make this code more flexible by adding a separate mapper class that will set properties using reflection. I'm not sure if it's worth the effort in this particular case, though.