2

So here is my situation I am comparing two situations of the WallEnums to the rest of them.

import static com.gowallgo.enumtypes.WallEnums.CAW;
"" ( and the rest )


   /**
     * {@link Set} of cancel {@link WallEnums}s
     */
    private static final Set<WallEnums> WALL_CODES = asSet(RES, CAW, AAP, ASV, CQP, OQR);


// more stuff and then I use it here . 

if (wallEnum != WALL_CODES.contains(wallEnum)){}

this begs for refactoring . where should I start so I don't need to make a static import for each code ?

8
  • 1
    What do you not like? Commented Feb 10, 2015 at 16:00
  • 2
    import static com.gowallgo.enumtypes.WallEnums.* ? Commented Feb 10, 2015 at 16:01
  • 2
    Use Enum.values()? Commented Feb 10, 2015 at 16:03
  • 1
    What is this supposed to do? if (wallEnum != WALL_CODES.contains(wallEnum)){} compare an enum value to a boolean? Commented Feb 10, 2015 at 16:07
  • 1
    @tom there is not quite enough to review here Commented Feb 10, 2015 at 16:12

3 Answers 3

2

If you don't want to import every enum value you can use

import com.gowallgo.enumtypes.WallEnums

WallEnums enum = WallEnums.RES;  //Now you have to use EnumName.VALUE
Sign up to request clarification or add additional context in comments.

Comments

1

Use EnumSet:

// Do not import anything

// This creates a Set that contains all posible values
// In case you need a subset use: EnumSet.of(WallEnums.RES, WallEnums.CAW, etc)
private static final Set<WallEnums> WALL_CODES = EnumSet.allOf(WallEnums.class);

// Later...
if (WALL_CODES.contains(someWallEnum)) {
    // Do stuff if someWallEnum belongs to WALL_CODES set
}

This code creates a set of enums using optimized EnumSet class. Then you could use any Set operation as usual, i.e contains().

Comments

1

You dont have to import each enum type, You could try importing every element of enum using:

import static com.gowallgo.enumtypes.WallEnums.*;

1 Comment

The code environment does not allow imports with a star ( idk why , just one of those glitch type things ) I should have mentioned this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.