package com.koenv.jsonapi.users.voters;

import com.koenv.jsonapi.users.model.PermissionType;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class VoterUtils {
    public static VoterResponse canAccess(PermissionType type, List<String> types, String check) {
        switch (type) {
            case BLACKLIST:
                if (types.contains(check)) {
                    return VoterResponse.DENIED;
                } else {
                    return VoterResponse.ALLOWED;
                }
            case WHITELIST:
                if (types.contains(check)) {
                    return VoterResponse.ALLOWED;
                } else {
                    return VoterResponse.DENIED;
                }
            default:
                return VoterResponse.NEUTRAL;
        }
    }

    public static boolean isUnanimous(Stream<VoterResponse> responses) {
        List<VoterResponse> matchedResponses = responses
                .filter(voterResponse -> voterResponse != VoterResponse.NEUTRAL)
                .collect(Collectors.toList());

        if (matchedResponses.size() == 0) {
            return false; // allMatch returns true if the list is empty, which is something we don't want
        }

        return matchedResponses.stream().allMatch(voterResponse -> {
            System.out.println("Response: " + voterResponse.name());
            return voterResponse == VoterResponse.ALLOWED;
        });
    }
}

@@ -1336,77 +1336,8 @@
 %3E %7B%0A
-            System.out.println(%22Response: %22 + voterResponse.name());%0A
     

Remove some logging