AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

enum and EnumMap as parameters?

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> comp.lang.java
View previous topic :: View next topic  
Author Message
~kurt
Guest





PostPosted: Thu Apr 12, 2007 7:10 am    Post subject: enum and EnumMap as parameters? Reply with quote



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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> comp.lang.java All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.