Primitive types may be enumerated as
The following example shows the definition of story points. A story point value may be selected from a fixed range of values.
/** * A comment about what story points are. */ @PropertyIntValueRange( value = { 0, 1, 2, 3, 5, 8, 13, 21, 50, 100 }, defaultValue = 8) Integer storyPoint();
True enumerations have an advantage over simple enumerations since their individual elements can be documented.
The following example defines an enumeration type for priorities:
/** * The valid priority values for user stories. */ public enum Priority { // ****************************** Enumeration ******************************* /** * The story is required for the final product. */ REQUIRED("required", 1), /** * The story is very important for the final product. */ VERY_IMPORTANT("very-important", 2), /** * The story is a nice-to-have for the final product, but not relevant for the * release. */ NICE_TO_HAVE("nice-to-have", 3), /** * The story would add to the user experience of the user, but is not relevant * for the release. */ POLISHING("polishing", 4), /** * The story is not necessary to be part of the release, but may be included * if resources are available. If the product backlog contains only * dispensable stores, the development is likely to come to an end. * <p> * The priority is available to keep stories in the product backlog for * further references. * </p> */ DISPENSABLE("dispensable", 5); // ********************************* Fields ********************************* // --- constants ------------------------------------------------------------ // --- members -------------------------------------------------------------- /** * The identifier of the priority. This value is used for resource lookups. */ private final String id; /** * The value of the priority. */ private final int priorityValue; // ****************************** Constructors ****************************** /** * Default constructor. * * @param id the identifier of the priority. * @param priorityValue the value of the priority. * @see */ private Priority(final String id, final int priorityValue) { this.id = id; this.priorityValue = priorityValue; } // ********************************* Methods ******************************** // --- init ----------------------------------------------------------------- // --- get&set -------------------------------------------------------------- /** * Returns the identifier of the priority. This value is used for resource * lookups. * * @return the identifier of the priority. */ public String getId() { return id; } /** * Returns the value of the priority. * * @return the value of the priority. */ public int getPriorityValue() { return priorityValue; } public boolean isCommented() { return true; } // --- business ------------------------------------------------------------- public List<Priority> getValues() { return Arrays.asList(values()); } public static Priority fromString(final String valueAsString) throws IllegalArgumentException { for (Priority priority : values()) { if (valueAsString.equals(priority.id)) { return priority; } } final String message = "The value '" + valueAsString + "' is not a valid value for priority. Valid values are: " + toString(Locale.ENGLISH); throw new IllegalArgumentException(message); } public static String toString(final Locale locale) { final StringBuilder buffer = new StringBuilder(64); for (Priority priority : values()) { buffer.append(priority.id).append(", "); } final int length = buffer.length(); if (length > 0) { buffer.setLength(length - 2); } return buffer.toString(); } // --- object basics -------------------------------------------------------- @Override public String toString() { return id; } }
Note that the methods
are necessary to integrate with smartics-properties. The comments may be made available by the smartics-properties-maven-plugin to the runtime or can be views in the reports.
Please refer to smartics-properties-doc for further examples.