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
1
vote
2 answers

Mutually exclusive Enum controlled by a EnumSet

public enum TagEnum { MALE,FEMALE,//GENDER YOUNG,MIDDLE_AGED,OLD//AGE } I wanna use TagEnum to describe a Person. MALE and FEMALE are mutually exclusive, so are those enums for age. For example, once you put MALE into the EnumSet, FEMALE will…
Anderson
  • 2,496
  • 1
  • 27
  • 41
1
vote
2 answers

Same method name with EnumSet (of different type) as a parameter

I have a method A @Deprecated public void doSomething (EnumSet param){ } Now, I want to write a new method B such that it has a same signature but takes an EnumSet of different type. public void doSomething(EnumSet
user2453055
  • 975
  • 1
  • 9
  • 19
1
vote
1 answer

Force children to use enums defined within themselves

Let's say I've got a parent abstract animal trainer class: public abstract class Trainer & Trainables>{ protected EnumSet completed; public void trainingComplete(E trainable){ …
anishthecoder
  • 940
  • 6
  • 20
1
vote
2 answers

Creating an EnumSet array in Java

I am trying to create an EnumSet array (using Eclipse). Version 1: EnumSet mySet[] = new EnumSet[3]; This works, but I get a warning: "EnumSet is a raw type. References to generic type EnumSet should be parameterized". Version 2 as…
Gunnar Bernstein
  • 6,074
  • 2
  • 45
  • 67
1
vote
3 answers

Checking for either/or with an EnumSet

So I'm converting some bitfields in our application to use EnumSet instead, and I'm curious if there's a better way to do a comparison for X|Y. Currently we do something like: if(bitfield & (X | Y) != 0) { //do stuff } The EnumSet equivalent…
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
1
vote
1 answer

Generic Enum/EnumSet Troubles

I have a class and function defined as the following: public class Site { public EnumSet contents; public void determineStates(Site a, Site b) { this.contents.clear(); this.contents.addAll(a.contents); …
nimble agar
  • 417
  • 8
  • 15
1
vote
1 answer

db4o enumset exception

I'm using db4o 8.0 with transparent activation/persistence ... I have a class which contains an EnumSet (and other things). I instantiate, add an enum value into set and store. When I search in DB, get it and trying to activate the object I get this…
ApollonDigital
  • 913
  • 3
  • 15
  • 24
1
vote
1 answer

Can I restrict method parameters to only certain Enum members?

Is there a way to restrict a method to only take certain members of an enumeration. Let's say you had an enumeration of military and enlisted ranks. If I wanted a function that only could take officer ranks and another that could only take…
ggb667
  • 1,881
  • 2
  • 20
  • 44
1
vote
1 answer

How can I use enumset.contains in jsp?

I have an enum: enum DestinationTab{ Overview, ThingsTodo }; I set an enumSet in my action class based on certain conditions. On my jsp, I'd like to render only those sections which are present in this enumSet. This construct…
brainydexter
  • 19,826
  • 28
  • 77
  • 115
0
votes
2 answers

Generate enum from CSV file

My goal is to to generate an enum in order to create an EnumSet. This part works if I write the enum. Instead of writing an enum of 50000 lines, I would like to import the 50000 rows CSV. The trouble starts when I try to replace the enum I wrote by…
Apage
  • 3
  • 2
0
votes
2 answers

XOR toggle an Enum value in or out of an EnumSet

I am refactoring some code that used low-level bit manipulation and masking to reimplement it with an EnumSet. The incentive is: having a much more maintainable and readable code. I find it appropriate to abstract the logic away from low-level…
Léa Gris
  • 17,497
  • 4
  • 32
  • 41
0
votes
2 answers

Boolean value remains false after the value of the static field involved changes

In my assignment I have to use an enum to make an EnumSet of elements that fit the criteria given. So, the code needs to be as flexible as possible and allow any criteria that could be applied to the object declared in the enum. I've been testing…
Huntbook
  • 114
  • 9
0
votes
2 answers

Generics Set with Enums

Problem space has been stripped down. So I have the following interface that I cannot change. public interface ItemInterface { Set> getItems(); } I have created the Items enum class public enum Item{ ITEM1, ITEM2, ITEM3 } So when I…
Robbo_UK
  • 11,351
  • 25
  • 81
  • 117
0
votes
2 answers

EnumSet as a parameter in generic Interface

I've a use case : inteface A{ get(EnumSet fetchModes); } class B implements A{ //Here FetchMode is an enum get(EnumSet fetchMode){ //Some logic here } } But it's throwing compile time error : Method get of class B has…
Vatsal Prakash
  • 558
  • 6
  • 17
0
votes
2 answers

How to convert EnumSet to Set

I have an enum class thats something like this: enum class SomeType(val id: String) { TYPE1("A"), TYPE2("B"), TYPE3("C"), TYPE4("D") } Now, I need to filter a list of Something which has a String that's stated in SomeType enum. So…
Archie G. Quiñones
  • 11,638
  • 18
  • 65
  • 107