public boolean f(Event e) { int n = fn.length == 1 ? 0 : (click++ % fn.length); return fn[n].f(e); } });
/** * Execute a function around each object. */ public static <T> void each(T[] objects, Function f) { for (int i = 0, l = objects.length; i < l; i++) { f.f(i, objects[i]); } }
/** * Override this method for bound callbacks. */ public void f(int i, Object arg) { f(i, new Object[] {arg}); }
/** * Execute a function around each object. */ public static <T> void each(List<T> objects, Function f) { for (int i = 0, l = objects.size(); i < l; i++) { f.f(i, objects.get(i)); } }
/** * Override this method for bound event handlers. * * @return boolean false means stop propagation and prevent default */ public boolean f(Event e) { setEvent(e); f(element); return true; }
/** * Override this method for bound callbacks. */ public Object f(Object... args) { setArguments(args); f(); return true; }
/** * Pass each element in the current matched set through a function, producing a new array * containing the return values. When the call to the function returns a null it is not added to * the array. */ public <W> List<W> map(Function f) { ArrayList<W> ret = new ArrayList<W>(); int i = 0; for (Element e : elements) { @SuppressWarnings("unchecked") W o = (W) f.f(e.<com.google.gwt.dom.client.Element> cast(), i++); if (o != null) { ret.add(o); } } return ret; }
/** * Methods fe(...) should be used from asynchronous contexts so as we can * catch the exception and send it to the GWT UncaughtExceptionHandler * They are intentionally final to avoid override them. */ public final boolean fe(Event ev, Object... args) { if (GWT.getUncaughtExceptionHandler() != null) { try { return f(ev, args); } catch (Exception e) { GWT.getUncaughtExceptionHandler().onUncaughtException(e); } return true; } return f(ev, args); }
@SuppressWarnings({"unchecked", "rawtypes"}) private boolean run(Object c, Object... o) { // Unbox array inside array when there is only an element. // It happens when running filters in Promise.then() if (o != null && o.length == 1 && o[0] != null && o[0].getClass().isArray()) { o = (Object[]) o[0]; } if (c instanceof Callback) { return ((Callback) c).f(o); } else if (c instanceof Function) { Object r = ((Function) c).f(o); return (r instanceof Boolean) ? (Boolean) r : true; } else if (c instanceof com.google.gwt.core.client.Callback) { ((com.google.gwt.core.client.Callback) c).onSuccess(o); } return true; }
/** * Execute a function around each object. */ public static void each(JsArrayMixed objects, Function f) { for (int i = 0, l = objects.length(); i < l; i++) { f.f(i, objects.getObject(i)); } }
/** * Override this for GQuery methods which take a callback and do not expect a * return value. * * @param e takes a com.google.gwt.dom.client.Element */ public void f(com.google.gwt.dom.client.Element e) { setElement(e); // This has to be the order of calls f(e.<com.google.gwt.user.client.Element> cast()); }
/** * Override this method for bound event handlers if you wish to deal with * per-handler user data. * * @return boolean false means stop propagation and prevent default */ public boolean f(Event e, Object... arg) { setArguments(arg); setEvent(e); return f(e); }
protected static void trigger(GwtEvent<?> e, Function callback, Element element, HasHandlers handlerManager) { if (handlerManager != null && e != null) { handlerManager.fireEvent(e); } if (callback != null) { callback.f(element.<com.google.gwt.dom.client.Element> cast()); } }
private void callHandlers(Element e, NativeEvent evt, Function... functions) { for (Function f : functions) { f.setEvent(Event.as(evt)); f.f(e); } } }
private static Promise makePromise(final Object o) { if (o instanceof Promise) { return (Promise) o; } else if (o instanceof Function) { return makePromise(((Function) o).f(new Object[0])); } else if (o instanceof GQuery) { return ((GQuery) o).promise(); } else { return new PromiseFunction() { public void f(Deferred dfd) { dfd.resolve(o); } }; } }
/** * Set a single property to a computed value, on all matched elements. */ public GQuery attr(String key, Function closure) { int i = 0; for (Element e : elements) { Object val = closure.f(e.<com.google.gwt.dom.client.Element> cast(), i++); $(e).attr(key, val); } return this; }
/** * Override this for GQuery methods which loop over matched elements and * invoke a callback on each element. * * @param e takes a com.google.gwt.dom.client.Element. * */ public Object f(com.google.gwt.dom.client.Element e, int i) { setElement(e); setIndex(i); // This has to be the order of calls return f(e.<com.google.gwt.user.client.Element> cast(), i); }
/** * Override this for GQuery methods which loop over matched widgets and * invoke a callback on each widget. * * NOTE: If your query has non-widget elements you might need to override * 'public void f()' or 'public void f(Element e)' to handle these elements and * avoid a runtime exception. */ public Object f(Widget w, int i) { setElement(w.getElement()); setIndex(i); f(w); return null; }
/** * Sets the value attribute of every matched element based in the return value of the function * evaluated for this element. * * NOTE: in jquery the function receives the arguments in different way, first index and them the * actual value, but we use the normal way in gquery Function, first the element and second the * index. */ public GQuery val(Function f) { for (int i = 0; i < size(); i++) { eq(i).val(f.f(get(i), i).toString()); } return this; }