title: Java enums: implementing common methods, avoiding duplication
body: <p>Let's say that I have two differents enumeration</p>
  
  <pre><code>public enum SomeEnumClass {
  
      private static  final SomeEnumClass[]   mValues = SomeEnumClass .values();
      ONE(1), TWO(2), THREE(3);
  
  }
  
  public enum OtherEnumClass {
      private static  final OtherEnumClass[]  mValues = OtherEnumClass .values();
      Monday(1), Tuesday(2), Wednesday(3), Thrusday(4), Friday(5), Saturday(6), Sunday(7)
  
  }
  </code></pre>
  
  <p>The enum have in common the type of data they carry (here, an int), and differ in their name and number of possible values.</p>
  
  <p>For each of those enum, I have several method to implements, which are strictly identical. Example:</p>
  
  <pre><code>        public static OtherEnumClass getCell(int index)
      {
          if (index &lt; OtherEnumClass .mValues.length )
          {
              return OtherEnumClass .mValues[index];              
          }
          throw new IllegalArgumentException("Invalid " + OtherEnumClass .class.getSimpleName() + " value: " + index);
      }
  </code></pre>
  
  <p>I am trying to find a way to avoid duplication of those methods, like I would do with abstract classes. But so far I am coming with nothing.</p>
  
  <p>We are using java 1.6 and cannot upgrade for now. Any help is appreciated. thanks.</p>