File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to use Enum for Range Comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to use Enum for Range Comparison" Watch "How to use Enum for Range Comparison" New topic
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
    
    4
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?
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to use Enum for Range Comparison
 
Similar Threads
How to handle enums ?
Downloading and saving/opening a file
parseInt problem
Unable to match database value with string
Tiger enums....