| Author |
How to use Enum for Range Comparison
|
nitin pai
Ranch Hand
Joined: May 30, 2006
Posts: 185
|
|
I would like to know how to use Enums in this case: I have to make a range comparison and I think Enums might be helpful here but not sure how to implement it. I want something like this (functionally): Enum STATUS{ STATUS1 (10,20), STATUS2 (20,30) } while in the program i need a call as this: int value = STATUS(12).getStatus(); //12 lies in the range 10 to 20 I should get the value as STATUS1. Is it possible to do so? Please show me how can this be done?
|
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
Yes, it can be done, but it looks awkward. You would have to add a constructor to your enum members, with max and min in, then getMax and getMin methods, then find some way of checking against each member of the enumerated type. Is that really what enumerated types were designed for? It doesn't look like good programming to me. Have you read the Java Tutorials? Or the links in this recent thread?
|
 |
 |
|
|
subject: How to use Enum for Range Comparison
|
|
|