[1040] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
[1030] | 14 |
|
---|
| 15 | package de.ugoe.cs.autoquest.usability.evaluation.result;
|
---|
| 16 |
|
---|
[1032] | 17 | import static java.lang.String.format;
|
---|
| 18 |
|
---|
| 19 | import java.util.List;
|
---|
[1030] | 20 | import java.util.Map;
|
---|
| 21 |
|
---|
[1032] | 22 | import org.apache.commons.lang.StringUtils;
|
---|
| 23 |
|
---|
| 24 | import com.google.common.base.CharMatcher;
|
---|
| 25 | import com.google.common.base.Joiner;
|
---|
[1040] | 26 | import com.google.common.base.Predicate;
|
---|
| 27 | import com.google.common.collect.Iterables;
|
---|
[1032] | 28 | import com.google.common.collect.Lists;
|
---|
| 29 |
|
---|
[1030] | 30 | import de.ugoe.cs.autoquest.usability.DefectDescription;
|
---|
| 31 | import de.ugoe.cs.autoquest.usability.ParameterFragment;
|
---|
| 32 |
|
---|
[1040] | 33 | /**
|
---|
| 34 | * <p>
|
---|
| 35 | * TODO comment
|
---|
| 36 | * </p>
|
---|
| 37 | *
|
---|
| 38 | * @author Alexander Deicke
|
---|
| 39 | */
|
---|
[1030] | 40 | public class UsabilityDefect {
|
---|
| 41 |
|
---|
| 42 | private UsabilityDefectSeverityLevel severityLevel;
|
---|
| 43 |
|
---|
| 44 | private DefectDescription defectDescription;
|
---|
| 45 |
|
---|
| 46 | private Map<String, String> descriptionParametersValues;
|
---|
| 47 |
|
---|
[1040] | 48 | public UsabilityDefect(UsabilityDefectSeverityLevel severityLevel,
|
---|
| 49 | DefectDescription defectDescription,
|
---|
| 50 | Map<String, String> descriptionParametersValues)
|
---|
| 51 | {
|
---|
| 52 | super();
|
---|
| 53 | this.severityLevel = severityLevel;
|
---|
| 54 | this.defectDescription = defectDescription;
|
---|
| 55 | this.descriptionParametersValues = descriptionParametersValues;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[1032] | 58 | public String defectDescription() {
|
---|
[1040] | 59 | if (containsParameterFragments(defectDescription)) {
|
---|
[1032] | 60 | return assembleDefectDescription();
|
---|
| 61 | }
|
---|
[1040] | 62 | else {
|
---|
| 63 | return Joiner.on(" ").skipNulls()
|
---|
| 64 | .join(defectDescription.getTextFragmentOrParameterFragment());
|
---|
| 65 | }
|
---|
[1030] | 66 | }
|
---|
| 67 |
|
---|
[1040] | 68 | private boolean containsParameterFragments(DefectDescription defectDescription) {
|
---|
| 69 | return Iterables.any(defectDescription.getTextFragmentOrParameterFragment(),
|
---|
| 70 | new Predicate<Object>() {
|
---|
| 71 |
|
---|
| 72 | @Override
|
---|
| 73 | public boolean apply(Object fragment) {
|
---|
| 74 | return fragment instanceof ParameterFragment;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | });
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[1032] | 80 | private String assembleDefectDescription() {
|
---|
[1040] | 81 | List<String> descriptionParts =
|
---|
| 82 | Lists.newArrayListWithCapacity(defectDescription.getTextFragmentOrParameterFragment()
|
---|
| 83 | .size());
|
---|
[1030] | 84 |
|
---|
| 85 | for (Object fragment : defectDescription.getTextFragmentOrParameterFragment()) {
|
---|
[1040] | 86 | if (isParameterFragment(fragment)) {
|
---|
[1032] | 87 | descriptionParts.add(parameterFragmentAsString((ParameterFragment) fragment));
|
---|
[1030] | 88 | }
|
---|
[1040] | 89 | else {
|
---|
| 90 | descriptionParts.add(CharMatcher.WHITESPACE.collapseFrom((String) fragment, ' ')
|
---|
| 91 | .trim());
|
---|
| 92 | }
|
---|
[1030] | 93 | }
|
---|
| 94 |
|
---|
[1032] | 95 | return Joiner.on(' ').join(descriptionParts);
|
---|
[1030] | 96 | }
|
---|
| 97 |
|
---|
[1040] | 98 | private boolean isParameterFragment(Object object) {
|
---|
| 99 | return object instanceof ParameterFragment;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[1032] | 102 | private String parameterFragmentAsString(ParameterFragment fragment) {
|
---|
[1040] | 103 | String value =
|
---|
| 104 | getValueOrEmptyString(descriptionParametersValues, fragment.getParameterName());
|
---|
[1032] | 105 | if (StringUtils.isNotEmpty(value)) {
|
---|
| 106 | return value;
|
---|
[1030] | 107 | }
|
---|
[1040] | 108 | else {
|
---|
| 109 | throw new IllegalArgumentException(
|
---|
| 110 | format("required parameter \"%s\" for usability defect description not provided",
|
---|
| 111 | fragment.getParameterName()));
|
---|
| 112 | }
|
---|
[1030] | 113 | }
|
---|
| 114 |
|
---|
[1040] | 115 | private String getValueOrEmptyString(Map<String, String> stringKeyValueMap, String key) {
|
---|
| 116 | return stringKeyValueMap != null && stringKeyValueMap.containsKey(key) ? stringKeyValueMap
|
---|
| 117 | .get(key) : StringUtils.EMPTY;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | public UsabilityDefectSeverityLevel getSeverityLevel() {
|
---|
| 121 | return severityLevel;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[1030] | 124 | }
|
---|