A simple permission matrix maps a role to the actions that role can perform.

role mapping The role decides which action list flows to the rest of the program.
derived permission The delete flag is derived from the action list, keeping the final check visible.

Permission Matrix

role
PermissionMatrix.java
Replay: real traced execution (multi-file project)
public class PermissionMatrix {
    static String actionsFor(String role) {
        if (role.equals("viewer")) {
            return "read";
        }

        if (role.equals("editor")) {
            return "read,write";
        }

        return "read,write,delete";
    }

    public static void main(String[] args) {
        String role = "editor";
        String actions = actionsFor(role);
        boolean canDelete = actions.contains("delete");

        System.out.println("role=" + role);
        System.out.println("actions=" + actions);
        System.out.println("delete=" + canDelete);
    }
}
public class PermissionMatrix {
    static String actionsFor(String role) {
        if (role.equals("viewer")) {
            return "read";
        }

        if (role.equals("editor")) {
            return "read,write";
        }

        return "read,write,delete";
    }

    public static void main(String[] args) {
        String role = "viewer";
        String actions = actionsFor(role);
        boolean canDelete = actions.contains("delete");

        System.out.println("role=" + role);
        System.out.println("actions=" + actions);
        System.out.println("delete=" + canDelete);
    }
}
public class PermissionMatrix {
    static String actionsFor(String role) {
        if (role.equals("viewer")) {
            return "read";
        }

        if (role.equals("editor")) {
            return "read,write";
        }

        return "read,write,delete";
    }

    public static void main(String[] args) {
        String role = "admin";
        String actions = actionsFor(role);
        boolean canDelete = actions.contains("delete");

        System.out.println("role=" + role);
        System.out.println("actions=" + actions);
        System.out.println("delete=" + canDelete);
    }
}
  1. role ← editor

    14public static void main(String[] args) {15    String role→ editor = "editor";  //@role="viewer", "admin"16    String actions = actionsFor(roleeditor);17    boolean canDelete = actions.contains("delete");
  2. static String actionsFor(String role)

    1public class PermissionMatrix {2    static String actionsFor(String roleeditor) {3        if (role.equals("viewer")) {
  3. actions ← read,write, canDelete ← false

    15    String role = "editor";  //@role="viewer", "admin"16    String actions→ read,write = actionsFor(roleeditor);17    boolean canDelete→ false = actions.contains("delete");1819    System.out.println("role=" + roleeditor);20    System.out.println("actions=" + actionsread,write);21    System.out.println("delete=" + canDeletefalse);22}
    outputrole=editor
    actions=read,write
    delete=false
  1. role ← viewer

    14public static void main(String[] args) {15    String role→ viewer = "viewer";16    String actions = actionsFor(roleviewer);17    boolean canDelete = actions.contains("delete");
  2. static String actionsFor(String role)

    1public class PermissionMatrix {2    static String actionsFor(String roleviewer) {3        if (role.equals("viewer")) {
  3. actions ← read, canDelete ← false

    15    String role = "viewer";16    String actions→ read = actionsFor(roleviewer);17    boolean canDelete→ false = actions.contains("delete");1819    System.out.println("role=" + roleviewer);20    System.out.println("actions=" + actionsread);21    System.out.println("delete=" + canDeletefalse);22}
    outputrole=viewer
    actions=read
    delete=false
  1. role ← admin

    14public static void main(String[] args) {15    String role→ admin = "admin";16    String actions = actionsFor(roleadmin);17    boolean canDelete = actions.contains("delete");
  2. static String actionsFor(String role)

    1public class PermissionMatrix {2    static String actionsFor(String roleadmin) {3        if (role.equals("viewer")) {4            return "read";5        }67        if (role.equals("editor")) {8            return "read,write";9        }1011        return "read,write,delete";12    }
  3. actions ← read,write,delete, canDelete ← true

    15    String role = "admin";16    String actions→ read,write,delete = actionsFor(roleadmin);17    boolean canDelete→ true = actions.contains("delete");1819    System.out.println("role=" + roleadmin);20    System.out.println("actions=" + actionsread,write,delete);21    System.out.println("delete=" + canDeletetrue);22}
    outputrole=admin
    actions=read,write,delete
    delete=true