Changeset 1040 for trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/result
- Timestamp:
- 01/16/13 17:51:51 (11 years ago)
- Location:
- trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/result
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/result/UsabilityDefect.java
r1032 r1040 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. 1 14 2 15 package de.ugoe.cs.autoquest.usability.evaluation.result; … … 7 20 import java.util.Map; 8 21 9 import lombok.AllArgsConstructor;10 import lombok.ExtensionMethod;11 import lombok.Getter;12 13 22 import org.apache.commons.lang.StringUtils; 14 23 15 24 import com.google.common.base.CharMatcher; 16 25 import com.google.common.base.Joiner; 26 import com.google.common.base.Predicate; 27 import com.google.common.collect.Iterables; 17 28 import com.google.common.collect.Lists; 18 29 19 30 import de.ugoe.cs.autoquest.usability.DefectDescription; 20 31 import de.ugoe.cs.autoquest.usability.ParameterFragment; 21 import de.ugoe.cs.autoquest.usability.util.DefectDescriptionExtensionMethods;22 32 23 @AllArgsConstructor 24 @ExtensionMethod({DefectDescriptionExtensionMethods.class}) 33 /** 34 * <p> 35 * TODO comment 36 * </p> 37 * 38 * @author Alexander Deicke 39 */ 25 40 public class UsabilityDefect { 26 41 27 @Getter28 42 private UsabilityDefectSeverityLevel severityLevel; 29 43 … … 32 46 private Map<String, String> descriptionParametersValues; 33 47 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 34 58 public String defectDescription() { 35 if (defectDescription.containsParameterFragments()) {59 if (containsParameterFragments(defectDescription)) { 36 60 return assembleDefectDescription(); 37 } else { 38 return Joiner.on(" ").skipNulls().join(defectDescription.getTextFragmentOrParameterFragment()); 61 } 62 else { 63 return Joiner.on(" ").skipNulls() 64 .join(defectDescription.getTextFragmentOrParameterFragment()); 39 65 } 40 66 } 41 67 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 42 80 private String assembleDefectDescription() { 43 List<String> descriptionParts = 44 Lists.newArrayListWithCapacity(defectDescription.getTextFragmentOrParameterFragment().size()); 81 List<String> descriptionParts = 82 Lists.newArrayListWithCapacity(defectDescription.getTextFragmentOrParameterFragment() 83 .size()); 45 84 46 85 for (Object fragment : defectDescription.getTextFragmentOrParameterFragment()) { 47 if ( fragment.isParameterFragment()) {86 if (isParameterFragment(fragment)) { 48 87 descriptionParts.add(parameterFragmentAsString((ParameterFragment) fragment)); 49 } else { 50 descriptionParts.add(CharMatcher.WHITESPACE.collapseFrom((String) fragment, ' ').trim()); 88 } 89 else { 90 descriptionParts.add(CharMatcher.WHITESPACE.collapseFrom((String) fragment, ' ') 91 .trim()); 51 92 } 52 93 } … … 55 96 } 56 97 98 private boolean isParameterFragment(Object object) { 99 return object instanceof ParameterFragment; 100 } 101 57 102 private String parameterFragmentAsString(ParameterFragment fragment) { 58 String value = descriptionParametersValues.getValueOrEmptyString(fragment.getParameterName()); 103 String value = 104 getValueOrEmptyString(descriptionParametersValues, fragment.getParameterName()); 59 105 if (StringUtils.isNotEmpty(value)) { 60 106 return value; 61 } else { 62 throw new IllegalArgumentException(format("required parameter \"%s\" for usability defect description not provided", fragment.getParameterName())); 107 } 108 else { 109 throw new IllegalArgumentException( 110 format("required parameter \"%s\" for usability defect description not provided", 111 fragment.getParameterName())); 63 112 } 64 113 } 65 114 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 66 124 } -
trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/result/UsabilityDefectDescriptionResolver.java
r1030 r1040 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. 14 1 15 package de.ugoe.cs.autoquest.usability.evaluation.result; 2 16 … … 4 18 import de.ugoe.cs.autoquest.usability.evaluation.rule.set.UsabilityRule; 5 19 20 /** 21 * <p> 22 * TODO comment 23 * </p> 24 * 25 * @author Alexander Deicke 26 */ 6 27 public interface UsabilityDefectDescriptionResolver { 7 28 -
trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/result/UsabilityDefectFactory.java
r1030 r1040 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. 1 14 2 15 package de.ugoe.cs.autoquest.usability.evaluation.result; … … 6 19 import de.ugoe.cs.autoquest.usability.DefectDescription; 7 20 import de.ugoe.cs.autoquest.usability.evaluation.rule.set.UsabilityRule; 8 import lombok.AllArgsConstructor;9 21 10 @AllArgsConstructor 22 /** 23 * <p> 24 * TODO comment 25 * </p> 26 * 27 * @author Alexander Deicke 28 */ 11 29 public class UsabilityDefectFactory { 30 31 public UsabilityDefectFactory(UsabilityDefectDescriptionResolver usabilityDefectDescriptionResolver) 32 { 33 super(); 34 this.usabilityDefectDescriptionResolver = usabilityDefectDescriptionResolver; 35 } 12 36 13 37 private final UsabilityDefectDescriptionResolver usabilityDefectDescriptionResolver; … … 15 39 public UsabilityDefect createUsabilityGuidlineRecommendation(UsabilityDefectSeverityLevel recommendationSeverityLevel, 16 40 UsabilityRule usabilityRule, 17 Map<String, String> recommendationMessageParameteValues) { 41 Map<String, String> recommendationMessageParameteValues) 42 { 18 43 DefectDescription guidlineDescription = 19 44 usabilityDefectDescriptionResolver.descriptionFor(usabilityRule); -
trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/result/UsabilityDefectSeverityLevel.java
r1030 r1040 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. 14 1 15 package de.ugoe.cs.autoquest.usability.evaluation.result; 2 16 17 /** 18 * <p> 19 * TODO comment 20 * </p> 21 * 22 * @author Alexander Deicke 23 */ 3 24 public enum UsabilityDefectSeverityLevel { 4 25 5 26 INFO, LOW, MEDIUM, HIGH; 6 27 7 28 } -
trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/result/UsabilityDefectXmlDescriptionResolver.java
r1030 r1040 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. 14 1 15 package de.ugoe.cs.autoquest.usability.evaluation.result; 2 16 … … 16 30 import de.ugoe.cs.autoquest.usability.evaluation.rule.set.UsabilityRule; 17 31 32 /** 33 * <p> 34 * TODO comment 35 * </p> 36 * 37 * @author Alexander Deicke 38 */ 18 39 public class UsabilityDefectXmlDescriptionResolver implements UsabilityDefectDescriptionResolver { 19 40 20 41 private static final String DEFAULT_MESSAGES_FILE = "defectDescriptions_en.xml"; 21 22 private static final UsabilityDefectXmlDescriptionResolver instance = new UsabilityDefectXmlDescriptionResolver(); 23 42 43 private static final UsabilityDefectXmlDescriptionResolver instance = 44 new UsabilityDefectXmlDescriptionResolver(); 45 24 46 private DefectDescriptions defectDescriptions; 25 47 26 48 private UsabilityDefectXmlDescriptionResolver() { 27 49 loadDescriptions(); 28 50 } 29 51 30 52 @SuppressWarnings("unchecked") 31 53 private void loadDescriptions() { 32 InputStream inputStream = 33 ClassLoader.getSystemResourceAsStream(DEFAULT_MESSAGES_FILE); 54 InputStream inputStream = ClassLoader.getSystemResourceAsStream(DEFAULT_MESSAGES_FILE); 34 55 try { 35 56 String packageName = DefectDescriptions.class.getPackage().getName(); … … 38 59 39 60 defectDescriptions = 40 ((JAXBElement<DefectDescriptions>) unmarshaller.unmarshal(inputStream)) 41 .getValue(); 61 ((JAXBElement<DefectDescriptions>) unmarshaller.unmarshal(inputStream)).getValue(); 42 62 } 43 63 catch (Exception e) { 44 throw new RuntimeException 45 ("error while initializing usability defect descriptions", e); 64 throw new RuntimeException("error while initializing usability defect descriptions", e); 46 65 } 47 66 finally { … … 56 75 } 57 76 } 58 77 59 78 public static UsabilityDefectXmlDescriptionResolver instance() { 60 79 return instance; … … 63 82 @Override 64 83 public DefectDescription descriptionFor(final UsabilityRule usabilityRule) { 65 Optional<DefectDescription> guidlineDescription = Iterables.tryFind(defectDescriptions.getDefectDescription(), new Predicate<DefectDescription>() { 66 67 public boolean apply(DefectDescription defectDescription) { 68 return usabilityRule.ruleIdentifier().equals(defectDescription.getDefectId()); 69 } 70 71 }); 72 if(!guidlineDescription.isPresent()) 73 throw new RuntimeException 74 ("error while initializing usability defect descriptions. No " + 75 "description text available for description " + usabilityRule.ruleIdentifier()); 84 Optional<DefectDescription> guidlineDescription = 85 Iterables.tryFind(defectDescriptions.getDefectDescription(), 86 new Predicate<DefectDescription>() { 87 88 public boolean apply(DefectDescription defectDescription) { 89 return usabilityRule.ruleIdentifier() 90 .equals(defectDescription.getDefectId()); 91 } 92 93 }); 94 if (!guidlineDescription.isPresent()) 95 throw new RuntimeException( 96 "error while initializing usability defect descriptions. No " + 97 "description text available for description " + 98 usabilityRule.ruleIdentifier()); 76 99 return guidlineDescription.get(); 77 100 }
Note: See TracChangeset
for help on using the changeset viewer.