17
17
18
18
import java .util .HashMap ;
19
19
import java .util .Map ;
20
+ import java .util .function .BiFunction ;
20
21
import java .util .function .Function ;
21
22
22
23
import org .springframework .hateoas .AffordanceModel .PayloadMetadata ;
23
24
import org .springframework .hateoas .AffordanceModel .PropertyMetadata ;
25
+ import org .springframework .hateoas .AffordanceModel .PropertyCreationContext ;
24
26
import org .springframework .lang .Nullable ;
25
27
import org .springframework .util .Assert ;
26
28
34
36
*/
35
37
class HalFormsOptionsFactory {
36
38
37
- private final Map <Class <?>, Map <String , Function <PropertyMetadata , HalFormsOptions >>> options ;
39
+ private final Map <Class <?>, Map <String , BiFunction <PropertyMetadata , PropertyCreationContext , HalFormsOptions >>> options ;
38
40
39
41
/**
40
42
* Creates a new, empty {@link HalFormsOptionsFactory}.
@@ -48,7 +50,7 @@ public HalFormsOptionsFactory() {
48
50
*
49
51
* @param options must not be {@literal null}.
50
52
*/
51
- private HalFormsOptionsFactory (Map <Class <?>, Map <String , Function <PropertyMetadata , HalFormsOptions >>> options ) {
53
+ private HalFormsOptionsFactory (Map <Class <?>, Map <String , BiFunction <PropertyMetadata , PropertyCreationContext , HalFormsOptions >>> options ) {
52
54
this .options = options ;
53
55
}
54
56
@@ -64,13 +66,13 @@ private HalFormsOptionsFactory(Map<Class<?>, Map<String, Function<PropertyMetada
64
66
* @see HalFormsOptions#remote(org.springframework.hateoas.Link)
65
67
*/
66
68
HalFormsOptionsFactory withOptions (Class <?> type , String property ,
67
- Function <PropertyMetadata , HalFormsOptions > creator ) {
69
+ BiFunction <PropertyMetadata , PropertyCreationContext , HalFormsOptions > creator ) {
68
70
69
71
Assert .notNull (type , "Type must not be null!" );
70
72
Assert .hasText (property , "Property must not be null or empty!" );
71
73
Assert .notNull (creator , "Creator function must not be null!" );
72
74
73
- Map <Class <?>, Map <String , Function <PropertyMetadata , HalFormsOptions >>> options = new HashMap <>(this .options );
75
+ Map <Class <?>, Map <String , BiFunction <PropertyMetadata , PropertyCreationContext , HalFormsOptions >>> options = new HashMap <>(this .options );
74
76
75
77
options .compute (type , (it , map ) -> {
76
78
@@ -95,22 +97,22 @@ HalFormsOptionsFactory withOptions(Class<?> type, String property,
95
97
* @return
96
98
*/
97
99
@ Nullable
98
- HalFormsOptions getOptions (PayloadMetadata payload , PropertyMetadata property ) {
100
+ HalFormsOptions getOptions (PayloadMetadata payload , PropertyMetadata property , PropertyCreationContext context ) {
99
101
100
102
Assert .notNull (payload , "Payload metadata must not be null!" );
101
103
Assert .notNull (property , "Property metadata must not be null!" );
102
104
103
105
Class <?> type = payload .getType ();
104
106
String name = property .getName ();
105
107
106
- Map <String , Function <PropertyMetadata , HalFormsOptions >> map = options .get (type );
108
+ Map <String , BiFunction <PropertyMetadata , PropertyCreationContext , HalFormsOptions >> map = options .get (type );
107
109
108
110
if (map == null ) {
109
111
return null ;
110
112
}
111
113
112
- Function <PropertyMetadata , HalFormsOptions > function = map .get (name );
114
+ BiFunction <PropertyMetadata , PropertyCreationContext , HalFormsOptions > function = map .get (name );
113
115
114
- return function == null ? null : function .apply (property );
116
+ return function == null ? null : function .apply (property , context );
115
117
}
116
118
}
0 commit comments