summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-03-20 10:37:54 +0200
committerArtur Signell <artur@vaadin.com>2012-03-21 15:27:50 +0200
commiteece939c47a93870d0b536ae6e7e79022f22289d (patch)
treeb6effbed05ec438a3c32c9ae796496e449f302fa
parent8ba0e099ac481384e75cd7f9a198ec361cd83cca (diff)
downloadvaadin-framework-eece939c47a93870d0b536ae6e7e79022f22289d.tar.gz
vaadin-framework-eece939c47a93870d0b536ae6e7e79022f22289d.zip
Added generics to KeyMapper and made it based on HashMap instead of
Hashtable
-rw-r--r--src/com/vaadin/event/ActionManager.java6
-rw-r--r--src/com/vaadin/terminal/KeyMapper.java16
-rw-r--r--src/com/vaadin/ui/AbstractSelect.java2
-rw-r--r--src/com/vaadin/ui/TabSheet.java9
-rw-r--r--src/com/vaadin/ui/Table.java8
-rw-r--r--src/com/vaadin/ui/Tree.java6
-rw-r--r--tests/server-side/com/vaadin/tests/server/TestKeyMapper.java8
7 files changed, 26 insertions, 29 deletions
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<Handler> actionHandlers = null;
/** Action mapper */
- protected KeyMapper actionMapper = null;
+ protected KeyMapper<Action> 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<Action>();
paintTarget.addVariable(viewer, "action", "");
paintTarget.startTag("actions");
@@ -195,7 +195,7 @@ public class ActionManager implements Action.Container, Action.Handler,
public void handleActions(Map<String, Object> 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;
/**
* <code>KeyMapper</code> 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<V> implements Serializable {
private int lastKey = 0;
- private final Hashtable<Object, String> objectKeyMap = new Hashtable<Object, String>();
+ private final HashMap<V, String> objectKeyMap = new HashMap<V, String>();
- private final Hashtable<String, Object> keyObjectMap = new Hashtable<String, Object>();
+ private final HashMap<String, V> keyObjectMap = new HashMap<String, V>();
/**
* 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<Object> implements
/**
* Keymapper used to map key values.
*/
- protected KeyMapper itemIdMapper = new KeyMapper();
+ protected KeyMapper<Object> itemIdMapper = new KeyMapper<Object>();
/**
* 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<Component> keyMapper = new KeyMapper<Component>();
/**
* 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<String, Object> 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<Object> columnIdMap = new KeyMapper<Object>();
/**
* 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<Action> 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<Handler>();
- actionMapper = new KeyMapper();
+ actionMapper = new KeyMapper<Action>();
}
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<Action> 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<Action.Handler>();
- actionMapper = new KeyMapper();
+ actionMapper = new KeyMapper<Action>();
}
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<Object> mapper = new KeyMapper<Object>();
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<Object> mapper = new KeyMapper<Object>();
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<Object> mapper = new KeyMapper<Object>();
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");