@Test public void getIdsShouldIncludeBothIndexAndNormalProperties() { array.put(0, array, "index"); array.put("a", array, "normal"); assertThat(array.getIds(), is(new Object[] {0, "a"})); }
private static Object[] convertArray(NativeArray jsArray, Map<Object, Boolean> identities) { Object[] ids = jsArray.getIds(); Object[] result = new Object[ids.length]; for (int i = 0; i < ids.length; i++) { Object id = ids[i]; int index = (Integer) id; Object jsValue = jsArray.get(index, jsArray); result[i] = jsToJava(jsValue, identities); } return result; }
private EventSet convertToEventSet(Object jsObject) { if (jsObject == null) return Events.emptySet; // This covers event sets AND events. if (jsObject instanceof EventSet) { return (EventSet) jsObject; } else if (jsObject instanceof NativeArray) { NativeArray arr = (NativeArray) jsObject; if (Stream.of(arr.getIds()).anyMatch(id -> arr.get(id) == null)) { throw new RuntimeException("EventSet Array contains null sets."); } return ComposableEventSet.anyOf( Arrays.asList(arr.getIndexIds()) .stream() .map(i -> (EventSet) arr.get(i)) .collect(toSet())); } else { final String errorMessage = "Cannot convert " + jsObject + " of class " + jsObject.getClass() + " to an event set"; Logger.getLogger(BThread.class.getName()).log(Level.SEVERE, errorMessage); throw new IllegalArgumentException(errorMessage); } }