1   package eu.fbk.dkm.pikes.raid;
2   
3   import javax.annotation.Nullable;
4   import java.util.Arrays;
5   import java.util.EnumSet;
6   import java.util.Set;
7   
8   public enum Component {
9   
10      POLARITY('p'),
11  
12      EXPRESSION('e', "NN", "VB", "JJ", "R"),
13  
14      HOLDER('h', "NN", "PRP", "JJP", "DTP", "WP"),
15  
16      TARGET('t', "NN", "PRP", "JJP", "DTP", "WP", "VB");
17  
18      private char letter;
19  
20      private String[] headPos;
21  
22      private Component(final char letter, final String... headPos) {
23          this.letter = letter;
24          this.headPos = headPos;
25      }
26  
27      public char getLetter() {
28          return this.letter;
29      }
30  
31      public String[] getHeadPos() {
32          return this.headPos;
33      }
34  
35      public static Component forLetter(final char letter) {
36          final char c = Character.toLowerCase(letter);
37          for (final Component component : values()) {
38              if (component.letter == c) {
39                  return component;
40              }
41          }
42          throw new IllegalArgumentException("No component for letter '" + letter + "'");
43      }
44  
45      public static Set<Component> forLetters(final String letters) {
46          final EnumSet<Component> result = EnumSet.noneOf(Component.class);
47          for (int i = 0; i < letters.length(); ++i) {
48              result.add(forLetter(letters.charAt(i)));
49          }
50          return result;
51      }
52  
53      static final EnumSet<Component> UNIVERSE = EnumSet.allOf(Component.class);
54  
55      static EnumSet<Component> toSet(@Nullable final Component... components) {
56          return components == null || components.length == 0 ? UNIVERSE : EnumSet.copyOf(Arrays
57                  .asList(components));
58      }
59  
60  }