Changeset 1032
- Timestamp:
- 01/13/13 17:01:54 (12 years ago)
- Location:
- autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/result/UsabilityDefect.java
r1030 r1032 2 2 package de.ugoe.cs.autoquest.usability.evaluation.result; 3 3 4 import static java.lang.String.format; 5 6 import java.util.List; 4 7 import java.util.Map; 5 8 9 import lombok.AllArgsConstructor; 10 import lombok.ExtensionMethod; 6 11 import lombok.Getter; 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 7 19 import de.ugoe.cs.autoquest.usability.DefectDescription; 8 20 import de.ugoe.cs.autoquest.usability.ParameterFragment; 21 import de.ugoe.cs.autoquest.usability.util.DefectDescriptionExtensionMethods; 9 22 23 @AllArgsConstructor 24 @ExtensionMethod({DefectDescriptionExtensionMethods.class}) 10 25 public class UsabilityDefect { 11 26 … … 17 32 private Map<String, String> descriptionParametersValues; 18 33 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;34 public String defectDescription() { 35 if(defectDescription.containsParameterFragments()) { 36 return assembleDefectDescription(); 37 } else { 38 return Joiner.on(" ").skipNulls().join(defectDescription.getTextFragmentOrParameterFragment()); 39 } 25 40 } 26 41 27 public String defectDescription() { 28 StringBuffer result = new StringBuffer(); 42 private String assembleDefectDescription() { 43 List<String> descriptionParts = 44 Lists.newArrayListWithCapacity(defectDescription.getTextFragmentOrParameterFragment().size()); 29 45 30 46 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)); 47 if (fragment.isParameterFragment()) { 48 descriptionParts.add(parameterFragmentAsString((ParameterFragment) fragment)); 49 } else { 50 descriptionParts.add(CharMatcher.WHITESPACE.collapseFrom((String) fragment, ' ').trim()); 54 51 } 55 52 } 56 53 57 return result.toString();54 return Joiner.on(' ').join(descriptionParts); 58 55 } 59 56 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(" ", " "); 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())); 67 63 } 68 69 return fragmentStr;70 64 } 71 65
Note: See TracChangeset
for help on using the changeset viewer.