aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManolo Carrasco <manolo@apache.org>2011-04-18 12:06:26 +0000
committerManolo Carrasco <manolo@apache.org>2011-04-18 12:06:26 +0000
commit490fba6318f27fc5cc48ae1990c09980fc1ef6b4 (patch)
treefee18fddf991ca6807cd37e150094f8336ac5ea3
parenta6921323279ffd15a3d2d16efb6286632e2d5743 (diff)
downloadgwtquery-490fba6318f27fc5cc48ae1990c09980fc1ef6b4.tar.gz
gwtquery-490fba6318f27fc5cc48ae1990c09980fc1ef6b4.zip
Remove HashMap and HashSet dependencies
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java3
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java4
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsObjectArray.java4
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java9
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java54
5 files changed, 38 insertions, 36 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java
index 351e2bd3..dde46218 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java
@@ -47,4 +47,7 @@ final public class JsMap<S, T> extends JavaScriptObject {
return c().keys();
}
+ public static <S, T> JsMap<S, T> create() {
+ return createObject().cast();
+ }
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java
index 92ca43b9..8aa538cf 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java
@@ -55,6 +55,10 @@ final public class JsNamedArray<T> extends JavaScriptObject {
return c().exists(key);
}
+ public final void delete(String key){
+ c().delete(key);
+ }
+
public final static <T> JsNamedArray<T> create() {
return createObject().cast();
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsObjectArray.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsObjectArray.java
index 88e37ba0..bc6768cf 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsObjectArray.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsObjectArray.java
@@ -44,8 +44,8 @@ public final class JsObjectArray<T> extends JavaScriptObject {
}
@SuppressWarnings("unchecked")
- public T get(int hashCode) {
- return (T)c().get(hashCode);
+ public T get(int index) {
+ return (T)c().get(index);
}
public int length() {
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java
index 103ae863..d3c3f019 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java
@@ -15,8 +15,6 @@
*/
package com.google.gwt.query.client.js;
-import java.util.HashSet;
-
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.dom.client.Element;
@@ -101,11 +99,12 @@ public class JsUtils {
*/
public static JsArray<Element> unique(JsArray<Element> a) {
JsArray<Element> ret = JavaScriptObject.createArray().cast();
- HashSet<Integer> f = new HashSet<Integer>();
+ JsCache cache = JsCache.create();
for (int i = 0; i < a.length(); i++) {
Element e = a.get(i);
- if (!f.contains(e.hashCode())) {
- f.add(e.hashCode());
+ int id = e.hashCode();
+ if (!cache.exists(id)) {
+ cache.put(id, true);
ret.push(e);
}
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java
index 27b34f37..9c15ec37 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java
@@ -17,16 +17,13 @@ package com.google.gwt.query.client.plugins.events;
import static com.google.gwt.query.client.GQuery.$;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import com.google.gwt.core.client.Duration;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.query.client.Function;
+import com.google.gwt.query.client.js.JsCache;
+import com.google.gwt.query.client.js.JsMap;
import com.google.gwt.query.client.js.JsNamedArray;
import com.google.gwt.query.client.js.JsObjectArray;
import com.google.gwt.user.client.DOM;
@@ -92,21 +89,21 @@ public class EventsListener implements EventListener {
*/
private static class LiveBindFunction extends BindFunction {
- Map<String, List<BindFunction>> bindFunctionBySelector;
+
+ JsNamedArray<JsObjectArray<BindFunction>> bindFunctionBySelector;
LiveBindFunction(int type, String namespace) {
-
super(type, namespace, null, null, -1);
- bindFunctionBySelector = new HashMap<String, List<BindFunction>>();
+ clean();
}
/**
* Add a {@link BindFunction} for a specific css selector
*/
public void addBindFunctionForSelector(String cssSelector, BindFunction f) {
- List<BindFunction> bindFunctions = bindFunctionBySelector.get(cssSelector);
+ JsObjectArray<BindFunction> bindFunctions = bindFunctionBySelector.get(cssSelector);
if (bindFunctions == null) {
- bindFunctions = new ArrayList<BindFunction>();
+ bindFunctions = JsObjectArray.create();
bindFunctionBySelector.put(cssSelector, bindFunctions);
}
@@ -114,7 +111,7 @@ public class EventsListener implements EventListener {
}
public void clean(){
- bindFunctionBySelector = new HashMap<String, List<BindFunction>>();
+ bindFunctionBySelector = JsNamedArray.create();
}
@Override
@@ -123,8 +120,7 @@ public class EventsListener implements EventListener {
return true;
}
- String[] selectors = bindFunctionBySelector.keySet().toArray(
- new String[0]);
+ String[] selectors = bindFunctionBySelector.keys();
// first element where the event was fired
Element eventTarget = getEventTarget(event);
@@ -148,15 +144,12 @@ public class EventsListener implements EventListener {
com.google.gwt.query.client.plugins.events.Event gqEvent = com.google.gwt.query.client.plugins.events.Event.create(event);
for (String cssSelector : realCurrentTargetBySelector.keys()) {
- List<BindFunction> bindFunctions = bindFunctionBySelector.get(cssSelector);
- if (bindFunctions == null){
- continue;
- }
-
- for (BindFunction f : bindFunctions) {
+ JsObjectArray<BindFunction> bindFunctions = bindFunctionBySelector.get(cssSelector);
+ for (int i = 0; bindFunctions != null && i < bindFunctions.length(); i++) {
+ BindFunction f = bindFunctions.get(i);
NodeList<Element> n = realCurrentTargetBySelector.get(cssSelector);
- if (n != null ) for (int i = 0; i < n.getLength(); i++) {
- Element element = n.getItem(i);
+ for (int j = 0; n != null && j < n.getLength(); j++) {
+ Element element = n.getItem(j);
gqEvent.setCurrentElementTarget(element);
boolean subResult = f.fire(gqEvent);
result &= subResult;
@@ -177,7 +170,7 @@ public class EventsListener implements EventListener {
* Remove the BindFunction associated to this cssSelector
*/
public void removeBindFunctionForSelector(String cssSelector) {
- bindFunctionBySelector.remove(cssSelector);
+ bindFunctionBySelector.delete(cssSelector);
}
/**
@@ -186,13 +179,13 @@ public class EventsListener implements EventListener {
* @return
*/
public boolean isEmpty() {
- return bindFunctionBySelector.isEmpty();
+ return bindFunctionBySelector.length() == 0;
}
@Override
public String toString() {
- return "live bind function for selector "
- + bindFunctionBySelector.keySet();
+ return "live bind function for selector "
+ + bindFunctionBySelector.<JsCache>cast().tostring();
}
/**
@@ -298,7 +291,8 @@ public class EventsListener implements EventListener {
private Element element;
private JsObjectArray<BindFunction> elementEvents = JsObjectArray.createArray().cast();
- private Map<Integer, LiveBindFunction> liveBindFunctionByEventType = new HashMap<Integer, LiveBindFunction>();
+
+ private JsMap<Integer, LiveBindFunction> liveBindFunctionByEventType = JsMap.create();
private EventsListener(Element element) {
this.element = element;
@@ -348,7 +342,8 @@ public class EventsListener implements EventListener {
public void die(int eventbits, String cssSelector) {
if (eventbits == 0) {
- for (LiveBindFunction liveBindFunction : liveBindFunctionByEventType.values()) {
+ for (String k :liveBindFunctionByEventType.keys()) {
+ LiveBindFunction liveBindFunction = liveBindFunctionByEventType.<JsCache>cast().get(k);
liveBindFunction.removeBindFunctionForSelector(cssSelector);
}
} else {
@@ -457,7 +452,7 @@ public class EventsListener implements EventListener {
private void clean() {
cleanGQListeners(element);
elementEvents = JsObjectArray.createArray().cast();
- liveBindFunctionByEventType = new HashMap<Integer, LiveBindFunction>();
+ liveBindFunctionByEventType = JsMap.create();
}
private void sink() {
@@ -499,7 +494,8 @@ public class EventsListener implements EventListener {
}
public void cleanEventDelegation() {
- for (LiveBindFunction function : liveBindFunctionByEventType.values()){
+ for (String k :liveBindFunctionByEventType.keys()) {
+ LiveBindFunction function = liveBindFunctionByEventType.<JsCache>cast().get(k);
function.clean();
}
}