1 package com.atlassian.webtest.ui.keys;
2
3 import com.google.common.collect.ImmutableList;
4 import com.google.common.collect.Lists;
5
6 import java.util.Collection;
7 import java.util.EnumSet;
8 import java.util.List;
9 import java.util.Set;
10
11 import static com.google.common.base.Preconditions.checkNotNull;
12
13
14
15
16
17 public final class CharacterKeySequence extends AbstractKeySequence
18 {
19
20 private final String characters;
21 private final Iterable<Key> charKeys;
22
23 public CharacterKeySequence(String characters, TypeMode mode, Set<ModifierKey> pressed, Collection<KeyEventType> keyEvents)
24 {
25 super(mode, pressed, keyEvents);
26 this.characters = checkNotNull(characters);
27 this.charKeys = initKeys();
28 }
29
30 private List<Key> initKeys()
31 {
32 List<Key> answer = Lists.newArrayList();
33 for (char character : characters.toCharArray())
34 {
35 answer.add(KeySequenceBuilder.keyFor(character));
36 }
37 return answer;
38 }
39
40 public CharacterKeySequence(String characters, TypeMode mode, Set<ModifierKey> pressed)
41 {
42 this(characters, mode, pressed, KeyEventType.ALL);
43 }
44
45 public CharacterKeySequence(String characters, Set<ModifierKey> pressed)
46 {
47 this(characters, TypeMode.DEFAULT, pressed);
48 }
49
50 public CharacterKeySequence(String characters)
51 {
52 this(characters, EnumSet.noneOf(ModifierKey.class));
53 }
54
55 public List<Key> keys()
56 {
57 return ImmutableList.copyOf(charKeys);
58 }
59
60
61
62
63
64
65 public String string()
66 {
67 return characters;
68 }
69
70 @Override
71 public String toString()
72 {
73 return string();
74 }
75 }