Questions tagged [enumset]

A specialized Set implementation for use with enum types. EnumSet class exists to take advantage of the efficient implementations that are possible when the number of possible elements is fixed and a unique index can be assigned to each.

A specialized Set implementation for use with enum types. EnumSet class exists to take advantage of the efficient implementations that are possible when the number of possible elements is fixed and a unique index can be assigned to each.

All of the elements in an enum set must come from a single enum type that is specified, explicitly or implicitly, when the set is created. Enum sets are represented internally as bit vectors. This representation is extremely compact and efficient. The space and time performance of this class should be good enough to allow its use as a high-quality, typesafe alternative to traditional int-based "bit flags." Even bulk operations (such as containsAll and retainAll) should run very quickly if their argument is also an enum set.

98 questions
0
votes
1 answer

store different enum types in enumSet

I want to store different enum types within one enum. Is this the right (shortest) way? public enum MyEnums { all(EnumSet.of(Color.red, Shape.round)); MyEnums(EnumSet> keys) { this.keys = keys; } private…
nimo23
  • 5,170
  • 10
  • 46
  • 75
0
votes
0 answers

Given a "black box" enum, is it possible to check if a provided integral is a valid member of the enum in C++?

I'm writing an EnumSet class for a project. I would like to have an EnumSet::AllOf() method if possible, like in Java. The obvious way to go about this is to iterate over every member of the std::underlying_type and try casting it to the enum class,…
Q Science
  • 111
  • 7
0
votes
0 answers

I have a qustion about empty EnumSets. I tried the .noneOf() method but i always get the "java.lang.ExceptionInInitializerError" error

This is a early construct of my class: public class Player { public enum Tech { NONE(EnumSet.noneOf(Tech.class)), VEGETATION(EnumSet.of(NONE)), LIVESTOCK(EnumSet.of(NONE)), STRAWBERRIES(EnumSet.of(VEGETATION)), …
Symlink
  • 383
  • 2
  • 12
0
votes
1 answer

Get fixed values dynamically in a java application using Enum and EnumSet

I am writing a web application where in I need to have a lot of fixed values in the system to support operations and UI.I figured out it's better to put them in an Enum and group them using EnumSet as described in the Snippet below. Now what I need…
nocoder
  • 89
  • 1
  • 7
0
votes
1 answer

JavaPoet - Exception unexpected

So, I'm making a program that takes a Class Diagram and, using JavaPoet, converts it in Java code. The class Diagram is not written in UML, it's already modelled inside the program with java. Here is the code portion giving me problems: (parsing…
user7244619
0
votes
1 answer

How to display EnumSet in JSP file in custom order?

I have an java.util.EnumSet containing a lot of elements that is being displayed as a drop down list (JSP). Now, by default they're sorted by ID: 1 Toyota 2 Honda 3 Audi 4 BMW What I want to achieve is the list in alphabetic order: 3 Audi 4 BMW 2…
pidabrow
  • 966
  • 1
  • 21
  • 47
0
votes
1 answer

Enumset wrapper for AbstractActions

I'd like to load a series of Swing Actions into a container at runtime and access them by a constant name as is possible with an Enum. The purpose of this would be to both restrict the Actions possible and also improve readability. Initially, I was…
James P.
  • 19,313
  • 27
  • 97
  • 155
0
votes
0 answers

Method returning an enum

I have a question involving EnumSet and Enum. More specifically, about passing them as paramaters and returning them from methods. Basically, I want to have a method in one class create an EnumSet of certain elements of a Enum than I want said class…
0
votes
1 answer

Why do we need Set and Map for Java Enum

I am new to Enum. While I am learning Enum, I came across EnumSet and EnumMap. I understand that when dealing with map and set using EnumSet and EnumMap is much better than the hashing counterparts from this question. Why an EnumSet or an EnumMap…
mvg
  • 1,574
  • 4
  • 37
  • 63
0
votes
2 answers

Problems when operating on Map, Object> in Java

public class MyClass { private Map, Object> member; public void putEnumSet(Class enumSetType, E enumSet) { this.member.put(enumSetType, enumSetType.cast(enumSet)); } public E getEnumSet(Class
stanleyerror
  • 728
  • 1
  • 9
  • 23
0
votes
1 answer

java EnumSet, incompatible types: inference variable E has incompatible bounds

I have a the below method which returns a enum set containing all of the elements of Types: @Override public EnumSet groupTypes() { return EnumSet.allOf(Types.class); } And the Types is an enum like below: public enum Types implements…
Tom
  • 385
  • 3
  • 7
  • 17
0
votes
1 answer

Adding type argument to EnumSet always give me "Bound mismatch"

I have this code below: public static Set union(Set set1, Set set2) { Set resultSet = new HashSet<>(set1); resultSet.addAll(set2); return resultSet; } I want to overload one method like below, and get bound mismatch: …
Yu-Ting Chen
  • 157
  • 1
  • 11
0
votes
2 answers

How does this Java EnumSet initialization construct work?

We have a habit of constructing EnumMap instances like in the following EnumMapExample.java example: package test; import java.util.EnumMap; public class EnumMapExample { enum TestEnum {SOME_VALUE, SOME_OTHER_VALUE} private final…
drvdijk
  • 5,556
  • 2
  • 29
  • 48
0
votes
1 answer

EnumSet - Efficient way to move intersection

I have two EnumSets. I want to transfer certain values from one to the other, but retain in both objects those values which are deemed "immoveable". Example code... Public enum MaterialTypes { STONE, METAL, WOOD, STICKS, …
Bumpy
  • 1,290
  • 1
  • 22
  • 32
0
votes
1 answer

Generics: Array of type expected

I have the following code: public class DEF implements Set { private EnumSet xyz=EnumSet.noneOf(ABC.class); @Override public T[] toArray(T[] a) { return xyz.toArray(a); } } Which gives me the following…
JohnyTex
  • 3,323
  • 5
  • 29
  • 52