Java EnumSet Create enumSetOf(long bitSet, Class eClass)

Here you can find the source of enumSetOf(long bitSet, Class eClass)

Description

enum Set Of

License

Apache License

Declaration

public static <E extends Enum<E>> EnumSet<E> enumSetOf(long bitSet, Class<E> eClass) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.EnumSet;

public class Main {
    public static final long EMPTY_BIT_SET = 0L;

    public static <E extends Enum<E>> EnumSet<E> enumSetOf(long bitSet, Class<E> eClass) {
        if (bitSet == EMPTY_BIT_SET) {
            return EnumSet.noneOf(eClass);
        }/* w  ww .j  av a2 s.  c  om*/
        EnumSet<E> flagSet = EnumSet.noneOf(eClass);
        for (E f : eClass.getEnumConstants()) {
            if (hasEnum(bitSet, f)) {
                flagSet.add(f);
            }
        }
        return flagSet;
    }

    public static boolean hasEnum(long bitSet, Enum<?> anEnum) {
        return (bitSet & (1 << anEnum.ordinal())) != 0;
    }
}

Related

  1. asSet(E[] array)
  2. createEnumSet(Class elementType)
  3. enumFromSet(EnumSet theSet)
  4. enumSet(T... elements)
  5. fromString(Class enumType, String value)
  6. fromString(Class enumClass, String name)
  7. intToEnumSet(Class enumClass, int decoded)
  8. newEnumSet(Class klass)