title: Getting enum associated with int value
body: <p>Previously, I had my LegNo enums defined simply as: </p>
  
  <pre><code>NO_LEG, LEG_ONE, LEG_TWO
  </code></pre>
  
  <p>and by calling <code>return LegNo.values()[i];</code>, I was able to get the value associated with each enum. </p>
  
  <p>But now I've decided I want the <code>LegNo</code> enum <code>NO_LEG</code> to be the int -1 instead of 0
  so I decided to use a private constructor to initialise and set its int value</p>
  
  <pre><code>NO_LEG(-1), LEG_ONE(1), LEG_TWO(2);
  
  private LegNo(final int leg) { legNo = leg; }
  </code></pre>
  
  <p>the only thing now is that because I'm doing it this way the <code>values()</code> method will not work for the <code>NO_LEG</code> enum. How do I get the enum associated with the int? Is there any efficient way of doing this other than using a case switch statement or an if-elseif-elseif</p>
  
  <p>I can see a lot of SO questions to do with getting the int value from the enum, but I'm after the reverse. </p>