@Test public void testGetDouble() { jsonArray.add(123d); assertEquals(Double.valueOf(123d), jsonArray.getDouble(0)); try { jsonArray.getDouble(-1); fail(); } catch (IndexOutOfBoundsException e) { jsonArray.getDouble(1); fail(); } catch (IndexOutOfBoundsException e) { assertEquals(Double.valueOf(123d), jsonArray.getDouble(1)); jsonArray.add(123); assertEquals(Double.valueOf(123d), jsonArray.getDouble(2)); jsonArray.add(123d); assertEquals(Double.valueOf(123d), jsonArray.getDouble(3)); jsonArray.add("foo"); try { jsonArray.getDouble(4); fail(); } catch (ClassCastException e) { assertNull(jsonArray.getDouble(5));
@Test public void testRemoveMethodReturnedObject() { JsonObject obj = new JsonObject(); obj.put("simple", "bar") .put("object", new JsonObject().put("name", "vert.x").put("count", 2)) .put("array", new JsonArray().add(1.0).add(2.0)); Object removed = obj.remove("missing"); assertNull(removed); removed = obj.remove("simple"); assertTrue(removed instanceof String); removed = obj.remove("object"); assertTrue(removed instanceof JsonObject); assertEquals(((JsonObject) removed).getString("name"), "vert.x"); removed = obj.remove("array"); assertTrue(removed instanceof JsonArray); assertEquals(((JsonArray) removed).getDouble(0), 1.0, 0.0); }
@Test public void testAddDouble() { assertSame(jsonArray, jsonArray.add(123d)); assertEquals(Double.valueOf(123d), jsonArray.getDouble(0)); try { jsonArray.add((Double)null); fail(); } catch (NullPointerException e) { // OK } }
@Test public void testRemoveMethodReturnedObject() { JsonArray obj = new JsonArray(); obj.add("bar") .add(new JsonObject().put("name", "vert.x").put("count", 2)) .add(new JsonArray().add(1.0).add(2.0)); Object removed = obj.remove(0); assertTrue(removed instanceof String); removed = obj.remove(0); assertTrue(removed instanceof JsonObject); assertEquals(((JsonObject) removed).getString("name"), "vert.x"); removed = obj.remove(0); assertTrue(removed instanceof JsonArray); assertEquals(((JsonArray) removed).getDouble(0), 1.0, 0.0); }
@Test public void testDecode() { byte[] bytes = TestUtils.randomByteArray(10); String strBytes = Base64.getEncoder().encodeToString(bytes); Instant now = Instant.now(); String strInstant = ISO_INSTANT.format(now); String json = "[\"foo\",123,1234,1.23,2.34,true,\"" + strBytes + "\",\"" + strInstant + "\",null,{\"foo\":\"bar\"},[\"foo\",123]]"; JsonArray arr = new JsonArray(json); assertEquals("foo", arr.getString(0)); assertEquals(Integer.valueOf(123), arr.getInteger(1)); assertEquals(Long.valueOf(1234l), arr.getLong(2)); assertEquals(Float.valueOf(1.23f), arr.getFloat(3)); assertEquals(Double.valueOf(2.34d), arr.getDouble(4)); assertEquals(true, arr.getBoolean(5)); assertArrayEquals(bytes, arr.getBinary(6)); assertEquals(Base64.getEncoder().encodeToString(bytes), arr.getValue(6)); assertEquals(now, arr.getInstant(7)); assertEquals(now.toString(), arr.getValue(7)); assertTrue(arr.hasNull(8)); JsonObject obj = arr.getJsonObject(9); assertEquals("bar", obj.getString("foo")); JsonArray arr2 = arr.getJsonArray(10); assertEquals("foo", arr2.getString(0)); assertEquals(Integer.valueOf(123), arr2.getInteger(1)); }
assertEquals(Long.valueOf(123l), jsonArray.getLong(2)); assertEquals(Float.valueOf(1.23f), jsonArray.getFloat(3)); assertEquals(Double.valueOf(1.23d), jsonArray.getDouble(4)); assertEquals(true, jsonArray.getBoolean(5)); assertArrayEquals(bytes, jsonArray.getBinary(6));
@Test public void testGetDouble() { jsonArray.add(123d); assertEquals(Double.valueOf(123d), jsonArray.getDouble(0)); try { jsonArray.getDouble(-1); fail(); } catch (IndexOutOfBoundsException e) { jsonArray.getDouble(1); fail(); } catch (IndexOutOfBoundsException e) { assertEquals(Double.valueOf(123d), jsonArray.getDouble(1)); jsonArray.add(123); assertEquals(Double.valueOf(123d), jsonArray.getDouble(2)); jsonArray.add(123d); assertEquals(Double.valueOf(123d), jsonArray.getDouble(3)); jsonArray.add("foo"); try { jsonArray.getDouble(4); fail(); } catch (ClassCastException e) { assertNull(jsonArray.getDouble(5));
@Test public void testRemoveMethodReturnedObject() { JsonObject obj = new JsonObject(); obj.put("simple", "bar") .put("object", new JsonObject().put("name", "vert.x").put("count", 2)) .put("array", new JsonArray().add(1.0).add(2.0)); Object removed = obj.remove("missing"); assertNull(removed); removed = obj.remove("simple"); assertTrue(removed instanceof String); removed = obj.remove("object"); assertTrue(removed instanceof JsonObject); assertEquals(((JsonObject) removed).getString("name"), "vert.x"); removed = obj.remove("array"); assertTrue(removed instanceof JsonArray); assertEquals(((JsonArray) removed).getDouble(0), 1.0, 0.0); }
@Test public void testAddDouble() { assertSame(jsonArray, jsonArray.add(123d)); assertEquals(Double.valueOf(123d), jsonArray.getDouble(0)); try { jsonArray.add((Double)null); fail(); } catch (NullPointerException e) { // OK } }
@Test public void testRemoveMethodReturnedObject() { JsonArray obj = new JsonArray(); obj.add("bar") .add(new JsonObject().put("name", "vert.x").put("count", 2)) .add(new JsonArray().add(1.0).add(2.0)); Object removed = obj.remove(0); assertTrue(removed instanceof String); removed = obj.remove(0); assertTrue(removed instanceof JsonObject); assertEquals(((JsonObject) removed).getString("name"), "vert.x"); removed = obj.remove(0); assertTrue(removed instanceof JsonArray); assertEquals(((JsonArray) removed).getDouble(0), 1.0, 0.0); }
@Test public void testDecode() { byte[] bytes = TestUtils.randomByteArray(10); String strBytes = Base64.getEncoder().encodeToString(bytes); Instant now = Instant.now(); String strInstant = ISO_INSTANT.format(now); String json = "[\"foo\",123,1234,1.23,2.34,true,\"" + strBytes + "\",\"" + strInstant + "\",null,{\"foo\":\"bar\"},[\"foo\",123]]"; JsonArray arr = new JsonArray(json); assertEquals("foo", arr.getString(0)); assertEquals(Integer.valueOf(123), arr.getInteger(1)); assertEquals(Long.valueOf(1234l), arr.getLong(2)); assertEquals(Float.valueOf(1.23f), arr.getFloat(3)); assertEquals(Double.valueOf(2.34d), arr.getDouble(4)); assertEquals(true, arr.getBoolean(5)); assertArrayEquals(bytes, arr.getBinary(6)); assertEquals(Base64.getEncoder().encodeToString(bytes), arr.getValue(6)); assertEquals(now, arr.getInstant(7)); assertEquals(now.toString(), arr.getValue(7)); assertTrue(arr.hasNull(8)); JsonObject obj = arr.getJsonObject(9); assertEquals("bar", obj.getString("foo")); JsonArray arr2 = arr.getJsonArray(10); assertEquals("foo", arr2.getString(0)); assertEquals(Integer.valueOf(123), arr2.getInteger(1)); }
@Override public Double getDouble(int index) { indexCheck(); return rows.get(row).getDouble(index); }
List<List<Double>> arrayList = new ArrayList<>(); JSONArray jsonArray= new JSONArray(response).getJSONArray(0); for(int i=0; i<jsonArray.length(); i++) { JsonArray nestedArray = jsonArray.get(i); List<Double> nestedList = new ArrayList<>(); for(int j=0; j< nestedArray.length(); j++) { nestedList.add(nestedArray.getDouble(j)); } arrayList.add(nestedList); }
assertEquals(Long.valueOf(123l), jsonArray.getLong(2)); assertEquals(Float.valueOf(1.23f), jsonArray.getFloat(3)); assertEquals(Double.valueOf(1.23d), jsonArray.getDouble(4)); assertEquals(true, jsonArray.getBoolean(5)); assertArrayEquals(bytes, jsonArray.getBinary(6));
@Override public double getDouble(final int columnIndex) { return orDefault(keys.getDouble(columnIndex), 0d); }
@Override public double getDouble(final int columnIndex) { return orDefault(resultSet.getResults().get(position).getDouble(columnIndex), 0d); }
@CodeTranslate public void getDouble() throws Exception { JsonArray arr = JsonTest.array; arr = JsonConverter.fromJsonArray(arr); JsonTest.o = arr.getDouble(0); }
/** * Test if query contains correct coordinates * @param jsonQuery the query * @param destination the expected coordinates */ private static void testQuery(JsonObject jsonQuery, double[] destination) { JsonArray coordinates = jsonQuery .getJsonObject("geo_shape") .getJsonObject("bbox") .getJsonObject("shape") .getJsonArray("coordinates"); JsonArray first = coordinates.getJsonArray(0); assertEquals(destination[0], first.getDouble(0), 0.0001); assertEquals(destination[1], first.getDouble(1), 0.0001); JsonArray second = coordinates.getJsonArray(1); assertEquals(destination[2], second.getDouble(0), 0.0001); assertEquals(destination[3], second.getDouble(1), 0.0001); } }