public static JsArrayBoolean fromBooleans(Collection<Boolean> collection) { JsArrayBoolean array = JsArrayBoolean.createArray().cast(); for(Boolean item : collection) { array.push(item); } return array; }
public static List<Boolean> toList(JsArrayBoolean array) { List<Boolean> list = new ArrayList<>(); if(array != null) { for (int i = 0; i < array.length(); i++) { list.add(array.get(i)); } } return list; }
public static JsArrayBoolean fromArray(boolean... values) { if (GWT.isScript()) { return reinterpretCast(values); } else { JsArrayBoolean ret = JavaScriptObject.createArray().cast(); for (int i = 0, l = values.length; i < l; i++) { ret.set(i, values[i]); } return ret; } }
public static boolean[] toArray(JsArrayBoolean values) { if (GWT.isScript()) { return reinterpretCast(values); } else { int length = values.length(); boolean[] ret = new boolean[length]; for (int i = 0, l = length; i < l; i++) { ret[i] = values.get(i); } return ret; } }
/** * Wraps a Java boolean Array to a JsArrayBoolean for dev mode. * * @param srcArray the array to wrap * @return the wrapped array */ public static JsArrayBoolean wrapArray(boolean[] srcArray) { JsArrayBoolean result = JavaScriptObject.createArray().cast(); for (int i = 0; i < srcArray.length; i++) { result.set(i, srcArray[i]); } return result; }
/** * Wraps a Java boolean Array to a JsArrayBoolean. * * @param srcArray the array to wrap * @return the wrapped array */ public static JsArrayBoolean wrapArray(boolean[] srcArray) { if (GWT.isScript()) { return arrayAsJsArrayForProdMode(srcArray); } JsArrayBoolean result = JavaScriptObject.createArray().cast(); for (int i = 0; i < srcArray.length; i++) { result.set(i, srcArray[i]); } return result; }
public JsArrayIterator(JsArrayBoolean array) { this((JavaScriptObject) array); }
private static native JsArrayBoolean reinterpretCast(boolean[] value) /*-{ return value; }-*/;
private static native boolean[] reinterpretCast(JsArrayBoolean value) /*-{ return value; }-*/;
/** * Sorts a JsArray of booleans. * * @param sortMe Array to be sorted. * @param comparator Comparator to be used, per native JS sort() method. */ public static native void sort(JsArrayBoolean sortMe, JavaScriptObject comparator) /*-{ sortMe.sort(comparator); }-*/;
/** * Does the trick for production mode. In production mode, a JavaScript array is used for Java * arrays. So we can directly use the array as JsArray. MUST NOT be called in dev mode. * * @param array the array to get the JsArray for * @return an equivalent JsArray */ private static native JsArrayBoolean arrayAsJsArrayForProdMode(boolean[] array) /*-{ return array; }-*/;