7
7
import java .util .stream .*;
8
8
9
9
public class MerkleNode {
10
+
10
11
public final Multihash hash ;
11
12
public final Optional <String > name ;
12
13
public final Optional <Integer > size ;
14
+ public final Optional <String > largeSize ;
13
15
public final Optional <Integer > type ;
14
16
public final List <MerkleNode > links ;
15
17
public final Optional <byte []> data ;
16
18
17
- public MerkleNode (String hash ) {
18
- this (hash , Optional .empty ());
19
- }
20
-
21
- public MerkleNode (String hash , Optional <String > name ) {
22
- this (hash , name , Optional .empty (), Optional .empty (), Arrays .asList (), Optional .empty ());
23
- }
24
-
25
- public MerkleNode (String hash , Optional <String > name , Optional <Integer > size , Optional <Integer > type , List <MerkleNode > links , Optional <byte []> data ) {
19
+ public MerkleNode (String hash ,
20
+ Optional <String > name ,
21
+ Optional <Integer > size ,
22
+ Optional <String > largeSize ,
23
+ Optional <Integer > type ,
24
+ List <MerkleNode > links ,
25
+ Optional <byte []> data ) {
26
26
this .name = name ;
27
27
this .hash = Cid .decode (hash );
28
28
this .size = size ;
29
+ this .largeSize = largeSize ;
29
30
this .type = type ;
30
31
this .links = links ;
31
32
this .data = data ;
32
33
}
33
34
35
+ public MerkleNode (String hash ) {
36
+ this (hash , Optional .empty ());
37
+ }
38
+
39
+ public MerkleNode (String hash , Optional <String > name ) {
40
+ this (hash , name , Optional .empty (), Optional .empty (), Optional .empty (), Arrays .asList (), Optional .empty ());
41
+ }
42
+
34
43
@ Override
35
44
public boolean equals (Object b ) {
36
45
if (!(b instanceof MerkleNode ))
@@ -51,13 +60,25 @@ public static MerkleNode fromJSON(Object rawjson) {
51
60
String hash = (String )json .get ("Hash" );
52
61
if (hash == null )
53
62
hash = (String )json .get ("Key" );
54
- Optional <String > name = json .containsKey ("Name" ) ? Optional .of ((String ) json .get ("Name" )): Optional .empty ();
55
- Optional <Integer > size = json .containsKey ("Size" ) ? Optional .<Integer >empty ().of ((Integer ) json .get ("Size" )): Optional .<Integer >empty ().empty ();
56
- Optional <Integer > type = json .containsKey ("Type" ) ? Optional .<Integer >empty ().of ((Integer ) json .get ("Type" )): Optional .<Integer >empty ().empty ();
63
+ Optional <String > name = json .containsKey ("Name" ) ?
64
+ Optional .of ((String ) json .get ("Name" )) :
65
+ Optional .empty ();
66
+ Object rawSize = json .get ("Size" );
67
+ Optional <Integer > size = rawSize instanceof Integer ?
68
+ Optional .of ((Integer ) rawSize ) :
69
+ Optional .empty ();
70
+ Optional <String > largeSize = rawSize instanceof String ?
71
+ Optional .of ((String ) json .get ("Size" )) :
72
+ Optional .empty ();
73
+ Optional <Integer > type = json .containsKey ("Type" ) ?
74
+ Optional .of ((Integer ) json .get ("Type" )) :
75
+ Optional .empty ();
57
76
List <Object > linksRaw = (List <Object >) json .get ("Links" );
58
- List <MerkleNode > links = linksRaw == null ? Collections .EMPTY_LIST : linksRaw .stream ().map (x -> MerkleNode .fromJSON (x )).collect (Collectors .toList ());
77
+ List <MerkleNode > links = linksRaw == null ?
78
+ Collections .emptyList () :
79
+ linksRaw .stream ().map (x -> MerkleNode .fromJSON (x )).collect (Collectors .toList ());
59
80
Optional <byte []> data = json .containsKey ("Data" ) ? Optional .of (((String )json .get ("Data" )).getBytes ()): Optional .empty ();
60
- return new MerkleNode (hash , name , size , type , links , data );
81
+ return new MerkleNode (hash , name , size , largeSize , type , links , data );
61
82
}
62
83
63
84
public Object toJSON () {
@@ -69,7 +90,7 @@ public Object toJSON() {
69
90
if (name .isPresent ())
70
91
res .put ("Name" , name .get ());
71
92
if (size .isPresent ())
72
- res .put ("Size" , size .get ());
93
+ res .put ("Size" , size .isPresent () ? size . get () : largeSize . get ());
73
94
if (type .isPresent ())
74
95
res .put ("Type" , type .get ());
75
96
return res ;
0 commit comments