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
3
votes
1 answer

Mapping EnumSet in Hibernate

How to store EnumSet in the DB (using Hibernate)? @Entity public class A { public static enum SOME_ENUM { A, B, C }; private EnumSet myEnumSet = EnumSet.of(SOME_ENUM.A, SOME_ENUM.B); ... ... } If I try to persist the above, I get…
Daniel
  • 249
  • 1
  • 2
  • 4
3
votes
2 answers

Instantiate EnumSet from one of two types of Enum

I have these two Enums declared as such: public enum EnumOne implements EnumInterface { SomethingHere, SomethingThere; public void someMethod () { } } public enum EnumTwo implements EnumInterface { SomethingOverYonder; public…
ShadowGeist
  • 71
  • 1
  • 3
  • 9
3
votes
1 answer

Union two ImmutableEnumSets with Guava

I want to union two ImmutableEnumSets from Guava. Here's my try on it: public final class OurColors { public enum Colors { RED, GREEN, BLUE, YELLOW, PINK, BLACK } public final static…
Juergen
  • 3,489
  • 6
  • 35
  • 59
3
votes
1 answer

Thread-safe Enumset in Java

I use the following code to initialize a synchronized instance of an EnumSet: private final Set instance = Collections.synchronizedSet(EnumSet.noneOf(MyClass.class)); I have two questions: do I retain all the benefits of an EnumSet like…
jilt3d
  • 3,864
  • 8
  • 34
  • 41
3
votes
3 answers

Using EnumSet of a enum implementing an interface

I have an interface public interface TerminalSymbol { // methods ... } an enum // common usage enum that I need public enum Common implements TerminalSymbol { EPSILON; @Override // methods ... } and I'd like to do something…
Mega-X
  • 67
  • 5
2
votes
3 answers

Can EnumSet return values in written order?

I have an EnumSet public static Set getTypes() { return EnumSet.of( TYPE_1, TYPE_2, TYPE_3 ); } And i want to get the values from it with a getter method When i try to get the values in my…
alexsk_1
  • 21
  • 3
2
votes
1 answer

EnumSet of bit flags into UInt in Kotlin

I have a lot of enum class in my Kotlin application. They all represent bit flags that I need to convert between EnumSet<> and UInt for serial communication with an FPGA board. How can I provide some extension methods that apply to all those…
Josh Brown
  • 935
  • 1
  • 11
  • 21
2
votes
3 answers

EnumSet modifiers inside an enum in Java

It makes sense declaring an EnumSet within a enum with the modifiers static and final? Or are redundant? Example: public enum Guitar { STRATOCASTER, LES_PAUL, CLASSIC; private static final EnumSet electrics =…
jpestana
  • 37
  • 6
2
votes
1 answer

Need of EnumSet / EnumMap over generified Set / Map

EnumSet/EnumMap can be created by specifying the defined enum to produce set/map instance as shown in below sample code. So far I read, difference between EnumSet/EnumMap with that of Set/Map is that we cannot add objects other than the specified…
parthiban
  • 115
  • 1
  • 1
  • 9
2
votes
2 answers

How can I mimic a multi-tiered menuing system using Java enums?

I need to accomplish the following (this is a simplified version): enum Animals{ enum Cats{tabby("some value"), siamese("some value")}, enum Dogs{poodle("some value"), dachsund("some value")}, enum Birds{canary("some value"), parrot("some…
bynary
  • 841
  • 2
  • 11
  • 26
2
votes
1 answer

EL syntax to check if a set contains a specific Enum value

I have an Item object, which has a field that is a Set of ItemTypes: public class Item { EnumSet itemTypeSet; ... public Set getItemTypeSet(){ return this.itemTypeSet; } } ItemType is of course a simple…
user1884155
  • 3,616
  • 4
  • 55
  • 108
2
votes
1 answer

Why EnumSet uses RegularEnumSet and JumboEnumSet for different sizes.How it impact performance?

While exploring Java EnumSet, i cam across two package-private class, RegularEnumSet JumboEnumSet From EnumSet source : if (universe.length <= 64) return new RegularEnumSet<>(elementType, universe); else return new…
Prateek
  • 12,014
  • 12
  • 60
  • 81
2
votes
2 answers

Convert an EnumSet to an array of integers

I have an EnumSet and want to convert it to array of its ordinal values. For example: enum MyEnum { A, B, C; } EnumSet enumSet = EnumSet.of(MyEnum.A, MyEnum.C); and what I want to get: [0, 2]
Sergеу Isupov
  • 504
  • 1
  • 8
  • 20
2
votes
1 answer

Understanding enumset for enumerators

As far as I understood it would be much easier and clearler to use EnumSet and that the Set was specifically designed for using with Enumerators. My question is whether we should consider to use the EnumSet every time we need to maintain some…
user3663882
  • 6,957
  • 10
  • 51
  • 92
2
votes
1 answer

(De)serialize enum set

Is there an easy way to serialize and deserialize enum sets with Jackson? private enum Type { YES, NO } @JacksonXmlProperty(localName = "type", isAttribute = true) private final EnumSet types; This gives the following XML: ...
user4402596