aspose file tools*
The moose likes Beginning Java and the fly likes mapping entire classes of enums Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "mapping entire classes of enums " Watch "mapping entire classes of enums " New topic
Author

mapping entire classes of enums

Stuart Rogers
Ranch Hand

Joined: Oct 02, 2008
Posts: 133
I'd like to build an hardware interface device that sits between
two game controllers and maps controller buttons based on which
game is to be played. So the device will run some java app where
I've statically coded all the mappings. There's one mapping for
each controller (EnumTGC and EnumPGC) and multiple
controller:controller mappings. Also, multiple games can use the
same controller:controller mapping but one game can only use one
controller:controller mapping. So....

so far so good. but here I run into trouble

when combined with the executable


Does that make sense? Overall idea here is the user will select which game is to be played
(hardcoded here to shrink the problem) and the associated controller:controller mapping gets used.

As always, all help/suggestions/advice/constructive criticism are all welcome,

TIA,

Still-learning Steve
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3379
    
    9
Hi Stuart,

Maybe the following example is useful for you. I have replaced EnumTGC and EnumPGC with interfaces with the more descriptive names Command and Button.

The point is that eventually all your games should care about is some mapping from Buttons to Commands. We can use the following type for this:
If your game detects that a certain button is pushed, it can easily look up the associated command like so:
Here's how it would look:
Stuart Rogers
Ranch Hand

Joined: Oct 02, 2008
Posts: 133
Genius! I thought the EnumMap might be of help but have not worked with it before. I'll give it a try.

Thanks for your help!!

CASE CLOSED

Still-learning Steve
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3379
    
    9
Note that you're programming to an interface, so it doesn't really matter whether you use a HashMap or an EnumMap. EnumMaps are just slightly more efficient than HashMaps are.
 
Consider Paul's rocket mass heater.
 
subject: mapping entire classes of enums
 
Similar Threads
Use of enum
Map Problem
HashMap entries with duplicate keys...
maps of classes of enums
sendRedirect with passing some values.