Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: something like bidirectional Hashmaps



Helge Hartmann wrote:

>Now I have a combo, where someone can choose one of these values. Because I
>don't want to use the toString() method, I have a String array, holding the
>values for the combo. But I don't have an idea how to create a good
>mapping, because it must work in both directions. At the moment I am using
>switch statements for the mapping. But this seems error prone, when
>changing something. There must be a better way.

Create a customized model that encapsulates the bi-directional mapping.
Then use that as the model behind your component.  The model class should
be composed from the behaviors, though not necessarily the API's, of
simpler classes like Map and List.

If you encapsulate all this, then the use of two Maps inside the model
object isn't externally visible.  I did something like this for the Lookup
interface in my open source Suite/P Toolkit of Posix features:
  <http://www.amug.org/~glguerin/sw/#suitep>

The concrete implementation is SimpleLookup.  It uses two Hashtables
internally, but it could easily be two Maps.  I chose Hashtable for
compatibility with Java versions that lack Map.

If you want ordering on one of the Maps, such as the names, so they can
represent a sequence of items in a combo-box, you may want to use an
ordered Map, or have some other way to manage the sequential aspect of the
model's representation.


>  case 3: vul = Vulnerability.NONE; break;

Shouldn't that be:
  vul = Vulnerability.BOTH;

  -- GG


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.