public static List<VaccineOfFactory> getFactoryData(List<VaccineInfo> data) {
if (data == null || data.size() == 0)
return null;
List<VaccineOfFactory> resultList = new ArrayList<>();
for (VaccineInfo vaccineInfo : data) {
int factoryIndex = getFactoryCnNameIndex(resultList, vaccineInfo);
if (factoryIndex != -1) {
int goodsCnNameIndex = getGoodsCnNameIndex(resultList.get(factoryIndex).getData()
, vaccineInfo);
if (goodsCnNameIndex != -1) {
resultList.get(factoryIndex).getData().get(goodsCnNameIndex).getVaccineInfoList().add(vaccineInfo);
} else {
VaccineOfName vaccineOfName = new VaccineOfName();
vaccineOfName.setGoodsCnName(vaccineInfo.getGoodsCnName());
vaccineOfName.setVaccineInfo(vaccineInfo);
resultList.get(factoryIndex).getData().add(vaccineOfName);
}
} else {
VaccineOfName vaccineOfName = new VaccineOfName();
vaccineOfName.setGoodsCnName(vaccineInfo.getGoodsCnName());
vaccineOfName.setVaccineInfo(vaccineInfo);
resultList.add(new VaccineOfFactory(vaccineInfo.getFactoryCnName(), vaccineOfName
, vaccineInfo.getInputType()));
}
}
return resultList;
}
private static int getFactoryCnNameIndex(List<VaccineOfFactory> factories,
VaccineInfo vaccineInfo) {
if (factories == null || factories.size() == 0 || vaccineInfo == null)
return -1;
for (int i = 0; i < factories.size(); i++) {
if (vaccineInfo.getFactoryCnName().equals(factories.get(i).getFactoryCnName()))
return i;
}
return -1;
}
private static int getGoodsCnNameIndex(List<VaccineOfName> vaccineOfNames,
VaccineInfo vaccineInfo) {
if (vaccineOfNames == null || vaccineOfNames.size() == 0 || vaccineInfo == null)
return -1;
for (int i = 0; i < vaccineOfNames.size(); i++) {
if (vaccineInfo.getGoodsCnName().equals(vaccineOfNames.get(i).getGoodsCnName()))
return i;
}
return -1;
}
|