@Test public void resolveEnumValue() { Assert.assertEquals( ChronoUnit.HALF_DAYS, EnumValueUtils.resolveEnumValue( outer, "inner.unit", "half-days" ) ); }
@Nullable public static <T extends Enum<T>> T resolveEnumValue( @Nonnull Object object, @Nonnull String propertyPath, @Nullable Object enumValueName ) { final String stringEnumName = (enumValueName == null) ? null : enumValueName.toString(); if ( stringEnumName == null ) { return null; } final Class<?> propertyClass; try { propertyClass = PropertyUtils.getPropertyType( object, propertyPath ); } catch ( IllegalAccessException | InvocationTargetException | NoSuchMethodException | IllegalArgumentException e ) { throw new IllegalArgumentException( "Could not resolve property " + propertyPath + " of object " + object.getClass().getSimpleName(), e ); } if ( !propertyClass.isEnum() ) { throw new IllegalArgumentException( "Property " + propertyPath + " of object " + object.getClass().getSimpleName() + " is no enumeration class: " + propertyClass.getSimpleName() ); } @SuppressWarnings( "unchecked" ) final Class<T> uncheckedEnumClass = (Class<T>) propertyClass; return NameUtils.toEnumValue( uncheckedEnumClass, stringEnumName ); }
EnumValueUtils { @Nullable public static <T extends Enum<T>> T resolveEnumValue( @Nonnull Object object, @Nonnull String propertyPath, @Nullable Object enumValueName ) { final String stringEnumName = (enumValueName == null) ? null : enumValueName.toString(); if ( stringEnumName == null ) { return null; } final Class<?> propertyClass; try { propertyClass = PropertyUtils.getPropertyType( object, propertyPath ); } catch ( IllegalAccessException | InvocationTargetException | NoSuchMethodException | IllegalArgumentException e ) { throw new IllegalArgumentException( "Could not resolve property " + propertyPath + " of object " + object.getClass().getSimpleName(), e ); } if ( !propertyClass.isEnum() ) { throw new IllegalArgumentException( "Property " + propertyPath + " of object " + object.getClass().getSimpleName() + " is no enumeration class: " + propertyClass.getSimpleName() ); } @SuppressWarnings( "unchecked" ) final Class<T> uncheckedEnumClass = (Class<T>) propertyClass; return NameUtils.toEnumValue( uncheckedEnumClass, stringEnumName ); } }
EnumValueUtils { @Nullable public static <T extends Enum<T>> T resolveEnumValue( @Nonnull Object object, @Nonnull String propertyPath, @Nullable Object enumValueName ) { final String stringEnumName = (enumValueName == null) ? null : enumValueName.toString(); if ( stringEnumName == null ) { return null; } final Class<?> propertyClass; try { propertyClass = PropertyUtils.getPropertyType( object, propertyPath ); } catch ( IllegalAccessException | InvocationTargetException | NoSuchMethodException | IllegalArgumentException e ) { throw new IllegalArgumentException( "Could not resolve property " + propertyPath + " of object " + object.getClass().getSimpleName(), e ); } if ( !propertyClass.isEnum() ) { throw new IllegalArgumentException( "Property " + propertyPath + " of object " + object.getClass().getSimpleName() + " is no enumeration class: " + propertyClass.getSimpleName() ); } @SuppressWarnings( "unchecked" ) final Class<T> uncheckedEnumClass = (Class<T>) propertyClass; return NameUtils.toEnumValue( uncheckedEnumClass, stringEnumName ); } private  EnumValueUtils(); }
EnumValueUtils { @Nullable public static <T extends Enum<T>> T resolveEnumValue( @Nonnull Object object, @Nonnull String propertyPath, @Nullable Object enumValueName ) { final String stringEnumName = (enumValueName == null) ? null : enumValueName.toString(); if ( stringEnumName == null ) { return null; } final Class<?> propertyClass; try { propertyClass = PropertyUtils.getPropertyType( object, propertyPath ); } catch ( IllegalAccessException | InvocationTargetException | NoSuchMethodException | IllegalArgumentException e ) { throw new IllegalArgumentException( "Could not resolve property " + propertyPath + " of object " + object.getClass().getSimpleName(), e ); } if ( !propertyClass.isEnum() ) { throw new IllegalArgumentException( "Property " + propertyPath + " of object " + object.getClass().getSimpleName() + " is no enumeration class: " + propertyClass.getSimpleName() ); } @SuppressWarnings( "unchecked" ) final Class<T> uncheckedEnumClass = (Class<T>) propertyClass; return NameUtils.toEnumValue( uncheckedEnumClass, stringEnumName ); } private  EnumValueUtils(); @Nullable static T resolveEnumValue( @Nonnull Object object, @Nonnull String propertyPath, @Nullable Object enumValueName ); }
EnumValueUtils { @Nullable public static <T extends Enum<T>> T resolveEnumValue( @Nonnull Object object, @Nonnull String propertyPath, @Nullable Object enumValueName ) { final String stringEnumName = (enumValueName == null) ? null : enumValueName.toString(); if ( stringEnumName == null ) { return null; } final Class<?> propertyClass; try { propertyClass = PropertyUtils.getPropertyType( object, propertyPath ); } catch ( IllegalAccessException | InvocationTargetException | NoSuchMethodException | IllegalArgumentException e ) { throw new IllegalArgumentException( "Could not resolve property " + propertyPath + " of object " + object.getClass().getSimpleName(), e ); } if ( !propertyClass.isEnum() ) { throw new IllegalArgumentException( "Property " + propertyPath + " of object " + object.getClass().getSimpleName() + " is no enumeration class: " + propertyClass.getSimpleName() ); } @SuppressWarnings( "unchecked" ) final Class<T> uncheckedEnumClass = (Class<T>) propertyClass; return NameUtils.toEnumValue( uncheckedEnumClass, stringEnumName ); } private  EnumValueUtils(); @Nullable static T resolveEnumValue( @Nonnull Object object, @Nonnull String propertyPath, @Nullable Object enumValueName );  }