package com.codingchili.core.protocol;

import com.codingchili.core.configuration.CoreStrings;

import java.util.HashMap;
import java.util.Map;

/**
 * Add custom roles to the rolemap, must be done before initializing protocols.
 * By mapping the name of the role to an instance annotations are no longer
 * limited to the default roles in #{@link Role}.
 */
public class RoleMap {
    public static final String ADMIN = "admin";
    public static final String USER = "user";
    public static final String PUBLIC = "public";
    public static final String UNSET = "unset";
    private static Map<String, RoleType> roleMap = new HashMap<>();

    static {
        put(ADMIN, Role.ADMIN);
        put(USER, Role.USER);
        put(PUBLIC, Role.PUBLIC);
    }

    public static void put(String role, RoleType type) {
        roleMap.put(role, type);
    }

    public static RoleType get(String role) {
        if (!roleMap.containsKey(role)) {
            throw new RuntimeException(CoreStrings.getMissingRole(role));
        } else {
            return roleMap.get(role);
        }
    }

    public static RoleType[] get(String[] roles) {
        RoleType[] list = new RoleType[roles.length];
        for (int i = 0; i < roles.length; i++) {
            list[i] = get(roles[i]);
        }
        return list;
    }
}

@@ -769,32 +769,174 @@
 LIC);%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A     * Adds a role mapping.%0D%0A     *%0D%0A     * @param name the name of the role.%0D%0A     * @param role the role implementation.%0D%0A     */%0D%0A
     public stati
@@ -953,19 +953,19 @@
 (String 
-rol
+nam
 e, RoleT
@@ -968,19 +968,19 @@
 oleType 
-typ
+rol
 e) %7B%0D%0A  
@@ -1001,29 +1001,269 @@
 put(
-role, type);
+name, role);%0D%0A    %7D%0D%0A%0D%0A    /**%0D%0A     * retrieves a role by its name.%0D%0A     *%0D%0A     * @param name the name of the role to retrieve.%0D%0A     * @return a registered role that matches the given name, throws an
 %0D%0A    
+ 
-%7D%0D%0A
+* exception if the role is not registered.%0D%0A     */
 %0D%0A  
@@ -1298,19 +1298,19 @@
 (String 
-rol
+nam
 e) %7B%0D%0A  
@@ -1340,19 +1340,19 @@
 ainsKey(
-rol
+nam
 e)) %7B%0D%0A 
@@ -1416,19 +1416,19 @@
 ingRole(
-rol
+nam
 e));%0D%0A  
@@ -1474,19 +1474,19 @@
 Map.get(
-rol
+nam
 e);%0D%0A   
@@ -1498,24 +1498,260 @@
 %7D%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A     * @param names multiple names to retrieve the roles for.%0D%0A     * @return a list of roles that matches the given list.%0D%0A     * Throws an exception if any of the roles in the given names%0D%0A     * is not registered.%0D%0A     */%0D%0A
     public s
@@ -1781,14 +1781,15 @@
 ring
-%5B%5D rol
+... nam
 es) 
@@ -1830,19 +1830,19 @@
 oleType%5B
-rol
+nam
 es.lengt
@@ -1874,19 +1874,19 @@
  0; i %3C 
-rol
+nam
 es.lengt
@@ -1922,19 +1922,19 @@
 %5D = get(
-rol
+nam
 es%5Bi%5D);%0D

Add javadoc to the RoleMap