"Converting/Parsing an Enumeration to a String More Generically" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "Converting/Parsing an Enumeration to a String More Generically" answered properly. Developers are finding an appropriate answer about Converting/Parsing an Enumeration to a String More Generically related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like Converting/Parsing an Enumeration to a String More Generically. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on Converting/Parsing an Enumeration to a String More Generically.
Converting/Parsing an Enumeration to a String More Generically
private interface EnumerationToStringHelper
{
List<Object> ProvideEnumerationValues();
Boolean CompareEnumerationToString(String possibleEnumeration, Object enumerationValue);
}
private class ExampleEnumToStringHelper implements EnumerationToStringHelperExampleEnum
{
public List<Object> ProvideEnumerationValues(){ return (List<Object>)ExampleEnum.values(); }
public Boolean CompareEnumerationToString(String possibleEnumeration, Object enumerationValue)
{
return ((ExampleEnum)enumerationValue).name().equalsIgnoreCase(possibleEnumeration);
}
}
private static Map<Type, EnumerationToStringHelper> TypeToEnumerationMap;
private static void PopulateTypeToEnumerationMap()
{
TypeToEnumerationMap = new Map<Type, EnumerationToStringHelper>
{
Type.forName('ExampleEnum') => new ExampleEnumToStringHelper()
};
}
public static Object ConvertStringToEnumeration(Type enumerationType, String possibleEnumeration)
{
if(possibleEnumeration == null) return null;
if(TypeToEnumerationMap == null)
PopulateTypeToEnumerationMap();
EnumerationToStringHelper conversionAction = TypeToEnumerationMap.get(enumerationType);
if(conversionAction == null)
throw new EnumerationToStringException('The Type you enter is either a) not an enumeration or b) not a supported enumeration.');
for(Object particalarEnumValue : conversionAction.ProvideEnumerationValues())
if(conversionAction.CompareEnumerationToString(possibleEnumeration, particalarEnumValue))
return particalarEnumValue;
return null;
}
public class EnumerationToStringException extends Exception { }
Source: salesforce.stackexchange.com
All those coders who are working on the Whatever based application and are stuck on Converting/Parsing an Enumeration to a String More Generically can get a collection of related answers to their query. Programmers need to enter their query on Converting/Parsing an Enumeration to a String More Generically related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about Converting/Parsing an Enumeration to a String More Generically for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of Converting/Parsing an Enumeration to a String More Generically while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "Converting/Parsing an Enumeration to a String More Generically". Visit this developer's friendly online web community, CodeProZone, and get your queries like Converting/Parsing an Enumeration to a String More Generically resolved professionally and stay updated to the latest Whatever updates.