mil.dod.th.ose.jaxb.proto.converter/src/mil/dod/th/ose/jaxbprotoconverter/EnumConverterFileGenerator.java
public void genEnumConverterFile(final ProtoEnum enumeration, final PrintStream outStream,
        final String protoClassName, final String protoPackageName, final String enumConvertersPackageName)
    {
        final String converterClassName = String.format("%sConverter", enumeration.getType().getSimpleName());

        final String enumClassName = String.format("%s.%s.%s", protoPackageName, protoClassName, 
                enumeration.getType().getSimpleName().replace(ProtoEnum.ENUM, PACKAGE_SEPARATOR) 
                + enumeration.getName());

        // Store converter info to generate wrapper later
        final EnumConverterInfo converterInfo = new EnumConverterInfo(
            enumConvertersPackageName, converterClassName, enumeration.getType().getName(), enumClassName);
        m_EnumConverters.add(converterInfo);

        final DateFormat dateFormat = new SimpleDateFormat(GEN_DATE_FORMAT);
        final long currentDate = new Date().getTime();
        outStream.println(GEN_FILE_COMMENT + dateFormat.format(currentDate));
        outStream.format("package %s;%n%n", enumConvertersPackageName); // NOCHECKSTYLE: Duplicate string is more readable
        outStream.println("import com.google.common.collect.BiMap;");
        outStream.println("import com.google.common.collect.ImmutableBiMap;");
        outStream.println();

        // Class Definition
        outStream.format("public final class %s {%n", converterClassName);

        // Map Definition
        outStream.format("    private static final BiMap<%s, %s> VALUE_MAP =%n",
                enumeration.getType().getName(), enumClassName);
        outStream.format("        ImmutableBiMap.<%s, %s>builder()%n",
                enumeration.getType().getName(), enumClassName);
        for (Object value : enumeration.getType().getEnumConstants())
        {
            outStream.format("       .put(%s.%s, %s.%s)%n",
                    enumeration.getType().getName(), value, enumClassName, value);
        }
        outStream.println("       .build();");
        outStream.println();

        // Method Definitions
        outStream.format("    public static %s convertJava%sToProto(%s value) {%n", enumClassName,
                enumeration.getName(), enumeration.getType().getName());
        outStream.println("        if (VALUE_MAP.containsKey(value)) {");
        outStream.println("            return VALUE_MAP.get(value);");
        outStream.println("        }"); // NOCHECKSTYLE: Duplicate string is more readable
        outStream.println(
            "        throw new IllegalArgumentException(String.format(\"Invalid java enum specified: %s\", value));");
        outStream.println("    }"); // NOCHECKSTYLE: Duplicate string is more readable
        outStream.println();

        outStream.format("    public static %s convertProto%sToJava(%s value) {%n",
                enumeration.getType().getName(), enumeration.getName(), enumClassName);
        outStream.println("        if (VALUE_MAP.containsValue(value)) {");
        outStream.println("            return VALUE_MAP.inverse().get(value);");
        outStream.println("        }");
        outStream.println(
            "        throw new IllegalArgumentException(String.format(\"Invalid proto enum specified: %s\", value));");
        outStream.println("    }");

        outStream.println("}"); // NOCHECKSTYLE: Duplicate string is more readable
    }
/**
     * Generates an enumeration converter source file for the given {@link ProtoEnum}.
     * 
     * @param enumeration
     *      proto enumeration
     * @param outStream
     *      source file output stream
     * @param protoClassName
     *      name of the associated proto class
     * @param protoPackageName
     *      Java package name of the associated proto class
     * @param enumConvertersPackageName
     *      Java package name for the enumeration converters
     */
Generates an enumeration converter source file for the given  ProtoEnum.


Generates an enumeration converter source file for the given ProtoEnum .
public void genEnumConverterFile(final ProtoEnum enumeration, final PrintStream outStream,
        final String protoClassName, final String protoPackageName, final String enumConvertersPackageName)
    {
        final String converterClassName = String.format("%sConverter", enumeration.getType().getSimpleName());
        final String enumClassName = String.format("%s.%s.%s", protoPackageName, protoClassName, 
                enumeration.getType().getSimpleName().replace(ProtoEnum.ENUM, PACKAGE_SEPARATOR) 
                + enumeration.getName());
        final EnumConverterInfo converterInfo = new EnumConverterInfo(
            enumConvertersPackageName, converterClassName, enumeration.getType().getName(), enumClassName);
        m_EnumConverters.add(converterInfo);
        final DateFormat dateFormat = new SimpleDateFormat(GEN_DATE_FORMAT);
        final long currentDate = new Date().getTime();
        outStream.println(GEN_FILE_COMMENT + dateFormat.format(currentDate));
        outStream.format("package %s;%n%n", enumConvertersPackageName); 
        outStream.println("import com.google.common.collect.BiMap;");
        outStream.println("import com.google.common.collect.ImmutableBiMap;");
        outStream.println();
        outStream.format("public final class %s {%n", converterClassName);
        outStream.format("    private static final BiMap<%s, %s> VALUE_MAP =%n",
                enumeration.getType().getName(), enumClassName);
        outStream.format("        ImmutableBiMap.<%s, %s>builder()%n",
                enumeration.getType().getName(), enumClassName);
        for (Object value : enumeration.getType().getEnumConstants())
        {
            outStream.format("       .put(%s.%s, %s.%s)%n",
                    enumeration.getType().getName(), value, enumClassName, value);
        }
        outStream.println("       .build();");
        outStream.println();
        outStream.format("    public static %s convertJava%sToProto(%s value) {%n", enumClassName,
                enumeration.getName(), enumeration.getType().getName());
        outStream.println("        if (VALUE_MAP.containsKey(value)) {");
        outStream.println("            return VALUE_MAP.get(value);");
        outStream.println("        }"); 
        outStream.println(
            "        throw new IllegalArgumentException(String.format(\"Invalid java enum specified: %s\", value));");
        outStream.println("    }"); 
        outStream.println();
        outStream.format("    public static %s convertProto%sToJava(%s value) {%n",
                enumeration.getType().getName(), enumeration.getName(), enumClassName);
        outStream.println("        if (VALUE_MAP.containsValue(value)) {");
        outStream.println("            return VALUE_MAP.inverse().get(value);");
        outStream.println("        }");
        outStream.println(
            "        throw new IllegalArgumentException(String.format(\"Invalid proto enum specified: %s\", value));");
        outStream.println("    }");
        outStream.println("}"); 
    }
public void genEnumConverterFile ( final ProtoEnum enumeration , final PrintStream outStream , final String protoClassName , final String protoPackageName , final String enumConvertersPackageName ) { final String converterClassName = String . format ( "%sConverter" , enumeration . getType ( ) . getSimpleName ( ) ) ; final String enumClassName = String . format ( "%s.%s.%s" , protoPackageName , protoClassName , enumeration . getType ( ) . getSimpleName ( ) . replace ( ProtoEnum . ENUM , PACKAGE_SEPARATOR ) + enumeration . getName ( ) ) ; final EnumConverterInfo converterInfo = new EnumConverterInfo ( enumConvertersPackageName , converterClassName , enumeration . getType ( ) . getName ( ) , enumClassName ) ; m_EnumConverters . add ( converterInfo ) ; final DateFormat dateFormat = new SimpleDateFormat ( GEN_DATE_FORMAT ) ; final long currentDate = new Date ( ) . getTime ( ) ; outStream . println ( GEN_FILE_COMMENT + dateFormat . format ( currentDate ) ) ; outStream . format ( "package %s;%n%n" , enumConvertersPackageName ) ; outStream . println ( "import com.google.common.collect.BiMap;" ) ; outStream . println ( "import com.google.common.collect.ImmutableBiMap;" ) ; outStream . println ( ) ; outStream . format ( "public final class %s {%n" , converterClassName ) ; outStream . format ( "    private static final BiMap<%s, %s> VALUE_MAP =%n" , enumeration . getType ( ) . getName ( ) , enumClassName ) ; outStream . format ( "        ImmutableBiMap.<%s, %s>builder()%n" , enumeration . getType ( ) . getName ( ) , enumClassName ) ; for ( Object value : enumeration . getType ( ) . getEnumConstants ( ) ) { outStream . format ( "       .put(%s.%s, %s.%s)%n" , enumeration . getType ( ) . getName ( ) , value , enumClassName , value ) ; } outStream . println ( "       .build();" ) ; outStream . println ( ) ; outStream . format ( "    public static %s convertJava%sToProto(%s value) {%n" , enumClassName , enumeration . getName ( ) , enumeration . getType ( ) . getName ( ) ) ; outStream . println ( "        if (VALUE_MAP.containsKey(value)) {" ) ; outStream . println ( "            return VALUE_MAP.get(value);" ) ; outStream . println ( "        }" ) ; outStream . println ( "        throw new IllegalArgumentException(String.format(\"Invalid java enum specified: %s\", value));" ) ; outStream . println ( "    }" ) ; outStream . println ( ) ; outStream . format ( "    public static %s convertProto%sToJava(%s value) {%n" , enumeration . getType ( ) . getName ( ) , enumeration . getName ( ) , enumClassName ) ; outStream . println ( "        if (VALUE_MAP.containsValue(value)) {" ) ; outStream . println ( "            return VALUE_MAP.inverse().get(value);" ) ; outStream . println ( "        }" ) ; outStream . println ( "        throw new IllegalArgumentException(String.format(\"Invalid proto enum specified: %s\", value));" ) ; outStream . println ( "    }" ) ; outStream . println ( "}" ) ; }
Generates an enumeration converter source file for the given {@link ProtoEnum}.
Generates an enumeration converter source file for the given { @link ProtoEnum } .
// Store converter info to generate wrapper later // NOCHECKSTYLE: Duplicate string is more readable // Class Definition // Map Definition // Method Definitions // NOCHECKSTYLE: Duplicate string is more readable // NOCHECKSTYLE: Duplicate string is more readable // NOCHECKSTYLE: Duplicate string is more readable