title: Check value in enum structure
body: <p>I use this JUnit test in order to load values from database and save them back. So far this is the current implementation:</p>
  
  <pre><code>public class BitStringTest {
  
      Map&lt;FeatureBitString, Boolean&gt; features = new HashMap&lt;&gt;();
  
      public void enableFeature(FeatureBitString feature) {
          features.put(feature, true);
      }
  
      public void disableFeature(FeatureBitString feature) {
          features.put(feature, false);
      }
  
      public boolean isFeatureEnabled(FeatureBitString feature) {
          Boolean enabled = features.get(feature);
          return enabled != null &amp;&amp; enabled;
      }
  
      public String convertToDatabaseValue() {
          return Arrays.stream(FeatureBitString.values()).map(f -&gt; isFeatureEnabled(f) ? "1" : "0").collect(joining());
      }
  
      public Map&lt;FeatureBitString, Boolean&gt; initFromDatabaseValue(String bitString) {
          // Note that, bitString length should equals to your number of feature. Or you
          // have to padding it
          char[] bitArray = bitString.toCharArray();
          return Arrays.stream(FeatureBitString.values())
                  .collect(toMap(f -&gt; f, f -&gt; bitArray[f.getIndex()] == '1', (v1, v2) -&gt; v2, LinkedHashMap::new));
      }
  
      @Test
      public void testToDatabaseValue() {
          System.out.println("\nProducing Features ");
          features.put(FeatureBitString.A, true);
          features.put(FeatureBitString.F, true);
          Assertions.assertEquals(convertToDatabaseValue(), "1000010");
      }
  }
  
  enum FeatureBitString {
      A("Type1", 0), // index 0 in bit string
      B("Type2", 1), // index 1 in bit String
      C("Type3", 2), // index 2 in bit String
      D("Type3", 3), // index 3 in bit String
      E("Type4", 4), // index 4 in bit String
      F("Type5", 5), // index 5 in bit String
      G("Type6", 6); // index 6 in bit String
  
      private final String featureName;
      private final int index;
  
      private FeatureBitString(String featureName, int value) {
          this.featureName = featureName;
          this.index = value;
      }
  
      public String getFeatureName() {
          return featureName;
      }
  
      public int getIndex() {
          return index;
      }
  }
  </code></pre>
  
  <p>How I can verify is the value "Type2" is present in enum FeatureBitString? Before I load it I would like to check is this value present according to the enum data.</p>
  
  <p>I tried to use this code:</p>
  
  <pre><code>public static Optional&lt;FeatureBitString&gt; getByFeatureName(String featureName) {
      return Optional.of(values()).map(FeatureBitString::getFeatureName).filter(f -&gt; f.equals(featureName)).findAny();
  }
  
  if (FeatureBitString.getByFeatureName("Type2").isPresent()) { 
     // ...
  }
  </code></pre>
  
  <p>But I get error <code>method values() is undefined for the type DatabaseFeaturesBitStringTest</code></p>