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
2
votes
2 answers

EnumSet in c# when there is needed a groupation on levels

In java I have : public enum MyEnum{ Value1, Value2, Value3, //so on } And a class which will have a property : public abstract class MyClass{ public EnumSet myEnum= EnumSet.noneOf(MyEnum.class); } But also there is an…
David
  • 127
  • 2
  • 9
2
votes
1 answer

Persisting EnumSet in Postgresql with Hibernate

Effective Java, Item 32, states Use EnumSet instead of bit fields. I also found this nice tutorial on the topic. This book has been around for a while, so why don't I find any posts on how to persist an EnumSet with Hibernate? Well, I actually found…
aweibell
  • 405
  • 1
  • 5
  • 14
2
votes
2 answers

Is a readonly EnumSet iterator thread safe?

I have an EnumSet which is final and immutable i.e. initialized once in the constructor. Is the contains() method on this EnumSet thread safe? It is internally using an iterator to make the contains check. Hence if two threads are simultaneously…
Harish
  • 7,589
  • 10
  • 36
  • 47
2
votes
2 answers

Receive an EnumSet from a spring form checkbox element?

I've seen a few related questions on this topic but none that seem to exactly match what I'm after. I have a form where I'd like the user to be able to select a number of items from a checkbox list (backed by an enum), and to receive that as a Set.…
Abby
  • 3,169
  • 1
  • 21
  • 40
2
votes
1 answer

EnumSet parcelable

I'm writting the writeToParcel method and my model has an EnumSet as attribut. I don't know which out.write....() i have to use for this type ?
AdrianoCelentano
  • 2,461
  • 3
  • 31
  • 42
2
votes
2 answers

What does this bit shift operation means in Java RegularEnumSet implementation?

In RegularEnumSet implementation, there is a code: elements = -1L >>> -universe.lengh It uses a Long type integer to implement efficient EnumSet. What is notable is that the right-hand operand of >>> is a negative figure. I have tested and found…
l4rmbr
  • 1,227
  • 7
  • 22
1
vote
1 answer

How can I combine 2 bits in a single field using an EnumSet?

Given a binary string coded on 1 byte, is it possible to map several of that byte's bits into an enum value ? e.g. : suppose I want to cut my field into this : bit1 and bit2 = field1 bit3 = field2 bit4 = field3 bit5 = field4 other bits are…
Philippe
  • 6,703
  • 3
  • 30
  • 50
1
vote
1 answer

Problem with constructor of a generic class using enumset

I want to develope a class in java. The problem is that the constructor doesn't work The class is this: public class EnumSetPlus> { //Map private EnumSet map; //Constructor public EnumSetPlus(){ } I want to inicializate the…
recluising
  • 348
  • 1
  • 3
  • 13
1
vote
1 answer

Unexpected token while using EnumSet

I'm using HERE MAPS SDK PREMIUM V3.18.3 and I'm trying to get truck routing with routeOptions.truckShippedHazardousGoods = RouteOptions.HazardousGoodType.COMBUSTIBLE This gives an error stating: Type…
1
vote
1 answer

How to invoke EnumSet#(all|none)Of with a Class?

I need to invoke EnumSet#nonOf or EnumSet#allOf with an unknown type of class. @Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { final EnumSetOfAll annotation =…
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
1
vote
1 answer

Best initializing for an EnumSet holded by instance of E

I'm coping with some work regarding places where I used some unsafe (no type safety) String or int representations of part of the model., and leveraging Enum and EnumSet best practices. One particular difficulty is this use case : an Enum where…
1
vote
1 answer

Using enumset in Guava's joiner

I am working on converting an enumset into a string of values that are in the enumset. At the moment, I am using Joiner.on(',').join(enumset)) to create a string of values. However, I am wondering what are the ordering guarantees that enumset…
gmemon
  • 2,573
  • 5
  • 32
  • 37
1
vote
1 answer

Java EnumSet Syntax Assistance

I am just starting to learn Java and I'm working through a simple application that works with a deck of cards. Currently, I'm trying to instantiate a Suit class with an enum. I wanted to use the EnumSet functionality, but I'm really having trouble…
Jeff
  • 689
  • 1
  • 5
  • 23
1
vote
1 answer

Hibernate Enum Set Error

I have a Role object which holds several permissions(which are ENUM). But i keep getting this error. Use of @OneToMany or @ManyToMany targeting an unmapped class: objects.Role.permissions[enums.AgentPermission] What is the best way to…
1
vote
2 answers

Java: EnumSet.copyOf -- is there a room for improvement?

I need to create an EnumSet from a Set. I decided to use the EnumSet#copyOf method. However, because of a restriction on this method: the specified collection must contain at least one element (in order to determine the new enum set's element…
Kedar Mhaswade
  • 4,535
  • 2
  • 25
  • 34