> public enum Colors
> {
>RED, GREEN, BLUE
>
>
> String myColor = "RED"; // or possibly int
>
> if ( myColor in Colors.values())
> {
>// myColor is RED, GREEN, or BLUE
Ah, I see.
try {
Color color = Color.valueOf("GRAPLE");
// member
}
catch (IllegalArgumentExeption exc) {
// not a member
}
Or just get the list of all of them, convert them to strings, and see if your string is in that list.
Cool, thanks, here's what I've got:
/*
* throws exception if not valid member
* just return false if exception is thrown
*
* @param semaphoreValue to test
*
* @return valid flag
*/
public static boolean isValidSemaphore (String semaphoreValue)
{
try
{
SemaphoreValues sv = SemaphoreValues.valueOf(semaphoreValue);
return true;
}
catch (IllegalArgumentException e)
{
// not a member
return false;
}
}
> > public enum Colors
> > {
> >RED, GREEN, BLUE
> >
> >
> > String myColor = "RED"; // or possibly int
> >
> > if ( myColor in Colors.values())
> > {
> >// myColor is RED, GREEN, or BLUE
>
> Ah, I see.
>
>
> try {
>Color color = Color.valueOf("GRAPLE");
> // member
> }
> catch (IllegalArgumentExeption exc) {
>// not a member
>
>
>
> Or just get the list of all of them, convert them to
> strings, and see if your string is in that list.
I wonder if that would work if an obfuscator was being used?
(I ask because I know it doesn't work in C#.)