public static <S extends Set<T>, T extends Enum<T>> Set<T> enumSet(final Class<T> type,
                                                                       final S set) {
        if (set instanceof EnumSet<?>) {
            return set;
        } else if (set == null || set.isEmpty()) {
            return EnumSet.noneOf(type);
        } else {
            // Make sure we get back an EnumSet as they are faster and more memory efficient
            return EnumSet.copyOf(set);
        }
    }
Returns a non-null {@link EnumSet} containing the items in set.
If set is not itself an {@link EnumSet} then the items will be copied into
a new {@link EnumSet}.

@param type The class of the {@link Enum} for use when constructing an empty {@link EnumSet}
@return A non-null {@link EnumSet}.
stroom-util-shared/src/main/java/stroom/util/shared/NullSafe.java