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



If you don't mind 3rd party libs, check out Jakarta Commons project from
Apache. Their collections extensions include a BidiMap with two
implementations to choose from!

http://jakarta.apache.org/commons/collections/

~Ethan Giordano


On 12/7/06 6:06 AM, "Helge Hartmann" <email@hidden> wrote:

> Hello!
> 
> I Have an Enum object
> 
> public enum Vulnerability {
> NONE, NORTH_SOUTH, EAST_WEST, BOTH;
> }
> 
> 
> 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.
> 
> 
> String[] vulnerability =
> {
> "keiner", "Nord-Süd", "Ost-West", "alle", "egal"
> };
> 
> public void createControl(Composite parent) {
> Composite container = new Composite(parent, SWT.NULL);
> container.setLayout(new FillLayout());
> vulCombo = new Combo(container,SWT.DROP_DOWN);
> vulCombo.setItems(vulnerability);
> 
> if(rule.getVul() == null) {
> vulCombo.setText(vulnerability[4]);
> } else {
> switch(rule.getVul()) {
> case NORTH_SOUTH: vulCombo.setText(vulnerability[0]); break;
> case EAST_WEST: vulCombo.setText(vulnerability[1]); break;
> case BOTH: vulCombo.setText(vulnerability[2]); break;
> case NONE: vulCombo.setText(vulnerability[3]); break;
> }
> }
> 
> vulCombo.setVisible(true);
> vulCombo.addSelectionListener(new SelectionAdapter() {
> @Override
> public void widgetSelected(SelectionEvent se) {
> int index = vulCombo.getSelectionIndex();
> switch(index){
> case 0: vul = Vulnerability.NONE; break;
> case 1: vul = Vulnerability.NORTH_SOUTH; break;
> case 2: vul = Vulnerability.EAST_WEST; break;
> case 3: vul = Vulnerability.NONE; break;
> case 4: vul = null;
> }
> }
> 
> });
> container.pack();
> //
> setControl(container);
> }
> 
> 
> 
> Thanks
> 
> Helge
>  _______________________________________________
> 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

 _______________________________________________
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

References: 
 >something like bidirectional Hashmaps (From: Helge Hartmann <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.