예제 #1
0
  @Test
  public void getIdsShouldIncludeBothIndexAndNormalProperties() {
    array.put(0, array, "index");
    array.put("a", array, "normal");

    assertThat(array.getIds(), is(new Object[] {0, "a"}));
  }
예제 #2
0
 public static Object map(Context cx, Scriptable thisObj, Object[] args, Function funObj) {
   NativeJavaObject njo = (NativeJavaObject) args[0];
   NativeArray array = (NativeArray) cx.newArray(thisObj, 0);
   Function f = (Function) args[1];
   Collection list = (Collection) njo.unwrap();
   int i = 0;
   for (Object o : list) {
     Object[] argx = {o, Context.javaToJS(i, f), njo};
     Object r = f.call(cx, thisObj, f, argx);
     array.put((int) array.getLength(), array, Context.javaToJS(r, f));
     i++;
   }
   return array;
 }
예제 #3
0
  public static Object filter(Context cx, Scriptable thisObj, Object[] args, Function funObj) {
    NativeArray array = (NativeArray) cx.newArray(thisObj, 0);
    NativeJavaObject njo = (NativeJavaObject) args[0];
    Function f = (Function) args[1];
    Collection list = (Collection) njo.unwrap();
    int i = 0;
    for (Object o : list) {
      Object[] argx = {o, i, njo};
      Object r = f.call(cx, thisObj, f, argx);
      if (r != null && r.getClass() != Undefined.class && !r.equals(false)) {
        array.put((int) array.getLength(), array, o);
      }
    }

    return array;
  }
예제 #4
0
파일: DB.java 프로젝트: o-nix/Kafra
  protected Object wrap(List<?> result) {
    Context context = Context.getCurrentContext();
    Scriptable scope = getParentScope();
    NativeArray array = (NativeArray) context.newArray(scope, result.size());
    int i = 0;

    for (Object part : result) {
      Object value = part;

      if (value instanceof ODocument) value = wrap((ODocument) part);
      else value = Context.javaToJS(value, scope);

      array.put(i, array, value);
      i++;
    }

    return array;
  }
예제 #5
0
 @Test
 public void getIndexIdsShouldIncludeIdsLessThan2ToThe32() {
   int maxIndex = (int) (1L << 31) - 1;
   array.put(maxIndex, array, "a");
   assertThat(array.getIndexIds(), is(new Integer[] {maxIndex}));
 }
예제 #6
0
 @Test
 public void getIndexIdsShouldNotIncludeNegativeIds() {
   array.put(-1, array, "a");
   assertThat(array.getIndexIds(), is(new Integer[] {}));
 }
예제 #7
0
 @Test
 public void getIndexIdsShouldWorkWhenIndicesSetAsString() {
   array.put("0", array, "a");
   assertThat(array.getIndexIds(), is(new Integer[] {0}));
 }
예제 #8
0
 @Test
 public void getIndexIdsShouldBeAZeroForSimpleSingletonArray() {
   array.put(0, array, "a");
   assertThat(array.getIndexIds(), is(new Integer[] {0}));
 }
예제 #9
0
 @Test
 public void getShouldReturnNormalProperties() {
   array.put("p", array, "a");
   assertThat((String) array.get("p", array), is("a"));
 }
예제 #10
0
 @Test
 public void putShouldAddNormalProperties() {
   array.put("p", array, "a");
   assertThat(array.has("p", array), is(true));
 }
예제 #11
0
 @Test
 public void putShouldAddIndexProperties() {
   array.put(0, array, "a");
   assertThat(array.has(0, array), is(true));
 }
예제 #12
0
 @Test
 public void deleteShouldRemoveNormalProperties() {
   array.put("p", array, "a");
   array.delete("p");
   assertThat(array.has("p", array), is(false));
 }
예제 #13
0
 @Test
 public void deleteShouldRemoveIndexProperties() {
   array.put(0, array, "a");
   array.delete(0);
   assertThat(array.has(0, array), is(false));
 }
예제 #14
0
 @Test
 public void getIndexIdsShouldNotReturnNonNumericIds() {
   array.put("x", array, "a");
   assertThat(array.getIndexIds(), is(new Integer[] {}));
 }
예제 #15
0
 @Test
 public void getIndexIdsShouldNotIncludeIdsGreaterThanOrEqualTo2ToThe32() {
   array.put((1L << 31) + "", array, "a");
   assertThat(array.getIndexIds(), is(new Integer[] {}));
 }