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

How to pass any (known at runtime only) Kotlin enum as parameter to a method in Java code?

Say we have enums enum class Status { OPEN, CLOSED } enum class Weekday { WORKDAY, DAYOFF } Having a Java class public KotlinInvoker { public methodWithKotlinEnumAsParameter_namely_AppendWorkingStatusString( ? kotlinEnum) { ... …
SoBeRich
  • 682
  • 2
  • 8
  • 15
7
votes
3 answers

Elegant way to deserialise EnumSet from String

I'd like to serialise some EnumSet to String using its toString() method. E.g.: EnumSet.of(FooType.COMMON, FooType.MEDIUM).toString() will give [COMMON, MEDIUM]. The question is about an elegant way to deserialise such a string back to the…
Andremoniy
  • 34,031
  • 20
  • 135
  • 241
6
votes
4 answers

Converting from EnumSet to Set when A inherits from B

The title pretty much explains the question. I have an interface method: Set getFieldSet() and I have a class, User which looks something like this class User { enum Fields implements Field { USERNAME, PASSWORD; ... …
Amir Rachum
  • 76,817
  • 74
  • 166
  • 248
6
votes
1 answer

Discrepancy between Eclipse compiler and javac - Enums, interfaces, and generics

The following code compiles (and runs tests as expected) in Eclipse: import java.util.EnumSet; public class EnumTest { static enum Cloneables implements Cloneable { One, Two, Three; } public T getOne(Class…
E-Riz
  • 31,431
  • 9
  • 97
  • 134
5
votes
5 answers

Which class in Java implements the abstract class EnumSet?

I see that EnumSet.of() returns an instance of an object of the type EnumSet. But I am not able to figure out which class actually implements this abstract class? How can you get an instance of the abstract type EnumSet, when you have not…
Foo
  • 4,206
  • 10
  • 39
  • 54
5
votes
3 answers

Convert between EnumSet and array of boolean values

I have an EnumSet and want to convert back-and-forth to/from an array of boolean primitives. If it works better, I could work with a List instead of an array, and/or Boolean objects rather than boolean primitives. enum MyEnum { DOG, CAT, BIRD;…
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
5
votes
1 answer

How to map EnumSet (or List of Enums) in an entity using JPA2

I have entity Person: @Entity @Table(schema="", name="PERSON") public class Person { List paymentTypesList; //some other fields //getters and setters and other logic } and I have enum PaymentType: public enum…
arteq
  • 51
  • 1
  • 4
4
votes
1 answer

Dealing with enums implementing common interface (iterate, deserialize)

I have an Android application that loads a data from web sources and displays it. I organized each API method those sources support in enum constants split per source. Let's say, SourceA provides Sport and Weather data and SourceB provides Stock and…
dmzkrsk
  • 2,011
  • 2
  • 20
  • 30
4
votes
1 answer

How do I initialize an empty EnumSet in kotlin?

I'm pretty new to Kotlin and trying to create a sort of bitset enum where ints correspond to state and I can toggle individual states by toggling individual bits. But I'm stuck on where an object can have no…
toshiomagic
  • 1,335
  • 1
  • 12
  • 39
4
votes
1 answer

EnumSet methods won't recognize any enum types as enums

There are a number of similar questions about similar errors but they're all about specific situations where the enum type hadn't initialized before trying to make an EnumSet of that type. My problem is much, much more basic. I can't get any EnumSet…
4
votes
4 answers

Is there something like nested enums in Java?

I want to do a Country enum from which i can access to its states, how can i do that? Something like this: public enum SomeEnum { ARGENTINA { BUENOS_AIRES; } UNITED_STATES { CALIFORNIA, FLORIDA, NEW_YORK, ALASKA; …
Luis Veliz
  • 247
  • 4
  • 8
4
votes
2 answers

How do you properly extend/subclass EnumSet in Java?

I've attempted to extend EnumSet to implement Comparable in Eclipse. However, I'm fraught with errors, right from the beginning. Here's what I start with: package sets; import java.util.EnumSet; enum Suits{ SPADE, DIAMOND, CLUB,…
nikodaemus
  • 1,918
  • 3
  • 21
  • 32
4
votes
1 answer

Java: How to write generic function that accepts Enum constants that implement a given interface?

So i have a bunch of enum's that all extend an interface: public interface MyInterface {} I then have several enums that extend the interface: public enum A implements MyInterface {} public enum B implements MyInterface {} I want a function that…
codecitrus
  • 659
  • 6
  • 17
4
votes
3 answers

convert a two Byte bit mask into a EnumSet

I am reading a binary file that has values stored in bit masks, both 1 Byte bit masks and 2 Byte bit masks. Each bit in the masks act as a switch that indicates where an Event has transpired. Example of 1 Byte mask: 00000101 Indicates that…
WolfmanDragon
  • 7,851
  • 14
  • 49
  • 61
3
votes
3 answers

java enum with enum in constructor

Is it possible to let a enum in java take a set of enums as as argument? If yes, then how do I implement it? When using this I whant to be able to say something like: Take a MODAL_SETTINGS.EDIT_MODAL_WINDOW and create this with the buttons…
Marthin
  • 6,413
  • 15
  • 58
  • 95