source: autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/util/TextInputUtil.java @ 1031

Last change on this file since 1031 was 1031, checked in by adeicke, 11 years ago

Corrected incorrect spelling.

  • Property svn:mime-type set to text/plain
File size: 2.4 KB
Line 
1package de.ugoe.cs.autoquest.usability.util;
2
3import java.util.List;
4
5import com.google.common.base.CharMatcher;
6import com.google.common.base.Predicate;
7import com.google.common.base.Splitter;
8import com.google.common.collect.HashMultiset;
9import com.google.common.collect.Iterables;
10import com.google.common.collect.Lists;
11import com.google.common.collect.Multiset;
12
13import de.ugoe.cs.autoquest.eventcore.gui.TextInput;
14import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
15import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
16
17public class TextInputUtil {
18   
19    public static Multiset<String> aggregateEnteredTextFromTextInputs(List<ITaskTreeNode> nodesWithTextInputEvents) {
20        List<Iterable<String>> allTextInputs = Lists.newArrayList();
21        for(ITaskTreeNode nodeWithTextInput : nodesWithTextInputEvents) {
22            TextInput textInput = (TextInput) ((IEventTask) nodeWithTextInput).getEventType();
23            allTextInputs.add(splitTextIntoWordsAndSigns(textInput.getEnteredText()));
24        }
25        return HashMultiset.create(Iterables.concat(allTextInputs));
26    }
27   
28    public static Iterable<String> splitTextIntoWordsAndSigns(String enteredText) {
29        CharMatcher onlyWords = CharMatcher.WHITESPACE.or(CharMatcher.forPredicate(characterIsJavaIdentifierPartPredicate()));
30        CharMatcher onlySigns = CharMatcher.WHITESPACE.or(CharMatcher.forPredicate(characterIsJavaIdentifierPartPredicate()).negate());
31        Iterable<String> words = Splitter.on(onlyWords).omitEmptyStrings().trimResults().split(enteredText);
32        Iterable<String> signs = Splitter.on(onlySigns).omitEmptyStrings().trimResults().split(enteredText);
33        return Iterables.concat(words, signs);
34    }
35   
36    public static Predicate<Character> characterIsJavaIdentifierPartPredicate() {
37        return new Predicate<Character>() {
38           
39            @Override
40            public boolean apply(Character character) {
41               return  !Character.isJavaIdentifierPart(character);
42            }
43           
44        };
45    }
46   
47    public static Predicate<Character> characterIsLetterOrDigitPredicate() {
48        return new Predicate<Character>() {
49           
50            @Override
51            public boolean apply(Character character) {
52                return !Character.isLetterOrDigit(character);
53            }
54           
55        };
56    }
57
58}
Note: See TracBrowser for help on using the repository browser.