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.

I had to track down a vaguely remembered article, but another possible idea
is to use the extended features of Java enum types, which are more than
mere integers.  Java enums have a class, a type, methods, and can be
defined to implement extended behavior.  Each defined enum type (your
Vulnerability class) also has a static values() method that returns an
ordered array of all enumerable values.  This suggests dealing with the
type itself in the model, rather than treating the values like plain C/C++
integers.

The article I was looking for is here:
  <http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html>

It's linked from here:
  <http://java.sun.com/j2se/1.5.0/docs/guide/language/index.html>

I found those by searching Sun's site for these keywords:
  enum tutorial

You can probably find additional information and ideas by googling for:
  java enum tutorial

  -- 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.