public Candlestick(JsonArray jsonArray) { super( Instant.ofEpochMilli(jsonArray.getJsonNumber(0).longValue()), jsonArray.getJsonNumber(1).bigDecimalValue(), jsonArray.getJsonNumber(2).bigDecimalValue(), jsonArray.getJsonNumber(3).bigDecimalValue(), jsonArray.getJsonNumber(4).bigDecimalValue(), jsonArray.getJsonNumber(5).bigDecimalValue() ); }
public Depth(JsonArray asks, JsonArray bids, Instant timestamp) { super(asks.stream().map(v -> { JsonArray a = (JsonArray) v; BigDecimal px = a.getJsonNumber(0).bigDecimalValue(); BigDecimal qty = a.getJsonNumber(1).bigDecimalValue(); return new BigDecimal[] { px, qty }; }).collect(Collectors.toList()).toArray(EMPTY_DEPTH), bids.stream().map(v -> { JsonArray a = (JsonArray) v; BigDecimal px = a.getJsonNumber(0).bigDecimalValue(); BigDecimal qty = a.getJsonNumber(1).bigDecimalValue(); return new BigDecimal[] { px, qty }; }).collect(Collectors.toList()).toArray(EMPTY_DEPTH)); this.timestamp = timestamp; }
/** * Converts the given JSON array to a List of Instant. * * @param array an array * @return a new List of Instant */ public static List<Instant> toListTimestamp(JsonArray array) { List<Instant> timestamps = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { timestamps.add(Instant.ofEpochSecond(array.getJsonNumber(i).longValue(), 0)); } return timestamps; }
/** * Converts the given JSON array to a List of Timestamp. * * @param array an array * @return a new List of Timestamps */ public static List<Timestamp> toListTimestamp(JsonArray array) { List<Timestamp> timestamps = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { timestamps.add(Timestamp.of(array.getJsonNumber(i).longValue(), 0)); } return timestamps; }
/** * {@inheritDoc} */ @Override public MeXBTStreamingTradeOrOrder[] decode(Reader reader) throws DecodeException, IOException { JsonReader jsonReader = Json.createReader(reader); JsonArray jsonArray = jsonReader.readArray(); MeXBTStreamingTradeOrOrder[] ret = new MeXBTStreamingTradeOrOrder[jsonArray.size()]; for (int i = 0; i < jsonArray.size(); i++) { JsonArray record = (JsonArray) jsonArray.get(i); long id = record.getJsonNumber(0).longValue(); long tick = record.getJsonNumber(1).longValue(); BigDecimal price = record.getJsonNumber(2).bigDecimalValue(); BigDecimal quantity = record.getJsonNumber(3).bigDecimalValue(); int action = record.getJsonNumber(4).intValue(); int side = record.getJsonNumber(5).intValue(); Date timestamp = new Date((tick - 621355968000000000L) / 10000); ret[i] = new MeXBTStreamingTradeOrOrder(id, timestamp, price, quantity, action, side); } return ret; }
/** * Converts the given numeric JSON array to a ListShort. * * @param array an array of numbers * @return a new ListShort */ public static ListShort toListShort(JsonArray array) { short[] values = new short[array.size()]; for (int i = 0; i < values.length; i++) { values[i] = (short) array.getJsonNumber(i).intValue(); } return new ArrayShort(values); }
/** * Converts the given numeric JSON array to a ListLong. * * @param array an array of numbers * @return a new ListLong */ public static ListLong toListLong(JsonArray array) { long[] values = new long[array.size()]; for (int i = 0; i < values.length; i++) { values[i] = (long) array.getJsonNumber(i).longValue(); } return new ArrayLong(values); }
/** * Converts the given numeric JSON array to a ListByte. * * @param array an array of numbers * @return a new ListByte */ public static ListByte toListByte(JsonArray array) { byte[] values = new byte[array.size()]; for (int i = 0; i < values.length; i++) { values[i] = (byte) array.getJsonNumber(i).intValue(); } return new ArrayByte(values); }
/** * Converts the given numeric JSON array to a ListInt. * * @param array an array of numbers * @return a new ListInt */ public static ListInt toListInt(JsonArray array) { int[] values = new int[array.size()]; for (int i = 0; i < values.length; i++) { values[i] = (int) array.getJsonNumber(i).intValue(); } return new ArrayInt(values); }
/** * Converts the given numeric JSON array to a ListLong. * * @param array an array of numbers * @return a new ListLong */ public static ListLong toListLong(JsonArray array) { long[] values = new long[array.size()]; for (int i = 0; i < values.length; i++) { values[i] = (long) array.getJsonNumber(i).longValue(); } return new ArrayLong(values); }
/** * Converts the given numeric JSON array to a ListInt. * * @param array an array of numbers * @return a new ListInt */ public static ListInt toListInt(JsonArray array) { int[] values = new int[array.size()]; for (int i = 0; i < values.length; i++) { values[i] = (int) array.getJsonNumber(i).intValue(); } return new ArrayInt(values); }
/** * Converts the given numeric JSON array to a ListShort. * * @param array an array of numbers * @return a new ListShort */ public static ListShort toListShort(JsonArray array) { short[] values = new short[array.size()]; for (int i = 0; i < values.length; i++) { values[i] = (short) array.getJsonNumber(i).intValue(); } return new ArrayShort(values); }
/** * Converts the given numeric JSON array to a ListByte. * * @param array an array of numbers * @return a new ListByte */ public static ListByte toListByte(JsonArray array) { byte[] values = new byte[array.size()]; for (int i = 0; i < values.length; i++) { values[i] = (byte) array.getJsonNumber(i).intValue(); } return new ArrayByte(values); }
/** * Converts the given numeric JSON array to a ListFloat. * * @param array an array of numbers * @return a new ListFloat */ public static ListFloat toListFloat(JsonArray array) { float[] values = new float[array.size()]; for (int i = 0; i < values.length; i++) { if (array.isNull(i)) { values[i] = Float.NaN; } else { values[i] = (float) array.getJsonNumber(i).doubleValue(); } } return new ArrayFloat(values); }
/** * Converts the given numeric JSON array to a ListDouble. * * @param array an array of numbers * @return a new ListDouble */ public static ListDouble toListDouble(JsonArray array) { double[] values = new double[array.size()]; for (int i = 0; i < values.length; i++) { if (array.isNull(i)) { values[i] = Double.NaN; } else { values[i] = array.getJsonNumber(i).doubleValue(); } } return new ArrayDouble(values); }
/** * Converts the given numeric JSON array to a ListDouble. * * @param array an array of numbers * @return a new ListDouble */ public static ListDouble toListDouble(JsonArray array) { double[] values = new double[array.size()]; for (int i = 0; i < values.length; i++) { if (array.isNull(i)) { values[i] = Double.NaN; } else { values[i] = array.getJsonNumber(i).doubleValue(); } } return new ArrayDouble(values); }
/** * Converts the given numeric JSON array to a ListFloat. * * @param array an array of numbers * @return a new ListFloat */ public static ListFloat toListFloat(JsonArray array) { float[] values = new float[array.size()]; for (int i = 0; i < values.length; i++) { if (array.isNull(i)) { values[i] = Float.NaN; } else { values[i] = (float) array.getJsonNumber(i).doubleValue(); } } return new ArrayFloat(values); }
public List<NodesTableItem> getNdbinfoNodesTable(String hostAddress, String agentPassword) throws AppException { List<NodesTableItem> resultList = new ArrayList<NodesTableItem>(); String url = createUrl("mysql", hostAddress, "ndbinfo", "nodes"); String jsonString = fetchContent(url, agentPassword); InputStream stream = new ByteArrayInputStream(jsonString.getBytes( StandardCharsets.UTF_8)); try { JsonArray json = Json.createReader(stream).readArray(); if (json.get(0).equals("Error")) { resultList.add(new NodesTableItem(null, json.getString(1), null, null, null)); return resultList; } for (int i = 0; i < json.size(); i++) { JsonArray node = json.getJsonArray(i); Integer nodeId = node.getInt(0); Long uptime = node.getJsonNumber(1).longValue(); String status = node.getString(2); Integer startPhase = node.getInt(3); Integer configGeneration = node.getInt(4); resultList.add(new NodesTableItem(nodeId, status, uptime, startPhase, configGeneration)); } } catch (Exception ex) { logger.log(Level.SEVERE, "Exception: {0}", ex); resultList.add(new NodesTableItem(null, "Error", null, null, null)); } return resultList; }
/** * Create a new Float32MultiArray based on the given JSON object. Any * missing values will be set to their defaults. * * @param jsonObject * The JSON object to parse. * @return A Float32MultiArray message based on the given JSON object. */ public static Float32MultiArray fromJsonObject(JsonObject jsonObject) { // check the layout MultiArrayLayout layout = jsonObject .containsKey(Float32MultiArray.FIELD_LAYOUT) ? MultiArrayLayout .fromJsonObject(jsonObject .getJsonObject(Float32MultiArray.FIELD_LAYOUT)) : new MultiArrayLayout(); // check the array float[] data = new float[] {}; JsonArray jsonData = jsonObject .getJsonArray(Float32MultiArray.FIELD_DATA); if (jsonData != null) { // convert each data data = new float[jsonData.size()]; for (int i = 0; i < data.length; i++) { data[i] = (float) jsonData.getJsonNumber(i).doubleValue(); } } return new Float32MultiArray(layout, data); } }
/** * Create a new Float64MultiArray based on the given JSON object. Any * missing values will be set to their defaults. * * @param jsonObject * The JSON object to parse. * @return A Float64MultiArray message based on the given JSON object. */ public static Float64MultiArray fromJsonObject(JsonObject jsonObject) { // check the layout MultiArrayLayout layout = jsonObject .containsKey(Float64MultiArray.FIELD_LAYOUT) ? MultiArrayLayout .fromJsonObject(jsonObject .getJsonObject(Float64MultiArray.FIELD_LAYOUT)) : new MultiArrayLayout(); // check the array double[] data = new double[] {}; JsonArray jsonData = jsonObject .getJsonArray(Float64MultiArray.FIELD_DATA); if (jsonData != null) { // convert each data data = new double[jsonData.size()]; for (int i = 0; i < data.length; i++) { data[i] = (double) jsonData.getJsonNumber(i).doubleValue(); } } return new Float64MultiArray(layout, data); } }