View Javadoc

1   package com.atlassian.webtest.ui.keys;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   /**
7    * Factory of {@link KeySequence} objects.
8    *
9    * @author Dariusz Kordonski
10   */
11  public final class Sequences
12  {
13      private Sequences() {
14          throw new AssertionError("Don't instantiate me");
15      }
16  
17      private static final KeySequence EMPTY = chars("");
18  
19      /**
20       * Create a sequence from a string of characters.
21       *
22       * @param sequence character sequence
23       * @return key sequence composed of characters from <tt>sequence</tt>
24       */
25      public static KeySequence chars(String sequence)
26      {
27          return new CharacterKeySequence(sequence);
28      }
29  
30  
31      /**
32       * Create a sequence builder from a string of characters.
33       *
34       * @param sequence character sequence
35       * @return key sequence builder initialized with characters from <tt>sequence</tt>
36       */
37      public static KeySequenceBuilder charsBuilder(String sequence)
38      {
39          return new KeySequenceBuilder(sequence);
40      }
41  
42      /**
43       * Empty key sequence (useful for clearing out form inputs).
44       *
45       * @return an empty key sequence
46       */
47      public static KeySequence empty()
48      {
49          return EMPTY;
50      }
51  
52  
53      /**
54       * Return key sequence consisting of one or more special keys.
55       *
56       * @param keys list of special keys in the sequence
57       * @return key sequence consisting of the <tt>keys</tt>
58       */
59      public static KeySequence keys(SpecialKey... keys)
60      {
61          return new DefaultKeySequence(copy(keys));
62      }
63  
64      /**
65       * Return key sequence builder initialized with <tt>keys</tt>.
66       *
67       * @param keys list of special keys in the sequence
68       * @return new key sequence builder
69       */
70      public static KeySequenceBuilder keysBuilder(Key... keys)
71      {
72          return new KeySequenceBuilder(keys);
73      }
74  
75  
76  
77      private static List<Key> copy(SpecialKey... keys)
78      {
79          List<Key> answer = new ArrayList<Key>();
80          for (SpecialKey key : keys)
81          {
82              answer.add(key);
83          }
84          return answer;
85      }
86  }