public static Prefer valueOf ( final String value ) { if ( nonNull ( value ) ) { final Map < String , String > data = new HashMap <> ( ) ; final Set < String > params = new HashSet <> ( ) ; stream ( value . split ( ";" ) ) . map ( String :: trim ) . map ( pref -> pref . split ( "=" , 2 ) ) . forEach ( x -> { if ( x . length == 2 ) { data . put ( x [ 0 ] . trim ( ) , x [ 1 ] . trim ( ) ) ; } else { params . add ( x [ 0 ] . trim ( ) ) ; } } ) ; final String waitValue = data . get ( PREFER_WAIT ) ; try { Integer wait = null ; if ( nonNull ( waitValue ) ) { wait = parseInt ( waitValue ) ; } return new Prefer ( data . get ( PREFER_RETURN ) , parseParameter ( data . get ( PREFER_INCLUDE ) ) , parseParameter ( data . get ( PREFER_OMIT ) ) , params , data . get ( PREFER_HANDLING ) , wait ) ; } catch ( final NumberFormatException ex ) { LOGGER . error ( "Cannot parse wait parameter value {}: {}" , waitValue , ex . getMessage ( ) ) ; } } return null ; }
Create a Prefer header representation from a header string