static boolean isValidEnum(final Class<?> type){
  if (type == null) {
    return false;
  }
  if (type.isEnum()) {
    return true;
  }
  final Method m;
  try {
    final String valuesMethod="values";
    m=type.getDeclaredMethod(valuesMethod);
    if (m == null) {
      return false;
    }
  }
 catch (  final SecurityException|NoSuchMethodException e) {
    return false;
  }
  if (!Modifier.isStatic(m.getModifiers())) {
    return false;
  }
  final Class<?> returnType=m.getReturnType();
  if (!returnType.isArray()) {
    return false;
  }
  final Method v;
  try {
    final String valueOfMethod="valueOf";
    v=type.getMethod(valueOfMethod,String.class);
    if (v == null) {
      return false;
    }
  }
 catch (  final SecurityException|NoSuchMethodException e) {
    return false;
  }
  if (!Modifier.isStatic(v.getModifiers())) {
    return false;
  }
  final Class<?> returnTypev=v.getReturnType();
  if (!type.isAssignableFrom(returnTypev)) {
    return false;
  }
  return true;
}

static boolean isValidEnum ( final Class < ? > type ) { if ( type == null ) { return false ; } if ( type . isEnum ( ) ) { return true ; } final Method m ; try { final String valuesMethod = "values" ; m = type . getDeclaredMethod ( valuesMethod ) ; if ( m == null ) { return false ; } } catch ( final SecurityException | NoSuchMethodException e ) { return false ; } if ( ! Modifier . isStatic ( m . getModifiers ( ) ) ) { return false ; } final Class < ? > returnType = m . getReturnType ( ) ; if ( ! returnType . isArray ( ) ) { return false ; } final Method v ; try { final String valueOfMethod = "valueOf" ; v = type . getMethod ( valueOfMethod , String . class ) ; if ( v == null ) { return false ; } } catch ( final SecurityException | NoSuchMethodException e ) { return false ; } if ( ! Modifier . isStatic ( v . getModifiers ( ) ) ) { return false ; } final Class < ? > returnTypev = v . getReturnType ( ) ; if ( ! type . isAssignableFrom ( returnTypev ) ) { return false ; } return true ; }
check if looks sufficiently like an enum to be treated as one . must implement static t [ ] values ( ) static t value ( string )
