Question: We are persisting an object in the database, But before there are few conditions that need to be checked I am using if-else to perform these what is the best way to eliminate if-else statements. We are also setting response object which a map in each and every statement.

Also, in future we have to check for other conditions before creating or updating.

```
Callable<Response> callableObj = () -> {
    if(isNew){
    if(checkCreatePermission()){
       if(checkDuplicate()) {
          return foundObejct();
       } else {
           persistNewObject();
       }
    } else {
        throw new Exception();
    }
} else {
    if(checkUpdatePermission()){
        udapteObject();
    } else {
        throw new Exception();
    }

}
};

```

Answer: 
You could use some early returns/throws. Makes the code a little more readable.

```
if(isNew){
    if(!checkCreatePermission()){
        throw new Exception();
    }
    if (checkDuplicate()) {
       return foundObejct();
    }
    persistNewObject();
} else {
    if(!checkUpdatePermission()){
        throw new Exception();
    }
    udapteObject();

}

```
I would suggest to split it down in few methods. Not sure if I got what do you need, but it could be something like

```java
    createOrUpdate() {
        if(isNew()){
            create();
        } else {
            update();
        }
    }

    create() {
        if(checkCreatePermission()){
            if(checkDuplicate()) {
                return foundObejct();
            } else {
                persistNewObject();
            }
        } else {
            throw new Exception();
        }
    }

    update() {
        if(checkCreatePermission()){
            udapteObject();
        } else {
            throw new Exception();
        }
    }

```