Skip to content

Commit

Permalink
Adds fromValue method to EntityType
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 4, 2024
1 parent 4107407 commit 274c64f
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

package org.opensearch.accesscontrol.resources;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* This enum contains the type of entities a resource can be shared with.
*
Expand All @@ -19,6 +24,9 @@ public enum EntityType {
ROLES("roles"),
BACKEND_ROLES("backend_roles");

private static final Map<String, EntityType> VALUE_MAP = Arrays.stream(values())
.collect(Collectors.toMap(EntityType::toString, Function.identity()));

private final String value;

EntityType(String value) {
Expand All @@ -29,4 +37,12 @@ public enum EntityType {
public String toString() {
return value;
}

public static EntityType fromValue(String value) {
EntityType type = VALUE_MAP.get(value);
if (type == null) {
throw new IllegalArgumentException("No enum constant with value: " + value);
}
return type;
}
}

0 comments on commit 274c64f

Please sign in to comment.