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.properties.tutorial.property.list; 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 */ 25 public enum Priority 26 { 27 // ****************************** Enumeration ******************************* 28 29 /** 30 * The story is required for the final product. 31 */ 32 REQUIRED("required", 1), 33 34 /** 35 * The story is very important for the final product. 36 */ 37 VERY_IMPORTANT("very-important", 2), 38 39 /** 40 * The story is a nice-to-have for the final product, but not relevant for the 41 * release. 42 */ 43 NICE_TO_HAVE("nice-to-have", 3), 44 45 /** 46 * The story would add to the user experience of the user, but is not relevant 47 * for the release. 48 */ 49 POLISHING("polishing", 4), 50 51 /** 52 * The story is not necessary to be part of the release, but may be included 53 * if resources are available. If the product backlog contains only 54 * dispensable stores, the development is likely to come to an end. 55 * <p> 56 * The priority is available to keep stories in the product backlog for 57 * further references. 58 * </p> 59 */ 60 DISPENSABLE("dispensable", 5); 61 62 // ********************************* Fields ********************************* 63 64 // --- constants ------------------------------------------------------------ 65 66 // --- members -------------------------------------------------------------- 67 68 /** 69 * The identifier of the priority. This value is used for resource lookups. 70 */ 71 private final String id; 72 73 /** 74 * The value of the priority. 75 */ 76 private final int priorityValue; 77 78 // ****************************** Constructors ****************************** 79 80 /** 81 * Default constructor. 82 * 83 * @param id the identifier of the priority. 84 * @param priorityValue the value of the priority. 85 * @see 86 */ 87 private Priority(final String id, final int priorityValue) 88 { 89 this.id = id; 90 this.priorityValue = priorityValue; 91 } 92 93 // ********************************* Methods ******************************** 94 95 // --- init ----------------------------------------------------------------- 96 97 // --- get&set -------------------------------------------------------------- 98 99 /** 100 * Returns the identifier of the priority. This value is used for resource 101 * lookups. 102 * 103 * @return the identifier of the priority. 104 */ 105 public String getId() 106 { 107 return id; 108 } 109 110 /** 111 * Returns the value of the priority. 112 * 113 * @return the value of the priority. 114 */ 115 public int getPriorityValue() 116 { 117 return priorityValue; 118 } 119 120 public boolean isCommented() 121 { 122 return true; 123 } 124 125 // --- business ------------------------------------------------------------- 126 127 public List<Priority> getValues() 128 { 129 return Arrays.asList(values()); 130 } 131 132 public static Priority fromString(final String valueAsString) 133 throws IllegalArgumentException 134 { 135 for (Priority priority : values()) 136 { 137 if (valueAsString.equals(priority.id)) 138 { 139 return priority; 140 } 141 } 142 143 final String message = 144 "The value '" + valueAsString 145 + "' is not a valid value for priority. Valid values are: " 146 + toString(Locale.ENGLISH); 147 throw new IllegalArgumentException(message); 148 } 149 150 public static String toString(final Locale locale) 151 { 152 final StringBuilder buffer = new StringBuilder(64); 153 for (Priority priority : values()) 154 { 155 buffer.append(priority.id).append(", "); 156 } 157 158 final int length = buffer.length(); 159 if (length > 0) 160 { 161 buffer.setLength(length - 2); 162 } 163 164 return buffer.toString(); 165 } 166 167 // --- object basics -------------------------------------------------------- 168 169 @Override 170 public String toString() 171 { 172 return id; 173 } 174 }