aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/schemaspy/model/ReportVector.java
blob: f2e0aef2d00f42b7be4fa936e8672f015cb1d385 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package org.schemaspy.model;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class ReportVector {
    private ArrayList<StackTraceLine> stackTrace;
    private double stackTraceHash;
    private int codeCoverage; //unused right now
    GenericTreeNode parentMutation;

    public ReportVector(GenericTreeNode parentMutation)
    {
        this.parentMutation = parentMutation;
        stackTrace = new ArrayList<StackTraceLine>();
    }

    public double getStackTraceHash() { return stackTraceHash; }

    public void setStackTraceHash(double stackTraceHash) { this.stackTraceHash = stackTraceHash; }

    public ArrayList<StackTraceLine> getStackTrace() {
        return stackTrace;
    }

    public void setStackTrace(ArrayList<StackTraceLine> stackTrace) {
        this.stackTrace = stackTrace;
    }

    public int getCodeCoverage() {
        return codeCoverage;
    }

    public void setCodeCoverage(int codeCoverage) {
        this.codeCoverage = codeCoverage;
    }

    public GenericTreeNode getParentMutation() {
        return parentMutation;
    }

    public void setParentMutation(GenericTreeNode parentMutation) {
        this.parentMutation = parentMutation;
    }

    public void addStackTraceLine(StackTraceLine stl)
    {
        stackTrace.add(stl);
    }

    public void parseFile(String pathToFile)
    {
        HashMap<String,ArrayList<String>> allLists = new HashMap<>();

        String data;
        String key="uninitialized key.Should not be that way";
        ArrayList<String> currentArray = new ArrayList<>();

        try {
            BufferedReader infile = new BufferedReader(new FileReader(pathToFile));
            while ((data = infile.readLine()) != null) {
                if (data.contains(":")) {
                    if (!currentArray.isEmpty()) {
                        allLists.put(key, currentArray); // putting in the map the "title" of the data and values before stepping into the next block
                        currentArray = new ArrayList<>();
                    }

                    key = data.replace(":", "");
                } else {
                    currentArray.add(data.replace(",",""));
                }
            }

            storeLines(allLists);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }


    public void storeLines(HashMap<String,ArrayList<String>> allLists)
    {
        int maxSize=0;

        for(Map.Entry<String,ArrayList<String>> entry : allLists.entrySet())
        {
            if(entry.getValue().size() > maxSize)
                maxSize = entry.getValue().size();
        }

        for(int i = 0; i < maxSize ; i ++)
        {
            String functionName = "unknown.this is abnormal behavior";
            String fileName = "unknown.this is abnormal behavior";
            int lineNumber = -1;

            if(i < allLists.get("functionNames").size()) {
                functionName = allLists.get("functionNames").get(i);
            }

            if(i < allLists.get("fileNames").size()) {
                fileName = allLists.get("fileNames").get(i);
            }

            if(i < allLists.get("lineNumbers").size()) {
                try
                {
                    lineNumber = Integer.parseInt(allLists.get("lineNumbers").get(i));
                }
                catch(Exception e) {e.printStackTrace();}
            }

            StackTraceLine stl = new StackTraceLine(functionName,fileName,lineNumber);
            stackTrace.add(stl);
        }
    }

    @Override
    public String toString() {
        return "ReportVector{" +
                "stackTrace=" + stackTrace +
                ", parentMutation=" + parentMutation +
                '}';
    }

    public boolean compareStackTrace (ReportVector rpv)
    {
        if(rpv.stackTrace.size() != this.stackTrace.size())
            return false;

        int i = 0;
        for(StackTraceLine stl : rpv.stackTrace)
        {
            if(!stl.compare(this.stackTrace.get(i)))
                return false;
            
            i++;
        }
        return true;
    }

    public double hashStackTrace(GenericTree mutationTree,GenericTreeNode currentNode)
    {
        Random rand = new Random();
        return rand.nextDouble();
    }
}