我需要简化以下Java代码。有什么方法可以使用set并做到这一点?

      if (!(((AdministrativeState.PLANNED == dispensingOccasionModel.getOccasionDTO().getAdminState()) ||
             (AdministrativeState.MISSED == dispensingOccasionModel.getOccasionDTO().getAdminState()) ||
             (AdministrativeState.SKIPPED == dispensingOccasionModel.getOccasionDTO().getAdminState()) ||
             (AdministrativeState.SELF_ADMINISTERED == dispensingOccasionModel.getOccasionDTO().getAdminState()) ||
(AdministrativeState.SELF_ADMINISTERED_BY_RANGE == dispensingOccasionModel.getOccasionDTO().getAdminState())) &&
        isSpecialDoseType(doseDetail))

最佳答案

使用Set,您可以初始化有效的枚举类型,并在@shmosel中执行包含,如注释中所指出:

Set<AdministrativeState> administrativeStates = Set.of(PLANNED, MISSED, SKIPPED, SELF_ADMINISTERED, SELF_ADMINISTERED_BY_RANGE)
if (!administrativeStates.contains(dispensingOccasionModel.getOccasionDTO().getAdminState())
        || !isSpecialDoseType(doseDetail))

07-24 21:47