mercredi 6 janvier 2016

Complex if/else logic in java with multiple variables [on hold]

There can be two types of groups- private and public. Each group can have members in it. I have three parameters id, includePrivate, includePublic to be passed into a method to return the groups as per the rules below. For eg.

public List<Group> getListofGroups(String id, Boolean isPrivate, Boolean   isPublic){}

  1. All groups {}
  2. all private groups {"includePrivate": true}
  3. all public groups {"includePublic": true}
  4. all private groups with membership {"id":"id1", "includePrivate": true }
  5. all private groups with membership + all public groups {"id":"id1", "includePrivate": true, "includePublic": true }

What is the best way to implement this complex if/else logic? Is it a good option to create a rules engine just for this api?

 For eg. if(isPrivate && isPublic && id=!null) {
    return publicAndPrivateWIthMembership();
} else if(isPrivate && id=!null ) {
    return privateGroupsWithMembership();
} else if((isPublic && !isPrivate) ||(isPublic && isPrivate == null) ) {
    return allPublicGroups();
} else if((isPrivate && !isPublic) ||(isPrivate && isPublic == null) ) {
    return allPrivateGroups();
}........

Aucun commentaire:

Enregistrer un commentaire