1 package com.aragost.javahg;
2
3 /**
4 * Enum type to represent phases introduced in Mercurial 2.1
5 */
6 public enum Phase {
7
8 PUBLIC, DRAFT, SECRET;
9
10 /**
11 * Return the Phase that correspond to the specified text.
12 * <p>
13 * The text is what mercurial uses in the command output (i.e.
14 * public, draft, or secret).
15 *
16 * @param s
17 * @return the Phase that correspond to the specified text. null is returned for the empty string.
18 * @throws IllegalArgumentException
19 * if no phase correspond to the specified text
20 */
21 public static Phase fromText(String s) {
22 for (Phase p : Phase.values()) {
23 if (p.text.equals(s)) {
24 return p;
25 }
26 }
27 if (s.equals("")) {
28 return null;
29 }
30 throw new IllegalArgumentException("No phase for " + s);
31 }
32
33 private String text;
34
35 private Phase() {
36 this.text = name().toLowerCase();
37 }
38 }