1 |
|
---|
2 | package de.ugoe.cs.autoquest.usability.evaluation.result;
|
---|
3 |
|
---|
4 | import java.util.Map;
|
---|
5 |
|
---|
6 | import lombok.Getter;
|
---|
7 | import de.ugoe.cs.autoquest.usability.DefectDescription;
|
---|
8 | import de.ugoe.cs.autoquest.usability.ParameterFragment;
|
---|
9 |
|
---|
10 | public class UsabilityDefect {
|
---|
11 |
|
---|
12 | @Getter
|
---|
13 | private UsabilityDefectSeverityLevel severityLevel;
|
---|
14 |
|
---|
15 | private DefectDescription defectDescription;
|
---|
16 |
|
---|
17 | private Map<String, String> descriptionParametersValues;
|
---|
18 |
|
---|
19 | public UsabilityDefect(UsabilityDefectSeverityLevel severityLevel,
|
---|
20 | DefectDescription recommendationDescription,
|
---|
21 | Map<String, String> descriptionParametersValues) {
|
---|
22 | this.severityLevel = severityLevel;
|
---|
23 | this.defectDescription = recommendationDescription;
|
---|
24 | this.descriptionParametersValues = descriptionParametersValues;
|
---|
25 | }
|
---|
26 |
|
---|
27 | public String defectDescription() {
|
---|
28 | StringBuffer result = new StringBuffer();
|
---|
29 |
|
---|
30 | for (Object fragment : defectDescription.getTextFragmentOrParameterFragment()) {
|
---|
31 | if (result.length() > 0) {
|
---|
32 | result.append(" ");
|
---|
33 | }
|
---|
34 |
|
---|
35 | if (fragment instanceof ParameterFragment) {
|
---|
36 | String value = null;
|
---|
37 | if (descriptionParametersValues != null) {
|
---|
38 | value =
|
---|
39 | descriptionParametersValues.get(((ParameterFragment) fragment)
|
---|
40 | .getParameterName());
|
---|
41 | }
|
---|
42 |
|
---|
43 | if (value != null) {
|
---|
44 | result.append(value);
|
---|
45 | }
|
---|
46 | else {
|
---|
47 | throw new IllegalArgumentException("required parameter \"" +
|
---|
48 | ((ParameterFragment) fragment).getParameterName() +
|
---|
49 | "\" for usability defect description not provided");
|
---|
50 | }
|
---|
51 | }
|
---|
52 | else {
|
---|
53 | result.append(getFragmentString(fragment));
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | return result.toString();
|
---|
58 | }
|
---|
59 |
|
---|
60 | private String getFragmentString(Object fragment) {
|
---|
61 | String fragmentStr = fragment.toString().trim();
|
---|
62 |
|
---|
63 | fragmentStr = fragmentStr.replaceAll("\n", " ");
|
---|
64 |
|
---|
65 | while (fragmentStr.indexOf(" ") > -1) {
|
---|
66 | fragmentStr = fragmentStr.replaceAll(" ", " ");
|
---|
67 | }
|
---|
68 |
|
---|
69 | return fragmentStr;
|
---|
70 | }
|
---|
71 |
|
---|
72 | }
|
---|