View Javadoc
1   package org.oxerr.okcoin.websocket.dto;
2   
3   import java.math.BigDecimal;
4   import java.util.Collections;
5   import java.util.Map;
6   import java.util.stream.Collectors;
7   
8   import javax.json.JsonObject;
9   import javax.json.JsonString;
10  import javax.json.JsonValue;
11  
12  public class Funds extends org.oxerr.okcoin.rest.dto.Funds {
13  
14  	private static final long serialVersionUID = 2015030701L;
15  
16  	public Funds(JsonValue jsonValue) {
17  		this((JsonObject) jsonValue);
18  	}
19  
20  	public Funds(JsonObject jsonObject) {
21  		this(
22  			jsonObject.getJsonObject("asset"),
23  			jsonObject.getJsonObject("borrow"),
24  			jsonObject.getJsonObject("free"),
25  			jsonObject.getJsonObject("freezed"),
26  			jsonObject.getJsonObject("union_fund")
27  		);
28  	}
29  
30  	public Funds(JsonObject assetJsonObject, JsonObject borrowJsonObject,
31  			JsonObject freeJsonObject, JsonObject frozenJsonObject,
32  			JsonObject unionFundJsonObject) {
33  		super(
34  			toMap(assetJsonObject),
35  			toMap(borrowJsonObject),
36  			toMap(freeJsonObject),
37  			toMap(frozenJsonObject),
38  			toMap(unionFundJsonObject)
39  		);
40  	}
41  
42  	private static Map<String, BigDecimal> toMap(JsonObject jsonObject) {
43  		return jsonObject == null ? Collections.emptyMap() : jsonObject
44  			.entrySet()
45  			.stream()
46  			.collect(
47  				Collectors.toMap(
48  					e -> e.getKey(),
49  					e -> new BigDecimal(((JsonString) e.getValue()).getString())
50  				)
51  			);
52  	}
53  
54  }