mardi 3 janvier 2017

How can we optimize the following code for If Else Optimization in Java?

Can anyone please help to optimize this code to reduce no of if_else statement Switch Case not possible here as Sonar is showing major defects and NpathComplexity.

if (status != null) {
            if (MDOConstants.DOCREATED.equalsIgnoreCase(status)) {
                return null;
            } else if (MDOConstants.INPROGRESS.equalsIgnoreCase(status)
                    && MDOConstants.MDO_Stored.equalsIgnoreCase(subStatus)) {
                return MDOConstants.INPROGRESS;
            } else if (MDOConstants.INPROGRESS.equalsIgnoreCase(status)
                     && MDOConstants.GCSS_SUBMITTED.equalsIgnoreCase(subStatus)) {
                return MDOConstants.INPROGRESS;
            } else if (MDOConstants.INPROGRESS.equalsIgnoreCase(status)
                     && MDOConstants.PENDING_TASKS.equalsIgnoreCase(subStatus)) {
                return MDOConstants.INPROGRESS;
            } else if (MDOConstants.INPROGRESS.equalsIgnoreCase(status)
                     && MDOConstants.ISSUANCE_OK.equalsIgnoreCase(subStatus)) {
                return MDOConstants.INPROGRESS;
            } else if (MDOConstants.INPROGRESS.equalsIgnoreCase(status)
                    && MDOConstants.GCSS_REQUESTED.equalsIgnoreCase(subStatus)) {
                return MDOConstants.ISSUANCE_REQUESTED;
            } else if (MDOConstants.INPROGRESS.equalsIgnoreCase(status)
                     && MDOConstants.GCSS_ISSUED.equalsIgnoreCase(subStatus)) {
                return MDOConstants.ISSUANCE_REQUESTED;
            } else if (MDOConstants.INPROGRESS.equalsIgnoreCase(status)
                     && MDOConstants.DEADLINE_PASSED.equalsIgnoreCase(subStatus)) {
                return MDOConstants.INPROGRESS;
            } else if (MDOConstants.INPROGRESS.equalsIgnoreCase(status)
                     && MDOConstants.DEADLINE_PASSED_OR_NEW_PICKUPDATE_NEEDED.equalsIgnoreCase(subStatus)) {
                return MDOConstants.INPROGRESS;
            } else if (MDOConstants.MNLHNDLD.equalsIgnoreCase(status)
                    && MDOConstants.MNLHNDLD_TECHNICAL.equalsIgnoreCase(subStatus)) {
                return MDOConstants.MNLHNDLD;
            } else if (MDOConstants.MNLHNDLD.equalsIgnoreCase(status)
                     && MDOConstants.MNLHNDLD_OUTSIDE_MDO.equalsIgnoreCase(subStatus)) {
                return MDOConstants.MNLHNDLD;
            } else if (MDOConstants.DOISSUED.equalsIgnoreCase(status)) {
                return MDOConstants.DOISSUED;
            }
        }

Aucun commentaire:

Enregistrer un commentaire