@@ -0,0 +1,2078 @@
+package ml.alternet.util;%0A%0Aimport java.lang.reflect.Field;%0Aimport java.security.AccessController;%0Aimport java.security.PrivilegedAction;%0Aimport java.util.function.UnaryOperator;%0Aimport java.util.logging.Logger;%0A%0Aimport ml.alternet.misc.Thrower;%0A%0A/**%0A * Enum-related utilities.%0A *%0A * @author Philippe Poulard%0A */%0A@Util%0Apublic class EnumUtil %7B%0A%0A    /**%0A     * Replace the value of an enum instance by another value.%0A     *%0A     * Helpful for enum values that are made of characters that%0A     * are not Java names.%0A     *%0A     * %3Ch3%3EExample%3C/h3%3E%0A     * An enum type made of values that contains a space.%0A     *%0A     * %3Cpre%3Epublic enum MyEnum %7B%0A     *    VALUE_1,%0A     *    VALUE_2,%0A     *    VALUE_3;%0A     *%0A     *    MyEnum() %7B%0A     *        // replace the %22_%22 in the name by a %22 %22%0A     *       EnumUtil.replace(MyEnum.class, this, s -%3E s.replace('_', ' '));%0A     *    %7D%0A     *%7D%3C/pre%3E%0A     * Usage :%0A     * %3Cpre%3E MyEnum val = MyEnum.valueOf(%22VALUE 2%22);%3C/pre%3E%0A     *%0A     * @param enumClass The enum class to patch%0A     * @param enumValue The instance to change%0A     * @param transformer Apply a transformation on the name of the instance%0A     */%0A    public static void replace(Class%3C? extends Enum%3C?%3E%3E enumClass, Object enumValue, UnaryOperator%3CString%3E transformer) %7B%0A        try %7B%0A            Field fieldName = enumClass.getSuperclass().getDeclaredField(%22name%22);%0A            AccessController.doPrivileged((PrivilegedAction%3CVoid%3E) (() -%3E %7B%0A                fieldName.setAccessible(true);%0A                return null;%0A            %7D));%0A            String value = (String) fieldName.get(enumValue);%0A            value = transformer.apply(value);%0A            fieldName.set(enumValue, value);%0A            AccessController.doPrivileged((PrivilegedAction%3CVoid%3E) (() -%3E %7B%0A                fieldName.setAccessible(false);%0A                return null;%0A            %7D));%0A        %7D catch (Exception e) %7B%0A            Logger.getLogger(enumClass.getName())%0A            .severe(%22Unable to access to %5C%22name%5C%22 field of class %22 + enumClass.getName());%0A            Thrower.doThrow(e);%0A        %7D%0A    %7D%0A%0A%7D%0A

Add replacement facility of enum values