File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
How to use Enum for Range Comparison
Joined: May 30, 2006
May 19, 2008 11:07:00
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):
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?
Joined: Oct 13, 2005
May 19, 2008 12:23:00
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:
subject: How to use Enum for Range Comparison
Downloading and saving/opening a file
Unable to match database value with string
How to handle enums ?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013