package xxx;
import org.junit.jupiter.api.Test;
import java.util.EnumMap;
import java.util.Map;
import java.util.function.Function;
public class MapDriveTest {
Map<UserTypeEnum, Function<String, String>> planMapper = new EnumMap<>(UserTypeEnum.class);
public MapDriveTest() {
planMapper.put(UserTypeEnum.LIVE_USER, input -> {
return "live user " + input;
});
planMapper.put(UserTypeEnum.STABLE_USER, input -> {
return "stable user " + input;
});
}
@Test
public void mapDriveTest() {
System.out.println(planMapper.get(UserTypeEnum.LIVE_USER).apply("dance"));
System.out.println(planMapper.get(UserTypeEnum.LIVE_USER).apply("sing"));
System.out.println(planMapper.get(UserTypeEnum.STABLE_USER).apply("code"));
System.out.println(planMapper.get(UserTypeEnum.STABLE_USER).apply("play"));
}
public enum UserTypeEnum {
LIVE_USER("live_user"),
STABLE_USER("stable_user");
private final String value;
UserTypeEnum(String value) {
this.value = value;
}
public String getValue(){
return value;
}
public String toString() {
return String.valueOf(value);
}
public static UserTypeEnum fromValue(String value) {
if( value == null ){
return null;
}
for (UserTypeEnum typeEnum : UserTypeEnum.values()) {
if (typeEnum.value.equals(value)) {
return typeEnum;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}
}
}