enum and EnumMap as parameters?
- From: ~kurt <actinouranium@xxxxxxxxxxxxx>
- Date: Thu, 12 Apr 2007 05:17:12 GMT
I've managed to confuse myself on this - it may be because I haven't worked
with Maps much.
I want to pass an enum and an EnumMap as a parameters.
I have a method that operates on each element of an array using a for loop.
It is a generic method, and the array could represent {x, y}, {x, y, z},
{x, y, z, dx, dy, dz}, and so on (the method solves a system of linear
differential equations and the array represents the "state" of the system).
To make it safer, and check for potential indexing errors at compile time,
I would like to make use of an enum, and an EnumMap.
For example, something like this:
enum TwoD { X, Y }
enum ThreeD { X, Y, Z }
EnumMap<ThreeD, Double> xyz =
new EnumMap<ThreeD, Double>(ThreeD.class);
xyz.put(ThreeD.X, 20.0);
xyz.put(ThreeD.Y, 10.0);
xyz.put(ThreeD.Z, 50.0);
/*
* The call to this method is conceptual - doesn't work.
*/
someMethod(xyz, ThreeD);
And, for someMethod:
/*
* Once again, just conceptual
*/
public void someMethod(EnumMap xyz, Enum D) {
/* loop on all values */
for (D d : D.values()) {
.
.
.
a = xyz.get(d);
.
.
.
}
Any suggestions on how to pass this information through the method?
Thanks,
- Kurt
.
- Prev by Date: Help with a decision
- Next by Date: Re: beginner's question
- Previous by thread: Help with a decision
- Next by thread: Re: beginner's question
- Index(es):
Relevant Pages
|