enum and EnumMap as parameters?



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
.



Relevant Pages

  • Re: Whats the additional value of EnumMap ?
    ... >> As enum values can be mapped to small integers, an EnumMap might be ... >> implemented using an array. ... Or maybe not...I haven't looked at the source code. ...
    (comp.lang.java.programmer)
  • Re: Help with EnumMap
    ... HashMap's employing enum values as keys. ... I'm having trouble creating new EnumMap ... How should one invoke a constructor for a new, empty EnumMap, ... EnumMap needs the class of the enum to properly construct the map. ...
    (comp.lang.java.help)
  • Re: Passing enum and EnumMap to a method
    ... to get all the elements of an enum given an EnumMap with the enum as the ... key type. ... Map<Thread.State, String> map = ... it would be nice if EnumMap added the method Class ...
    (comp.lang.java.programmer)
  • Re: Whats the additional value of EnumMap ?
    ... > As enum values can be mapped to small integers, ... (Hmm, that's easy to check, the source ... > code for EnumMap is available. ... And yes, it uses an array:). ...
    (comp.lang.java.programmer)
  • EnumMap and jsp?
    ... I'm currently using a parallel map of Map ... Where photoSizes is the map. ... In my java code I otherwise use an enum instead of using the string thumb1, but the enum is used with a parallel EnumMap, while this photoSizes is the map. ...
    (comp.lang.java.programmer)