Example usage for java.util EnumSet noneOf

List of usage examples for java.util EnumSet noneOf

Introduction

In this page you can find the example usage for java.util EnumSet noneOf.

Prototype

public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) 

Source Link

Document

Creates an empty enum set with the specified element type.

Usage

From source file:Main.java

/**
 * Turns an array of enumeration values into an enum set
 *
 * @param clazz the type of the enum/*from  w  ww.  ja  va 2  s . c o m*/
 * @param ts the array of enums
 * @return the enum set containing all the values from the array
 */
public static <T extends Enum<T>> EnumSet<T> toEnumSet(Class<T> clazz, T... ts) {
    if (ts == null)
        return null;

    EnumSet<T> res = EnumSet.noneOf(clazz);
    for (T t : ts) {
        res.add(t);
    }
    return res;
}

From source file:org.mozilla.gecko.home.SearchLoader.java

@SuppressWarnings("unchecked")
public static Loader<Cursor> createInstance(Context context, Bundle args) {
    if (args != null) {
        final String searchTerm = args.getString(KEY_SEARCH_TERM);
        final EnumSet<FilterFlags> flags = (EnumSet<FilterFlags>) args.getSerializable(KEY_FILTER_FLAGS);
        return new SearchCursorLoader(context, searchTerm, flags);
    } else {/*from  ww w .j a v a2 s  .  co m*/
        return new SearchCursorLoader(context, "", EnumSet.noneOf(FilterFlags.class));
    }
}

From source file:org.kontalk.util.EncodingUtils.java

/**
 * Get an enum set by parsing an integer which represents a bit array.
 * Source: http://stackoverflow.com/questions/2199399/storing-enumset-in-a-database
 * @param <T> type of elements in enum set
 * @param enumClass enum class to determine the type
 * @param decoded integer decoded as/*from   w w w  . jav a2s .  com*/
 * @return an enum set containing the enums specified by the integer
 */
public static <T extends Enum<T>> EnumSet<T> intToEnumSet(Class<T> enumClass, int decoded) {
    EnumSet<T> enumSet = EnumSet.noneOf(enumClass);
    T[] enums = enumClass.getEnumConstants();
    while (decoded != 0) {
        int ordinal = Integer.numberOfTrailingZeros(decoded);
        enumSet.add(enums[ordinal]);
        decoded -= Integer.lowestOneBit(decoded);
    }
    return enumSet;
}

From source file:com.jayway.jsonpath.Configuration.java

public static Configuration defaultConfiguration() {
    return new Configuration(JsonProviderFactory.createProvider(), EnumSet.noneOf(Option.class));
}

From source file:util.awt.AWTJSONUtil.java

/** Deserialize an EnumSet from a JSON array. */
public static <T extends Enum<T>> EnumSet<T> enumSetFromJSON(Class<T> enumType, JSONArray array)
        throws JSONException {
    EnumSet<T> ret = EnumSet.noneOf(enumType);
    for (int i = 0; i < array.length(); i++) {
        String element = array.getString(i);
        try {//from   ww  w . j a v a  2  s. c o m
            T t = Enum.valueOf(enumType, element);
            ret.add(t);
        } catch (IllegalArgumentException e) {
            throw new JSONException("Unknown enumerator in set of " + enumType.getSimpleName() + ": \""
                    + element + "\": " + e.getMessage());
        }
    }
    return ret;
}

From source file:org.yccheok.jstock.news.Utils.java

public static Set<NewsSource> getSupportedNewsSources(Country country) {
    List<NewsServer> newsServers = NewsServerFactory.getNewsServers(country);
    Set<NewsSource> set = EnumSet.noneOf(NewsSource.class);
    for (NewsServer newsServer : newsServers) {
        NewsSource newsSource = classToNewsSourceMap.get(newsServer.getClass());
        if (newsSource != null) {
            set.add(newsSource);//from  w ww  .ja  va2s .  c om
        }
    }
    return set;
}

From source file:org.mozilla.gecko.home.SearchLoader.java

public static void init(LoaderManager manager, int loaderId, LoaderCallbacks<Cursor> callbacks,
        String searchTerm) {//  w  ww .  j  av  a2  s  .co  m
    init(manager, loaderId, callbacks, searchTerm, EnumSet.noneOf(FilterFlags.class));
}

From source file:ru.savvy.jpafilterbuilder.FilterConverter.java

private Map.Entry<String, EnumSet<Option>> extractOptions(String fieldName) throws IllegalArgumentException {
    int firstPar = fieldName.indexOf("(");
    int secondPar = fieldName.indexOf(")");

    EnumSet<Option> options = EnumSet.noneOf(Option.class);

    if (secondPar > firstPar && firstPar >= 0) {
        String field = fieldName.substring(firstPar + 1, secondPar);
        if (field.trim().length() > 0) {
            String sopts[] = field.split(",");
            for (String sopt : sopts) {
                String s = sopt.trim();
                try {
                    options.add(Option.valueOf(s.toUpperCase(Locale.US)));
                } catch (IllegalArgumentException e) {
                    throw new IllegalArgumentException("Field option \"" + s + "\" does not exist");
                }//from  w  w w . j  a v a 2  s .  c  o m
            }
        }
        return new HashMap.SimpleEntry<>(fieldName.substring(0, firstPar).trim(), options);

    }
    return new HashMap.SimpleEntry<>(fieldName, options);
}

From source file:io.swagger.inflector.config.DirectionDeserializer.java

@Override
public Set<Configuration.Direction> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.VALUE_FALSE) {
        return EnumSet.noneOf(Configuration.Direction.class);
    } else if (token == JsonToken.VALUE_TRUE) {
        return EnumSet.allOf(Configuration.Direction.class);
    } else if (token == JsonToken.START_ARRAY) {
        final Set<Configuration.Direction> items = EnumSet.noneOf(Configuration.Direction.class);
        while (true) {
            final JsonToken next = jp.nextToken();
            if (next == JsonToken.VALUE_STRING) {
                final String name = jp.getText();
                items.add(Configuration.Direction.valueOf(name));
            } else if (next == JsonToken.END_ARRAY) {
                return items;
            } else {
                break;
            }//from  ww w .j  av a  2 s . c o  m
        }
    }
    throw ctxt.mappingException(Configuration.Direction.class);
}

From source file:com.asakusafw.testdriver.compiler.util.DeploymentUtil.java

/**
 * Deploys an artifact onto the directory.
 * @param source the source file/directory
 * @param destination the target path//from   w  w w  .j a va  2s .c  o m
 * @param options the deployment options
 * @throws IOException if I/O error was occurred
 */
public static void deploy(File source, File destination, DeployOption... options) throws IOException {
    Objects.requireNonNull(source);
    Objects.requireNonNull(destination);
    Objects.requireNonNull(options);
    Set<DeployOption> opts = EnumSet.noneOf(DeployOption.class);
    Collections.addAll(opts, options);
    if (opts.contains(DeployOption.DELETE_SOURCE)) {
        move(source, destination);
    } else {
        copy(source, destination);
    }
}