I defined many data classes as needed for the operation, eg. DataForMSDForAdvanceReqeust
. Each data class is like below:
@Data
class DataForMSDForAdvanceReqeust implements Serializable {
private final String id;
private final String advanceRequestValue;
private final String advanceRequestShowText;
public DataForMSDForAdvanceReqeust(String id, String advanceRequestValue, String advanceRequestShowText) {
this.id = id;
this.advanceRequestValue = advanceRequestValue;
this.advanceRequestShowText = advanceRequestShowText;
}
}
Then in the following functionfetchDataMSDForAdvanceRequest
, I will be using this above DataForMSDForAdvanceReqeust
in creating return values like
List<DataForMSDForAdvanceReqeust> result = new ArrayList<>();
and somewhere else in the following code:
@ResponseBody
@RequestMapping(value = "/fetchDataMSDForAdvanceRequest", method = RequestMethod.POST)
public List<DataForMSDForAdvanceReqeust> fetchDataMSDForAdvanceRequest(
@RequestBody @NonNull MasterSearchRequestParam param) {
SearchFilterForAdvanceRequestVo searchFilter = SearchFilterForAdvanceRequestVo.of(new HashMap<>());
List<MasterSearchSimpleResult> tmp = new ArrayList<>();
tmp = availableAdvanceRequestSearchService.dbsearch(true, searchFilter);
List<DataForMSDForAdvanceReqeust> result = new ArrayList<>();
int count = 0;
String inputString = param.getInputKeyword();
if (inputString.length() != 0) {
for (MasterSearchSimpleResult searchR : tmp) {
if (searchR.getShowText().contains(inputString)) {
result.add(new DataForMSDForAdvanceReqeust(Integer.toString(++count), searchR.getValue(), searchR
.getShowText()));
}
}
} else {
for (MasterSearchSimpleResult searchR : tmp) {
result.add(new DataForMSDForAdvanceReqeust(Integer.toString(++count), searchR.getValue(), searchR
.getShowText()));
}
}
return result;
}
I want to seperate this part of code out, as for many other fetch data function similiar to fetchDataMSDForAdvanceRequest
above, the below part is almost identical, except the return type is different:
List<DataForMSDForAdvanceReqeust> result = new ArrayList<>();
int count = 0;
String inputString = param.getInputKeyword();
if (inputString.length() != 0) {
for (MasterSearchSimpleResult searchR : tmp) {
if (searchR.getShowText().contains(inputString)) {
result.add(new DataForMSDForAdvanceReqeust(Integer.toString(++count), searchR.getValue(), searchR
.getShowText()));
}
}
} else {
for (MasterSearchSimpleResult searchR : tmp) {
result.add(new DataForMSDForAdvanceReqeust(Integer.toString(++count), searchR.getValue(), searchR
.getShowText()));
}
}
return result;
I want to write a function that will takes DataForMSDForAdvanceReqeust
as the parameter, as there are many different @Data classes available. It looks like a Generic class, but I am not sure how to carry it out if using that. I am also looking for other methods, if possible.
Do you have any idea about passing a data class as the parameter of another function?