[1030] | 1 |
|
---|
| 2 | package de.ugoe.cs.autoquest.usability.evaluation.result;
|
---|
| 3 |
|
---|
[1032] | 4 | import static java.lang.String.format;
|
---|
| 5 |
|
---|
| 6 | import java.util.List;
|
---|
[1030] | 7 | import java.util.Map;
|
---|
| 8 |
|
---|
[1032] | 9 | import lombok.AllArgsConstructor;
|
---|
| 10 | import lombok.ExtensionMethod;
|
---|
[1030] | 11 | import lombok.Getter;
|
---|
[1032] | 12 |
|
---|
| 13 | import org.apache.commons.lang.StringUtils;
|
---|
| 14 |
|
---|
| 15 | import com.google.common.base.CharMatcher;
|
---|
| 16 | import com.google.common.base.Joiner;
|
---|
| 17 | import com.google.common.collect.Lists;
|
---|
| 18 |
|
---|
[1030] | 19 | import de.ugoe.cs.autoquest.usability.DefectDescription;
|
---|
| 20 | import de.ugoe.cs.autoquest.usability.ParameterFragment;
|
---|
[1032] | 21 | import de.ugoe.cs.autoquest.usability.util.DefectDescriptionExtensionMethods;
|
---|
[1030] | 22 |
|
---|
[1032] | 23 | @AllArgsConstructor
|
---|
| 24 | @ExtensionMethod({DefectDescriptionExtensionMethods.class})
|
---|
[1030] | 25 | public class UsabilityDefect {
|
---|
| 26 |
|
---|
| 27 | @Getter
|
---|
| 28 | private UsabilityDefectSeverityLevel severityLevel;
|
---|
| 29 |
|
---|
| 30 | private DefectDescription defectDescription;
|
---|
| 31 |
|
---|
| 32 | private Map<String, String> descriptionParametersValues;
|
---|
| 33 |
|
---|
[1032] | 34 | public String defectDescription() {
|
---|
| 35 | if(defectDescription.containsParameterFragments()) {
|
---|
| 36 | return assembleDefectDescription();
|
---|
| 37 | } else {
|
---|
| 38 | return Joiner.on(" ").skipNulls().join(defectDescription.getTextFragmentOrParameterFragment());
|
---|
| 39 | }
|
---|
[1030] | 40 | }
|
---|
| 41 |
|
---|
[1032] | 42 | private String assembleDefectDescription() {
|
---|
| 43 | List<String> descriptionParts =
|
---|
| 44 | Lists.newArrayListWithCapacity(defectDescription.getTextFragmentOrParameterFragment().size());
|
---|
[1030] | 45 |
|
---|
| 46 | for (Object fragment : defectDescription.getTextFragmentOrParameterFragment()) {
|
---|
[1032] | 47 | if (fragment.isParameterFragment()) {
|
---|
| 48 | descriptionParts.add(parameterFragmentAsString((ParameterFragment) fragment));
|
---|
| 49 | } else {
|
---|
| 50 | descriptionParts.add(CharMatcher.WHITESPACE.collapseFrom((String) fragment, ' ').trim());
|
---|
[1030] | 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[1032] | 54 | return Joiner.on(' ').join(descriptionParts);
|
---|
[1030] | 55 | }
|
---|
| 56 |
|
---|
[1032] | 57 | private String parameterFragmentAsString(ParameterFragment fragment) {
|
---|
| 58 | String value = descriptionParametersValues.getValueOrEmptyString(fragment.getParameterName());
|
---|
| 59 | if (StringUtils.isNotEmpty(value)) {
|
---|
| 60 | return value;
|
---|
| 61 | } else {
|
---|
| 62 | throw new IllegalArgumentException(format("required parameter \"%s\" for usability defect description not provided", fragment.getParameterName()));
|
---|
[1030] | 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | }
|
---|