Projekt

Obecné

Profil

Stáhnout (2.65 KB) Statistiky
| Větev: | Tag: | Revize:
1
package jdeserialize;
2

    
3
import java.util.Map;
4

    
5
/**
6
 * <p>
7
 * Represents an array instance, including the values the comprise the array.
8
 * </p>
9
 *
10
 * <p>
11
 * Note that in arrays of primitives, the classdesc will be named "[x", where x
12
 * is the field type code representing the primitive type. See
13
 * jdeserialize.resolveJavaType() for an example of analysis/generation of
14
 * human-readable names from these class names.
15
 * </p>
16
 */
17
public class arrayobj extends contentbase {
18
    /**
19
     * Type of the array instance.
20
     */
21
    public classdesc classdesc;
22

    
23
    /**
24
     * Values of the array, in the order they were read from the stream.
25
     */
26
    public arraycoll data;
27

    
28
    public arrayobj(int handle, classdesc cd, arraycoll data) {
29
        super(contenttype.ARRAY);
30
        this.handle = handle;
31
        this.classdesc = cd;
32
        this.data = data;
33
    }
34

    
35
    public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata, boolean child) {
36
        StringBuilder sb = new StringBuilder();
37
        boolean bracketInserted = false;
38

    
39
        for(int i = 0; i < this.data.size(); i++) {
40
            Object el = this.data.get(i);
41
            
42
            boolean isLast = (i == this.data.size()-1) || (this.data.get(i+1) == null);
43

    
44
            if (el != null) {
45
                if (el instanceof content) {
46
                    if(!bracketInserted){
47
                        sb.append("\n").append(indentation).append("[ \n");
48
                        bracketInserted = true;
49
                        indentation += "\t";
50
                    }
51
                    sb.append(((content) el).toJson(indentation, fielddata, false));
52

    
53
                    if (!isLast) {
54
                        sb.append(",\n");
55
                    }
56
                    else{
57
                        indentation = indentation.replaceFirst("\t", "");
58
                        sb.append("\n").append(indentation).append("]");
59
                        bracketInserted = false;
60
                    }
61
                }else{
62
                    if(!bracketInserted){
63
                        sb.append("[ ");
64
                        bracketInserted = true;
65
                    }
66
                    
67
                    sb.append(el.toString());
68
                    
69
                    if (!isLast) {
70
                        sb.append(", ");
71
                    }
72
                    else {
73
                        sb.append(" ]");
74
                    }
75
                }
76
            }
77
        }
78
        return sb.toString();
79
    }
80

    
81
    public String toString() {
82
        return "[array " + jdeserialize.hex(handle) + " classdesc " + classdesc.toString() + ": " + data.toString()
83
                + "]";
84
    }
85
}
(6-6/20)