7
votes
4answers
521 views

An enum that has situationally invalid entries

Is it considered bad style to have that BOTH value in the Direction enum? Problems can arise from ...
3
votes
1answer
40 views

An attempt to extend an enum to prevent branching without violating the Open-Closed principle

I love making utility State enums, and giving them methods that do useful things based on which instance of the enum is provided. This works when the enum is very specific to the class I'm working on, ...
12
votes
4answers
434 views

Enum with getting subset

I just wrote this but I'm not sure if this is good practice. Can someone give me advice as to whether it's good or how I can do better or even it's bad code? The point is that I need a sub ...
4
votes
1answer
55 views

“Agenda” test application for Enum

I'm still new in Java so I always try to find new ways and improve my skills. I found enum in Java to be very powerful (maybe excessively?) and while I was reading ...
12
votes
5answers
830 views

Java enum containing a hash map for look up

I have the below enum. I need to get the description by code. It is working but can it be improved still? ...
7
votes
4answers
223 views

Saving enum value using name()

Let's assume I have an enum type enum ComponentState { TURNED_OFF, TURNED_ON, SUSPENDED, TO_REPAIR; } This enum describes a state of some ...
9
votes
5answers
621 views

Direction enum class

As request of Simon's comment: Direction.java ...
3
votes
2answers
240 views

Validating an input string against some enum fields

I have this enum below ...
5
votes
1answer
63 views

One-line initialisation for a constant list with all entries except one from another list

I'm looking to simplify the initialisation of the second constant, preferably to just one line. Any ideas? Anything from Guava or JDK (up to 1.6) is ok to use. ...
5
votes
1answer
126 views

Critique of Cardinal Direction Enum

I'm working on a simple game in which I need to track the cardinal direction of an object. I experimented with using the enum's ordinal value, as well as using switches for the rotation, but both ...
3
votes
1answer
71 views

Critique of enum

I'm working my way through The Java Programming Language, Fourth Edition - The Java Series. This is Exercise 6.4: Expand your traffic light color enum from Exercise 6.1 on page 152 so that each ...
7
votes
4answers
400 views

Tic-Tac-Toe design

Kindly look at this code and point out design flaws or areas for improvement. I think I've done the last part right (the enum). I think the rest of the design is flawed but I am very new to ...
3
votes
1answer
147 views

Enums with different methods, useful or abuse?

I'm wondering if the way I wrote our TextHelper class is a really a proper way to do it. We have products that are interlinked in different ways and every product has multiple text fields that might ...
3
votes
2answers
2k views

Boolean flags encoded as integer implemented with EnumSet

I'm a beginner in Java so I would appreciate a review of following simple class - in fact it's my first real usage of enums. The background: I'm parsing MySQL internal client-server protocol. One of ...
5
votes
3answers
180 views

Should I design my enumeration in some way that indicates what the highest value is?

This is a subtle question about design in which I want to find the most elegant and appropriate solution. I have an enumeration representing a French card deck (see code below). With it I need to do ...