View Javadoc
1   package org.oxerr.okcoin.websocket.dto;
2   
3   import static java.util.stream.Collectors.toList;
4   
5   import javax.json.JsonArray;
6   import javax.json.JsonValue;
7   import javax.json.JsonValue.ValueType;
8   
9   public class CandlestickChart extends
10  		org.oxerr.okcoin.rest.dto.CandlestickChart {
11  
12  	private static final long serialVersionUID = 2015030501L;
13  
14  	private static final Candlestick[] EMPTY_CANDLESTICK_ARRAY = new Candlestick[0];
15  
16  	public CandlestickChart(JsonValue jsonValue) {
17  		this((JsonArray) jsonValue);
18  	}
19  
20  	public CandlestickChart(JsonArray jsonArray) {
21  		super(parseCandlesticks(jsonArray));
22  	}
23  
24  	private static Candlestick[] parseCandlesticks(JsonArray jsonArray) {
25  		if (jsonArray.get(0).getValueType() == ValueType.ARRAY) {
26  			// first push contains multiple candlesticks.
27  
28  			return jsonArray.stream().map(e -> new Candlestick(e))
29  				.collect(toList())
30  				.toArray(EMPTY_CANDLESTICK_ARRAY);
31  		} else {
32  			// the follows contain only one candlestick.
33  
34  			return new Candlestick[] { new Candlestick(jsonArray) };
35  		}
36  	}
37  
38  }