public static < T , V > T update ( T object , Class < V > type , String pattern , Bifunctor < V , String , V > updater ) { if ( type . isPrimitive ( ) ) { throw new IllegalArgumentException ( "Primitive type must be boxed" ) ; } Pattern regex = pattern != null ? Pattern . compile ( pattern ) : null ; for ( Field field : object . getClass ( ) . getFields ( ) ) { if ( ( regex == null || regex . matcher ( field . getName ( ) ) . matches ( ) ) && type . isAssignableFrom ( boxPrimitive ( field . getType ( ) ) ) ) { try { field . set ( object , updater . invoke ( field . getName ( ) , type . cast ( field . get ( object ) ) ) ) ; } catch ( Exception x ) { } } } return object ; }
Updates an object by modifying all of its public fields that match a certain name pattern or a super type with a transforming function .