Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 4bbee803

Přidáno uživatelem Jan Havlíček před více než 4 roky(ů)

#7794 Got rid of simpleToString.
Rewrote the toString() instead (no need to re-cast Object types)

Zobrazit rozdíly:

demo_jh/Deserializer_tests/src/app/App.java
131 131
        try {
132 132
            System.out.println("Starting...");
133 133

  
134
            this.serialize(new samples.ok.SimpleChild(), "serialized/simpleChild.out");
134
            this.serialize(new samples.ok.Simple(), "serialized/simple_arrays.out");
135 135

  
136
            samples.ok.SimpleChild test1 = this.deserialize("serialized/simple.out");
136
            //samples.ok.SimpleChild test1 = this.deserialize("serialized/simple.out");
137 137

  
138 138
        } catch (Exception e) {
139 139
            System.out.println(e.toString());
demo_jh/Deserializer_tests/src/samples/ok/Simple.java
9 9
    private String pozdrav = "AHOJ";
10 10
    private int testInt = 123;
11 11
    private double testDouble = 1.00;
12
    private int[] intArray = new int[3];
13
    private String[] stringArray = new String[3];
12 14

  
13 15
    public Simple() 
14 16
    {
15 17
        int locInt = 5;
18
        this.intArray[0] = 5;
19
        this.intArray[1] = 10;
20
        this.intArray[2] = 15;
21

  
22
        this.stringArray[0] = "A";
23
        this.stringArray[1] = "B";
24
        this.stringArray[2] = "C";
16 25
    }
17 26
}
project/Deserializer/bcha.json
1 1
{
2 2
	class samples.ok.Simple : {
3
		"double testDouble" : 1.0, 
4
		"int testInt" : 123, 
5
		"null pozdrav" : [String 0x7e0003: "AHOJ"]
3
		"testDouble" : "1.0", 
4
		"testInt" : "123", 
5
		"intArray" : "[5,10,15]", 
6
		"pozdrav" : "AHOJ", 
7
		"stringArray" : "[A,B,C]"
6 8
	}
7 9
}
project/Deserializer/src/Converter.java
28 28
		try {
29 29
			String json = convert(FileWorker.loadByteArray(input));
30 30
			
31
			String title = "Ulo?en? JSON";
31
			String title = "Ulo�en� JSON";
32 32
			if (FileWorker.saveJson(output, json)) {
33 33
				System.out.println("The JSON file was saved correctly.");
34
				Report.info(title, null, "Ulo?en? JSON souboru prob?hlo v po??dku.");
34
				Report.info(title, null, "Ulo�en� JSON souboru prob�hlo v po��dku.");
35 35
			} else {
36 36
				System.out.println("There was an error saving the JSON file.");
37
				Report.error(title, null, "P?i ukl?d?n? JSON souboru nastala chyba.");
37
				Report.error(title, null, "P�i ukl�d�n� JSON souboru nastala chyba.");
38 38
			}
39 39
		} catch (IOException e) {
40 40
			System.out.println("There was an error loading the file.");
41 41
			e.printStackTrace();
42
			Report.error("Na??t?n? souboru", null, "P?i na??t?n? souboru do?lo k chyb?.");
42
			Report.error("Na��t�n� souboru", null, "P�i na��t�n� souboru do�lo k chyb�.");
43 43
		}
44 44

  
45 45
		main.convertIsComplete();
......
62 62
			{
63 63
				if(cnt != null)
64 64
				{
65
					json += cnt.simpleFormatToString();
65
					json += cnt.toString();
66 66
				}
67 67
			}
68 68

  
project/Deserializer/src/Deserializer.java
40 40
		stage.setScene(createScene());
41 41
		stage.setMinWidth(400);
42 42
		stage.show();
43
		
44
		//tests
45
		Converter thread = new Converter(this, new File("simple_arrays.out"), new File("bcha.json"));
46
		thread.start();
43 47
	}
44 48
	
45 49
	private Scene createScene() {
project/Deserializer/src/jdeserialize/arrayobj.java
25 25
        this.data = data;
26 26
    }
27 27
    public String toString() {
28
        return "[array " + jdeserialize.hex(handle) + " classdesc " + classdesc.toString() + ": " 
29
            + data.toString() + "]";
28
        StringBuilder sb = new StringBuilder();
29
        sb.append("[");
30
        for(Object el : this.data)
31
        {
32
            sb.append(el);
33
            if(!el.equals(this.data.get(this.data.size()-1)))
34
            {
35
                sb.append(',');
36
            }
37
        }
38
        sb.append("]");
39
        return sb.toString();
30 40
    }
31 41
}
32 42

  
project/Deserializer/src/jdeserialize/content.java
64 64
     * @param value the new value to use
65 65
     */
66 66
    public void setIsExceptionObject(boolean value);
67

  
68
    /**
69
     * Jan Havlicek, 200406 for Java object universal deserializer project.
70
     * Added because of wanted format of string representation fo objects.
71
     */
72
    public String simpleFormatToString();
73 67
}
74 68

  
project/Deserializer/src/jdeserialize/contentbase.java
24 24
    }
25 25
    public void validate() throws ValidityException {
26 26
    }
27

  
28
    @Override
29
    public String simpleFormatToString() {
30
        // TODO Auto-generated method stub
31
        return "";
32
    }
33 27
}
34 28

  
project/Deserializer/src/jdeserialize/instance.java
1 1
package jdeserialize;
2
import java.lang.reflect.Field;
3 2
import java.util.*;
4 3

  
5 4
/**
......
27 26
    }
28 27
    public String toString() {
29 28
        StringBuffer sb = new StringBuffer();
30
        sb.append(classdesc.name).append(' ').append("_h").append(jdeserialize.hex(handle))
31
            .append(" = r_").append(jdeserialize.hex(classdesc.handle)).append(";  ");
32
        //sb.append("// [instance " + jdeserialize.hex(handle) + ": " + jdeserialize.hex(classdesc.handle) + "/" + classdesc.name).append("]");
33
        return sb.toString();
34
    }
35
    /**
36
     * Object annotation data.
37
     */
38
    public Map<classdesc, List<content>> annotations;
39

  
40

  
41
    @Override
42
    public String simpleFormatToString()
43
    {
44
        StringBuffer sb = new StringBuffer();
45 29
        
46 30
        //ClassName
47 31
        sb.append("{\n\tclass ").append(classdesc.name);
......
63 47

  
64 48
        for(field f : classdesc.fields)
65 49
        {
66
            //v this.fielddata najit element, jehoz key == classdesc
67
            //v tomto prvku fielddata najdu value (element) podle key == f
68
            //jeho value je chtena hodnota
69
            String val = this.fielddata.get(classdesc).get(f).toString();
70

  
71
            sb.append("\n\t\t");
72
            sb.append("\"").append(f.type.getJavaType()).append(" ").append(f.name).append("\"");
73
            sb.append(" : ");
74
            sb.append(val);
50
            /*if(f.type.getJavaType() != null)
51
            {*/
52
                //v this.fielddata najit element, jehoz key == classdesc
53
                //v tomto prvku fielddata najdu value (element) podle key == f
54
                //jeho value je chtena hodnota
55
                var val = this.fielddata.get(classdesc).get(f).toString();
56
                sb.append("\n\t\t");
57
                //Datový typ není potřeba - json jej nepoužívá!
58
                sb.append("\"")./*append(f.type.getJavaType()).append(" ").*/append(f.name).append("\"");
59
                sb.append(" : ");
60
                sb.append("\"").append(val).append("\"");
61
            /*}
62
            else if(f.classname != null)
63
            {
64
                content val = (content) this.fielddata.get(classdesc).get(f);
65
                sb.append("\n\t\t");
66
                sb.append("\"").append(f.name).append("\"");
67
                sb.append(" : ");
68
                sb.append("\"").append(val.toString()).append("\"");
69
            }*/
75 70

  
76 71
            if(!f.equals(classdesc.fields[classdesc.fields.length-1]))
77 72
            {
......
83 78
        
84 79
        return sb.toString();
85 80
    }
86
}
81
    /**
82
     * Object annotation data.
83
     */
84
    public Map<classdesc, List<content>> annotations;
85
}
project/Deserializer/src/jdeserialize/stringobj.java
16 16
        return x;
17 17
    }
18 18
    public String toString() {
19
        return "[String " + jdeserialize.hex(handle) + ": \"" + value + "\"]";
19
        return this.value;
20 20
    }
21 21
    /**
22 22
     * Constructor.

Také k dispozici: Unified diff