From: jdramaix Date: Fri, 22 Nov 2013 12:33:06 +0000 (+0100) Subject: code review part2 X-Git-Tag: release-1.4.0~30^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e81950823a5e8421ff0fa901da29daf61b6304d3;p=gwtquery.git code review part2 --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java index bdd0e26d..babf630c 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java @@ -263,7 +263,7 @@ public class Events extends GQuery { /** * Trigger a html event in all matched elements. * - * @param htmlEvent An string representing the html event desired + * @param htmlEvent A string representing the desired html event. * @functions a set of function to run if the event is not canceled. */ public Events triggerHtmlEvent(String htmlEvent, Function... functions) { @@ -273,7 +273,7 @@ public class Events extends GQuery { /** * Trigger a html event in all matched elements. * - * @param htmlEvent An string representing the html event desired + * @param htmlEvent An string representing the desired html event. * @functions a set of function to run if the event is not canceled. */ public Events triggerHtmlEvent(String htmlEvent, Object[] datas, final Function... functions) { 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 1cf84b7b..eacc9d18 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 @@ -31,6 +31,7 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.EventListener; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -136,32 +137,17 @@ public class EventsListener implements EventListener { public boolean fire(Event event, Object[] eventData) { if (times != 0) { times--; - Object[] arguments = new Object[0]; - + Object[] arguments; + eventData = eventData != null ? eventData : new Object[0]; // The argument of the function will be first the data attached to the handler then the // data attached to the event. - if (eventData != null) { - if (data != null){ - Object[] handlerData; - if (data.getClass().isArray()) { - handlerData = (Object[]) data; - } else { - handlerData = new Object[] {data}; - } - arguments = new Object[handlerData.length + eventData.length]; - int index = 0; - for (int i = 0; i < handlerData.length; i++, index++) { - arguments[index] = handlerData[i]; - } - for (int i = 0; i < eventData.length; i++, index++) { - arguments[index] = eventData[i]; - } - - } else { - arguments = eventData; - } - } else if (data != null){ - arguments = new Object[] {data}; + if (data != null) { + Object[] handlerData = data.getClass().isArray() ? (Object[]) data : new Object[]{data}; + arguments = new Object[handlerData.length + eventData.length]; + System.arraycopy(handlerData, 0, arguments, 0, handlerData.length); + System.arraycopy(eventData, 0, arguments, handlerData.length, eventData.length); + } else { + arguments = eventData; } return function.fe(event, arguments); }