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 test.de.smartics.properties.spi.core.metadata; 17 18 import java.util.Arrays; 19 import java.util.List; 20 import java.util.Locale; 21 22 /** 23 * Test enum values. 24 */ 25 enum EnumValue 26 { 27 // ****************************** Enumeration ******************************* 28 29 /** 30 * The story is required for the final product. 31 */ 32 ONE("one"), 33 34 /** 35 * The story is very important for the final product. 36 */ 37 TWO("two"), 38 39 /** 40 * The story is a nice-to-have for the final product, but not relevant for the 41 * release. 42 */ 43 THREE("three"); 44 45 // ********************************* Fields ********************************* 46 47 // --- constants ------------------------------------------------------------ 48 49 // --- members -------------------------------------------------------------- 50 51 private final String id; 52 53 // ****************************** Constructors ****************************** 54 55 private EnumValue(final String id) 56 { 57 this.id = id; 58 } 59 60 // ********************************* Methods ******************************** 61 62 // --- init ----------------------------------------------------------------- 63 64 // --- get&set -------------------------------------------------------------- 65 66 // --- business ------------------------------------------------------------- 67 68 public List<EnumValue> getValues() // TODO: Needed? 69 { 70 return Arrays.asList(values()); 71 } 72 73 public static EnumValue fromString(final String valueAsString) 74 throws IllegalArgumentException 75 { 76 for (EnumValue value : values()) 77 { 78 if (valueAsString.equals(value.id)) 79 { 80 return value; 81 } 82 } 83 84 final String message = 85 "The value '" + valueAsString 86 + "' is not a valid value. Valid values are: " 87 + toString(Locale.ENGLISH); 88 throw new IllegalArgumentException(message); 89 } 90 91 public static String toString(final Locale locale) 92 { 93 final StringBuilder buffer = new StringBuilder(64); 94 for (EnumValue value : values()) 95 { 96 buffer.append(value.id).append(", "); 97 } 98 99 final int length = buffer.length(); 100 if (length > 0) 101 { 102 buffer.setLength(length - 2); 103 } 104 105 return buffer.toString(); 106 } 107 108 // --- object basics -------------------------------------------------------- 109 110 @Override 111 public String toString() 112 { 113 return id; 114 } 115 }