title: Replace String Enum with protobuf auto generated Enum
body: <p>My Enum original java code is:</p>
  
  <pre><code>public enum CarModel {
      NOMODEL("NOMODEL");
      X("X"),
      XS("XS"),
      XSI("XS-I"); //NOTE the special - character. Can't be declared XS-I
      XSI2("XS-I.2"); //NOTE the special . character. Can't be declared XS-I.2
      private final String carModel;
      CarModel(String carModel) { 
          this.carModel = carModel;
      }
  
      public String getCarModel() { return carModel; }
  
      public static CarModel fromString(String text) {
          if (text != null) {
              for (CarModel c : CarModel.values()) {
                  if (text.equals(c.carModel)) {
                      return c;
                  }
              }
          }
          return NOMODEL; //default
      }
  }
  </code></pre>
  
  <p>Now if I use protobuf I get in the .proto file:</p>
  
  <pre><code>enum CarModel {
      NOMODEL = 0;
      X = 1;
      XS = 2;
      XSI = 3;
      XSI2 = 4;
  }
  </code></pre>
  
  <p>from my <a href="https://stackoverflow.com/questions/19130965/how-do-i-share-enum-values-between-my-java-code-and-proto-file">earlier question</a> I know I can call the enum generated by protoc and remove my own class (and thus avoid the duplicate value definitions) but I still need to define somewhere (In a wrapper class? wrapper enum class?) the alternate <code>fromString()</code> method that will return the right string per the enum. How do I do that?</p>
  
  <p>EDIT:
  How do I implement the following:</p>
  
  <p><code>String carModel = CarModel.XSI.toString();</code> 
  This will return "XS-I"</p>
  
  <p>and:</p>
  
  <pre><code>CarModel carModel = CarModel.fromString("XS-I.2");
  </code></pre>