| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
Your objection is perfectly valid, but the main point of my code was to show you how you can write code that isn't error-prone. The technique I've applied can be adapted to your needs in many different ways without breaking MVC. There's certainly something to be said for not putting the display name in the model. You could instead use the toString() method as the resource key, and still get the resource from the resource file. But then you'd still probably need a bidirectional map. It shouldn't be hard to write one. For example: public interface ReversableMap<K, V> extends Map<K, V> { public K reverseGet(V value); } public class TwoWayMap<K, V> extends HashMap<K, V> implements ReversableMap<K, V> { private HashMap<V, K> reverseMap = new HashMap<V, K>(); TwoWayMap() { super(); } public K reverseGet(V value) { return reverseMap.get(v); } public put(K key, V value) { super.put(key, value); reverseMap.put(value, key); } // override for efficiency. public boolean containsValue(Object value) { return reverseMap.containsKey(value); } } I think that should cover it. I haven't compiled this, but it shouldn't be too hard to make it work. I'm pretty sure the default clone() method would work if you need it to, but be sure to test it if you do. On Dec 11, 2006, at 12:02 PM, email@hidden wrote:
------------------------------------------- Miguel Muñoz 323/225-7285 ------------------------------------------- The Sun, with all those planets revolving around it and dependent on it, can still ripen a vine of grapes like it had nothing else to do in the world. -- Galileo ------------------------------------------- There are seven sins in the world. Wealth without work. Pleasure without conscience. Knowledge without character. Commerce without morality. Science without humanity. Worship without sacrifice. Politics without principle. -- Mohandas Gandhi ------------------------------------------- If tyranny and oppression come to this land, it will come in the guise of fighting a foreign enemy. -- James Madison |
_______________________________________________ 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
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
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.