com.eclipsesource.v8.V8Array.getDouble()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中com.eclipsesource.v8.V8Array.getDouble()方法的一些代码示例,展示了V8Array.getDouble()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。V8Array.getDouble()方法的具体详情如下:
包路径:com.eclipsesource.v8.V8Array
类名称:V8Array
方法名:getDouble

V8Array.getDouble介绍

[英]Returns the double value associated at this index. If the value at this index does not exist, or if it's not a double, then V8ResultUndefined exception is thrown.
[中]返回与此索引关联的双精度值。如果此索引处的值不存在,或者它不是双精度的,则会引发V8ResultUndefined异常。

代码示例

代码示例来源:origin: jooby-project/jooby

String svgPath = params.get(0).toString();
String pngPath = params.get(1).toString();
Float w = new Float(params.getDouble(2));
Float h = new Float(params.getDouble(3));
V8Function callback = (V8Function) params.get(4);
Try.run(() -> {

代码示例来源:origin: eclipsesource/J2V8

private Object getArrayItem(final V8Array array, final int index) {
  try {
    int type = array.getType(index);
    switch (type) {
      case INTEGER:
        return array.getInteger(index);
      case DOUBLE:
        return array.getDouble(index);
      case BOOLEAN:
        return array.getBoolean(index);
      case STRING:
        return array.getString(index);
      case V8_ARRAY:
      case V8_TYPED_ARRAY:
        return array.getArray(index);
      case V8_OBJECT:
        return array.getObject(index);
      case V8_FUNCTION:
        return array.getObject(index);
      case V8_ARRAY_BUFFER:
        return array.get(index);
      case UNDEFINED:
        return V8.getUndefined();
    }
  } catch (V8ResultUndefined e) {
    // do nothing
  }
  return null;
}

代码示例来源:origin: eclipsesource/J2V8

@Test(expected = UnsupportedOperationException.class)
public void testGetDoubleUndefined() {
  V8Array undefined = v8.getArray("array");
  undefined.getDouble("foo");
}

代码示例来源:origin: eclipsesource/J2V8

@Test(expected = UnsupportedOperationException.class)
public void testGetDoubleIndexUndefined() {
  V8Array undefined = v8.getArray("array");
  undefined.getDouble(7);
}

代码示例来源:origin: eclipsesource/J2V8

/*** Get Double ***/
@Test
public void testArrayGetDouble() {
  V8Array array = v8.executeArrayScript("[3.1,4.2,5.3];");
  assertEquals(3.1, array.getDouble(0), 0.00001);
  assertEquals(4.2, array.getDouble(1), 0.00001);
  assertEquals(5.3, array.getDouble(2), 0.00001);
  array.close();
}

代码示例来源:origin: eclipsesource/J2V8

@Test(expected = V8ResultUndefined.class)
public void testArrayGetDoubleWrongType() {
  V8Array array = v8.executeArrayScript("['string'];");
  try {
    array.getDouble(0);
  } finally {
    array.close();
  }
}

代码示例来源:origin: eclipsesource/J2V8

@Test(expected = V8ResultUndefined.class)
public void testArrayGetDoubleIndexOutOfBounds() {
  V8Array array = v8.executeArrayScript("[];");
  try {
    array.getDouble(0);
  } finally {
    array.close();
  }
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testAddDouble() {
  V8Array array = new V8Array(v8);
  array.push(1.1);
  array.push(2.2);
  array.push(3.3);
  array.push(4.9);
  assertEquals(4, array.length());
  assertEquals(1.1, array.getDouble(0), 0.000001);
  assertEquals(2.2, array.getDouble(1), 0.000001);
  assertEquals(3.3, array.getDouble(2), 0.000001);
  assertEquals(4.9, array.getDouble(3), 0.000001);
  array.close();
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testGetTypedArrayType64BitFloatValue() {
  V8Array result = (V8Array) v8.executeScript("var buf = new ArrayBuffer(8); var floats = new Float64Array(buf); floats[0] = 255.5; floats");
  assertEquals(255.5, result.getDouble(0), 0.00001);
  result.close();
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testGetTypedArrayType32BitFloatValue() {
  V8Array result = (V8Array) v8.executeScript("var buf = new ArrayBuffer(4); var floats = new Float32Array(buf); floats[0] = 255.5; floats");
  assertEquals(255.5, result.getDouble(0), 0.00001);
  result.close();
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testAddTypedArrayFloat() {
  V8Array array = (V8Array) v8.executeScript("var buf = new ArrayBuffer(8); var floats = new Float32Array(buf); floats");
  array.add("0", 7.7);
  array.add("1", 17.7);
  assertEquals(2, array.length());
  assertEquals(7.7, array.getDouble(0), 0.000001);
  assertEquals(17.7, array.getDouble(1), 0.000001);
  array.close();
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testArrayGetDoubleChangeValue() {
  V8Array array = v8.executeArrayScript("foo = []; foo;");
  v8.executeVoidScript("foo[0] = 3.14159");
  assertEquals(3.14159, array.getDouble(0), 0.000001);
  array.close();
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testPushDouble() {
  V8Array array = new V8Array(v8);
  V8ObjectUtils.pushValue(v8, array, 7.8);
  assertEquals(7.8, array.getDouble(0), 0.000001);
  array.close();
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testUseCustomByteBuffer_Float32Array() {
  ByteBuffer byteBuffer = ByteBuffer.allocateDirect(8);
  V8ArrayBuffer buffer = new V8ArrayBuffer(v8, byteBuffer);
  v8.add("buf", buffer);
  V8Array array = (V8Array) v8.executeScript("var floats = new Float32Array(buf); floats");
  buffer.putFloat(0, 7.7f);
  buffer.putFloat(4, 17.7f);
  assertEquals(2, array.length());
  assertEquals(7.7, array.getDouble(0), 0.000001);
  assertEquals(17.7, array.getDouble(1), 0.000001);
  array.close();
  buffer.close();
}

代码示例来源:origin: eclipsesource/J2V8

private Object getArrayItem(final V8Array array, final int index) {
  try {
    int type = array.getType(index);
    switch (type) {
      case INTEGER:
        return array.getInteger(index);
      case DOUBLE:
        return array.getDouble(index);
      case BOOLEAN:
        return array.getBoolean(index);
      case STRING:
        return array.getString(index);
      case V8_ARRAY:
      case V8_TYPED_ARRAY:
        return array.getArray(index);
      case V8_OBJECT:
        return array.getObject(index);
      case V8_FUNCTION:
        return array.getObject(index);
      case V8_ARRAY_BUFFER:
        return array.get(index);
      case UNDEFINED:
        return V8.getUndefined();
    }
  } catch (V8ResultUndefined e) {
    // do nothing
  }
  return null;
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testAddTypedArrayFloatToBackingStore() {
  V8ArrayBuffer buffer = new V8ArrayBuffer(v8, 8);
  v8.add("buf", buffer);
  V8Array array = (V8Array) v8.executeScript("var floats = new Float32Array(buf); floats");
  buffer.putFloat(0, 7.7f);
  buffer.putFloat(4, 17.7f);
  assertEquals(2, array.length());
  assertEquals(7.7, array.getDouble(0), 0.000001);
  assertEquals(17.7, array.getDouble(1), 0.000001);
  array.close();
  buffer.close();
}

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testGetArrayElementFromProperties() {
  V8Array v8Array = new V8Array(v8);
  v8Array.push("1").push(2).push(3.3);
  String result1 = v8Array.getString("0");
  int result2 = v8Array.getInteger("1");
  double result3 = v8Array.getDouble("2");
  assertEquals("1", result1);
  assertEquals(2, result2);
  assertEquals(3.3, result3, 0.000001);
  v8Array.close();
}

代码示例来源:origin: eclipsesource/J2V8

/**** Mixed Array ****/
@Test
public void testMixedArray() {
  V8Array array = v8.executeArrayScript("['a', 3, 3.1, true];");
  assertEquals(4, array.length());
  assertEquals("a", array.getString(0));
  assertEquals(3, array.getInteger(1));
  assertEquals(3.1, array.getDouble(2), 0.00001);
  assertTrue(array.getBoolean(3));
  array.close();
}

代码示例来源:origin: com.eclipsesource.j2v8/j2v8_macosx_x86_64

private Object getArrayItem(final V8Array array, final int index) {
  try {
    int type = array.getType(index);
    switch (type) {
      case INTEGER:
        return array.getInteger(index);
      case DOUBLE:
        return array.getDouble(index);
      case BOOLEAN:
        return array.getBoolean(index);
      case STRING:
        return array.getString(index);
      case V8_ARRAY:
      case V8_TYPED_ARRAY:
        return array.getArray(index);
      case V8_OBJECT:
        return array.getObject(index);
      case V8_FUNCTION:
        return array.getObject(index);
      case V8_ARRAY_BUFFER:
        return array.get(index);
      case UNDEFINED:
        return V8.getUndefined();
    }
  } catch (V8ResultUndefined e) {
    // do nothing
  }
  return null;
}

代码示例来源:origin: com.eclipsesource.j2v8/j2v8_win32_x86_64

private Object getArrayItem(final V8Array array, final int index) {
  try {
    int type = array.getType(index);
    switch (type) {
      case INTEGER:
        return array.getInteger(index);
      case DOUBLE:
        return array.getDouble(index);
      case BOOLEAN:
        return array.getBoolean(index);
      case STRING:
        return array.getString(index);
      case V8_ARRAY:
      case V8_TYPED_ARRAY:
        return array.getArray(index);
      case V8_OBJECT:
        return array.getObject(index);
      case V8_FUNCTION:
        return array.getObject(index);
      case V8_ARRAY_BUFFER:
        return array.get(index);
      case UNDEFINED:
        return V8.getUndefined();
    }
  } catch (V8ResultUndefined e) {
    // do nothing
  }
  return null;
}

相关文章