From: Artur Signell Date: Tue, 20 Mar 2012 08:37:54 +0000 (+0200) Subject: Added generics to KeyMapper and made it based on HashMap instead of X-Git-Tag: 7.0.0.alpha2~277 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=eece939c47a93870d0b536ae6e7e79022f22289d;p=vaadin-framework.git Added generics to KeyMapper and made it based on HashMap instead of Hashtable --- diff --git a/src/com/vaadin/event/ActionManager.java b/src/com/vaadin/event/ActionManager.java index 13496c1deb..f362eb6c0a 100644 --- a/src/com/vaadin/event/ActionManager.java +++ b/src/com/vaadin/event/ActionManager.java @@ -37,7 +37,7 @@ public class ActionManager implements Action.Container, Action.Handler, protected HashSet actionHandlers = null; /** Action mapper */ - protected KeyMapper actionMapper = null; + protected KeyMapper actionMapper = null; protected Component viewer; @@ -151,7 +151,7 @@ public class ActionManager implements Action.Container, Action.Handler, * removed but still exist on client side */ if (!actions.isEmpty() || clientHasActions) { - actionMapper = new KeyMapper(); + actionMapper = new KeyMapper(); paintTarget.addVariable(viewer, "action", ""); paintTarget.startTag("actions"); @@ -195,7 +195,7 @@ public class ActionManager implements Action.Container, Action.Handler, public void handleActions(Map variables, Container sender) { if (variables.containsKey("action") && actionMapper != null) { final String key = (String) variables.get("action"); - final Action action = (Action) actionMapper.get(key); + final Action action = actionMapper.get(key); final Object target = variables.get("actiontarget"); if (action != null) { handleAction(action, sender, target); diff --git a/src/com/vaadin/terminal/KeyMapper.java b/src/com/vaadin/terminal/KeyMapper.java index d44cd0de3a..3f19692ef1 100644 --- a/src/com/vaadin/terminal/KeyMapper.java +++ b/src/com/vaadin/terminal/KeyMapper.java @@ -5,7 +5,7 @@ package com.vaadin.terminal; import java.io.Serializable; -import java.util.Hashtable; +import java.util.HashMap; /** * KeyMapper is the simple two-way map for generating textual keys @@ -16,14 +16,13 @@ import java.util.Hashtable; * @VERSION@ * @since 3.0 */ -@SuppressWarnings("serial") -public class KeyMapper implements Serializable { +public class KeyMapper implements Serializable { private int lastKey = 0; - private final Hashtable objectKeyMap = new Hashtable(); + private final HashMap objectKeyMap = new HashMap(); - private final Hashtable keyObjectMap = new Hashtable(); + private final HashMap keyObjectMap = new HashMap(); /** * Gets key for an object. @@ -31,7 +30,7 @@ public class KeyMapper implements Serializable { * @param o * the object. */ - public String key(Object o) { + public String key(V o) { if (o == null) { return "null"; @@ -58,8 +57,7 @@ public class KeyMapper implements Serializable { * the name with the desired value. * @return the object with the key. */ - public Object get(String key) { - + public V get(String key) { return keyObjectMap.get(key); } @@ -69,7 +67,7 @@ public class KeyMapper implements Serializable { * @param removeobj * the object to be removed. */ - public void remove(Object removeobj) { + public void remove(V removeobj) { final String key = objectKeyMap.get(removeobj); if (key != null) { diff --git a/src/com/vaadin/ui/AbstractSelect.java b/src/com/vaadin/ui/AbstractSelect.java index 6a6c452896..defe6e9a86 100644 --- a/src/com/vaadin/ui/AbstractSelect.java +++ b/src/com/vaadin/ui/AbstractSelect.java @@ -205,7 +205,7 @@ public abstract class AbstractSelect extends AbstractField implements /** * Keymapper used to map key values. */ - protected KeyMapper itemIdMapper = new KeyMapper(); + protected KeyMapper itemIdMapper = new KeyMapper(); /** * Item icons. diff --git a/src/com/vaadin/ui/TabSheet.java b/src/com/vaadin/ui/TabSheet.java index d614832cd2..974a039fee 100644 --- a/src/com/vaadin/ui/TabSheet.java +++ b/src/com/vaadin/ui/TabSheet.java @@ -84,7 +84,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, * Mapper between server-side component instances (tab contents) and keys * given to the client that identify tabs. */ - private final KeyMapper keyMapper = new KeyMapper(); + private final KeyMapper keyMapper = new KeyMapper(); /** * When true, the tab selection area is not displayed to the user. @@ -658,12 +658,11 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, @Override public void changeVariables(Object source, Map variables) { if (variables.containsKey("selected")) { - setSelectedTab((Component) keyMapper.get((String) variables - .get("selected"))); + setSelectedTab(keyMapper.get((String) variables.get("selected"))); } if (variables.containsKey("close")) { - final Component tab = (Component) keyMapper.get((String) variables - .get("close")); + final Component tab = keyMapper + .get((String) variables.get("close")); if (tab != null) { closeHandler.onTabClose(this, tab); } diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 52981b875f..079082cc25 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -349,7 +349,7 @@ public class Table extends AbstractSelect implements Action.Container, /** * Keymapper for column ids. */ - private final KeyMapper columnIdMap = new KeyMapper(); + private final KeyMapper columnIdMap = new KeyMapper(); /** * Holds visible column propertyIds - in order. @@ -451,7 +451,7 @@ public class Table extends AbstractSelect implements Action.Container, /** * Action mapper. */ - private KeyMapper actionMapper = null; + private KeyMapper actionMapper = null; /** * Table cell editor factory. @@ -2595,7 +2595,7 @@ public class Table extends AbstractSelect implements Action.Container, (String) variables.get("action"), ","); if (st.countTokens() == 2) { final Object itemId = itemIdMapper.get(st.nextToken()); - final Action action = (Action) actionMapper.get(st.nextToken()); + final Action action = actionMapper.get(st.nextToken()); if (action != null && (itemId == null || containsId(itemId)) && actionHandlers != null) { @@ -3605,7 +3605,7 @@ public class Table extends AbstractSelect implements Action.Container, if (actionHandlers == null) { actionHandlers = new LinkedList(); - actionMapper = new KeyMapper(); + actionMapper = new KeyMapper(); } if (!actionHandlers.contains(actionHandler)) { diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java index 619f722e23..499fe9d63f 100644 --- a/src/com/vaadin/ui/Tree.java +++ b/src/com/vaadin/ui/Tree.java @@ -81,7 +81,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, /** * Action mapper. */ - private KeyMapper actionMapper = null; + private KeyMapper actionMapper = null; /** * Is the tree selectable on the client side. @@ -448,7 +448,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, (String) variables.get("action"), ","); if (st.countTokens() == 2) { final Object itemId = itemIdMapper.get(st.nextToken()); - final Action action = (Action) actionMapper.get(st.nextToken()); + final Action action = actionMapper.get(st.nextToken()); if (action != null && (itemId == null || containsId(itemId)) && actionHandlers != null) { for (Handler ah : actionHandlers) { @@ -1027,7 +1027,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, if (actionHandlers == null) { actionHandlers = new LinkedList(); - actionMapper = new KeyMapper(); + actionMapper = new KeyMapper(); } if (!actionHandlers.contains(actionHandler)) { diff --git a/tests/server-side/com/vaadin/tests/server/TestKeyMapper.java b/tests/server-side/com/vaadin/tests/server/TestKeyMapper.java index ca33cf3314..ca8ec763c2 100644 --- a/tests/server-side/com/vaadin/tests/server/TestKeyMapper.java +++ b/tests/server-side/com/vaadin/tests/server/TestKeyMapper.java @@ -10,7 +10,7 @@ import com.vaadin.terminal.KeyMapper; public class TestKeyMapper extends TestCase { public void testAdd() { - KeyMapper mapper = new KeyMapper(); + KeyMapper mapper = new KeyMapper(); Object o1 = new Object(); Object o2 = new Object(); Object o3 = new Object(); @@ -41,7 +41,7 @@ public class TestKeyMapper extends TestCase { } public void testRemoveAll() { - KeyMapper mapper = new KeyMapper(); + KeyMapper mapper = new KeyMapper(); Object o1 = new Object(); Object o2 = new Object(); Object o3 = new Object(); @@ -58,7 +58,7 @@ public class TestKeyMapper extends TestCase { } public void testRemove() { - KeyMapper mapper = new KeyMapper(); + KeyMapper mapper = new KeyMapper(); Object o1 = new Object(); Object o2 = new Object(); Object o3 = new Object(); @@ -82,7 +82,7 @@ public class TestKeyMapper extends TestCase { } - private void assertSize(KeyMapper mapper, int i) { + private void assertSize(KeyMapper mapper, int i) { try { Field f1 = KeyMapper.class.getDeclaredField("objectKeyMap"); Field f2 = KeyMapper.class.getDeclaredField("keyObjectMap");