title: Multiple Java 8 Enums with same methods
body: <p>I have a series of enums which look like this except that the name and values are different:</p>
  
  <pre><code>/* Bone Diagnosis. Value is internal code stored in database. */
  public enum BoneDiagnosis {
      NORMAL(121),
      ELEVATED(207),
      OSTEOPENIA(314),
      OSTEOPOROSIS(315);
  
      private int value;
      BoneDiagnosis(final int value) {
          this.value = value;
      }
  
      /** Get localized text for the enumeration. */
      public String getText() {
          return MainProgram.localize(this.getClass().getSimpleName().toUpperCase() + ".VALUE." + this.name());
      }
  
      /** Convert enumeration to predetermined database value. */
      public int toDB() {
          return value;
      }
  
      /** Convert a value read from the database back into an enumeration. */
      public static BoneDiagnosis fromDB(final Integer v) {
          if (v != null) {
              for (final BoneDiagnosis pc : values()) {
                  if (v == pc.toDB()) {
                      return pc;
                  }
              }
          }
          return null;
      }
  }
  </code></pre>
  
  <p>I know I cannot extend enums, but is there some way to abstract this design to remove all the duplicate code in toDB(), fromDB(), and getText() that each class has? I looked at other questions like <a href="https://stackoverflow.com/q/22083689/1663987">Is it possible to extend enum in Java 8?</a> which had an example using an interface, but I could not figure out how to handle the constructor and the static method. I also cannot figure out how to remove the explicit reference to type BoneDiagnosis in the fromDB() method.</p>
  
  <p>My dream would be to have each class merely be defined something like what follows, with all the other support wrapped up in whatever BoneDiagnosisComplexTypeDefinition is. Is this possible?</p>
  
  <pre><code>public enum BoneDiagnosisComplexTypeDefinition {
      NORMAL(121),
      ELEVATED(207);
      OSTEOPENIA(314),
      OSTEOPOROSIS(315)
  }
  </code></pre>