我需要根据声纳可接受的水平降低以下java方法的复杂性。现在,它发出了类似声纳的问题。
需要一些专家帮助。
public List<X> Y(final DateTime treatmentDiscontinueTime,
final List< P> validPrescribedPrescriptions)
{
final List<x> doseWrapperList = new ArrayList<>();
final int noOfPrescriptions = validPrescribedPrescriptions.size();
for (int prescriptionIndex = 0; prescriptionIndex < noOfPrescriptions; prescriptionIndex++)
{
final BasePrescribedPrescription basePrescribedPrescription = validPrescribedPrescriptions.get(prescriptionIndex);
final String firstDoseText = basePrescribedPrescription.getFirstText();
final String secondDoseText = basePrescribedPrescription.getSecondText();
final boolean accordingToSchedule = A.ACCORDING.equals(firstDoseText);
final boolean specificPrescription = A.SP.equals(firstDoseText);
final boolean specificVbTypePrescription = A.SPVB.equals(firstDoseText);
List<D> doseDetails = new ArrayList<>(basePrescribedPrescription.getDoseDetails());
final DateTime changedDosageEndDate =
getChangedDoseEndDate(basePrescribedPrescription.getActualTerminateDate(), treatmentDiscontinueTime);
final int noOfDosages = doseDetails.size();
for (int doseIndex = 0; doseIndex < noOfDosages; doseIndex++)
{
final D doseDetail = doseDetails.get(doseIndex);
if ((doseDetail.getStart().getStartDate() != null) && (changedDosageEndDate != null) &&
doseDetail.getStart().getStartDate().isAfter(changedDosageEndDate))
{
continue;
}
String previewDoseText;
if (accordingToSchedule)
{
previewDoseText = X
}
else if (specificPrescription)
{
previewDoseText = Y;
}
else if (specificVbTypePrescription)
{
previewDoseText = Z;
}
else if (noOfDosages == 2)
{
previewDoseText = ((doseIndex == 0) ? secondDoseText : firstDoseText);
}
else
{
previewDoseText = firstDoseText;
}
final boolean isUnplanned =isuNplaned()
if (!isUnplanned)
{
doseStart = getStartDate();
doseEnd = getEndDate();
}
doseWrapperList.add(new DoseInfoLiteDTOWrapper(previewDoseText, doseStart, doseEnd, doseDetail));
}
}
return doseWrapperList;
}
我需要一些专家帮助来解决此声纳问题。我采用了不同的方法来提取代码片段,将这种方法分解为很少的部分。但是仍然找不到合适的方法来实现它。
答案 0 :(得分:1)
我认为不难清除:
提示:研究TDD以尽可能编写简洁的代码