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 ; }
Returns EnumSet constructed from bit flag . Bit flags bit position is according to Enum ordinal .