View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.sandbox.agile;
17  
18  import java.util.Arrays;
19  import java.util.List;
20  import java.util.Locale;
21  
22  /**
23   * The valid priority values for user stories.
24   * <p>
25   * Only {@link #REQUIRED required}, {@link #VERY_IMPORTANT very important} are
26   * items that are necessary to be implemented.
27   * </p>
28   */
29  public enum Priority
30  {
31    // ****************************** Enumeration *******************************
32  
33    /**
34     * The story is required for the final product.
35     * <p>
36     * This and {@link #VERY_IMPORTANT} are items necessary to be implemented.
37     * </p>
38     */
39    REQUIRED("required", 1),
40  
41    /**
42     * The story is very important for the final product.
43     * <p>
44     * This and {@link #REQUIRED} are items necessary to be implemented.
45     * </p>
46     */
47    VERY_IMPORTANT("very-important", 2),
48  
49    /**
50     * The story is a nice-to-have for the final product, but not relevant for the
51     * release.
52     */
53    NICE_TO_HAVE("nice-to-have", 3),
54  
55    /**
56     * The story would add to the user experience of the user, but is not relevant
57     * for the release.
58     */
59    POLISHING("polishing", 4),
60  
61    /**
62     * The story is not necessary to be part of the release, but may be included
63     * if resources are available. If the product backlog contains only
64     * dispensable stores, the development is likely to come to an end.
65     * <p>
66     * The priority is available to keep stories in the product backlog for
67     * further references.
68     * </p>
69     */
70    DISPENSABLE("dispensable", 5);
71  
72    // ********************************* Fields *********************************
73  
74    // --- constants ------------------------------------------------------------
75  
76    // --- members --------------------------------------------------------------
77  
78    /**
79     * The identifier of the priority. This value is used for resource lookups.
80     */
81    private final String id;
82  
83    /**
84     * The value of the priority.
85     */
86    private final int priorityValue;
87  
88    // ****************************** Constructors ******************************
89  
90    /**
91     * Default constructor.
92     *
93     * @param id the identifier of the priority.
94     * @param priorityValue the value of the priority.
95     */
96    private Priority(final String id, final int priorityValue)
97    {
98      this.id = id;
99      this.priorityValue = priorityValue;
100   }
101 
102   // ********************************* Methods ********************************
103 
104   // --- init -----------------------------------------------------------------
105 
106   // --- get&set --------------------------------------------------------------
107 
108   /**
109    * Returns the identifier of the priority. This value is used for resource
110    * lookups.
111    *
112    * @return the identifier of the priority.
113    */
114   public String getId()
115   {
116     return id;
117   }
118 
119   /**
120    * Returns the value of the priority.
121    *
122    * @return the value of the priority.
123    */
124   public int getPriorityValue()
125   {
126     return priorityValue;
127   }
128 
129   // --- business -------------------------------------------------------------
130 
131   /**
132    * Returns the priority values as a list.
133    *
134    * @return the priority values as a list.
135    */
136   public List<Priority> getValues()
137   {
138     return Arrays.asList(values());
139   }
140 
141   /**
142    * Parses the string representation of a priority instance.
143    *
144    * @return the priority instance read from the string.
145    * @throws IllegalArgumentException if {@code valueAsString} is not a valid
146    *           string representation of a priority value.
147    */
148   public static Priority fromString(final String valueAsString)
149     throws IllegalArgumentException
150   {
151     for (Priority priority : values())
152     {
153       if (valueAsString.equals(priority.id))
154       {
155         return priority;
156       }
157     }
158 
159     final String message =
160         "The value '" + valueAsString
161             + "' is not a valid value for priority. Valid values are: "
162             + toString(Locale.ENGLISH);
163     throw new IllegalArgumentException(message);
164   }
165 
166   // --- object basics --------------------------------------------------------
167 
168   /**
169    * Returns the string representation of the instance for the given locale.
170    *
171    * @param locale the locale for which the string representation is requested.
172    * @return the string representation of this instance.
173    */
174   public static String toString(final Locale locale)
175   {
176     final StringBuilder buffer = new StringBuilder(64);
177     for (Priority priority : values())
178     {
179       buffer.append(priority.id).append(", ");
180     }
181 
182     final int length = buffer.length();
183     if (length > 0)
184     {
185       buffer.setLength(length - 2);
186     }
187 
188     return buffer.toString();
189   }
190 
191   /**
192    * {@inheritDoc}
193    *
194    * @see java.lang.Enum#toString()
195    */
196   @Override
197   public String toString()
198   {
199     return id;
200   }
201 }