code: public static <E extends Enum<E>> EnumSet<E> getSet(Class<E> elementType, int flag)
      {
          EnumSet<E> set = EnumSet.noneOf(elementType);
          E[] enumConstants = elementType.getEnumConstants();
          if (enumConstants.length > Integer.SIZE)
          {
              throw new IllegalArgumentException(elementType+" contains too many enums for int");
          }
          for (int ii=0;ii<enumConstants.length;ii++)
          {
              if ((flag & (1<<ii)) != 0)
              {
                  set.add(enumConstants[ii]);
              }
          }
          return set;
      }
docs: Returns EnumSet constructed from bit flag. Bit flags bit position is
  according to Enum ordinal.
  
  <p>Throws IllegalArgumentException if enum contains too many values
  to fit flag.
  @param <E>
  @param elementType
  @param flag
  @return