41
41
*/
42
42
final class GroupsMetadata {
43
43
44
- private final Map <String , DefaultRegistration > groupMap ;
44
+ private final Map <String , Registration > groupMap ;
45
45
46
46
public GroupsMetadata () {
47
47
this (Collections .emptyList ());
48
48
}
49
49
50
- GroupsMetadata (Iterable <DefaultRegistration > registrations ) {
50
+ GroupsMetadata (Iterable <Registration > registrations ) {
51
51
this .groupMap = new LinkedHashMap <>();
52
52
registrations .forEach (registration -> this .groupMap .put (registration .name (), registration ));
53
53
}
@@ -58,7 +58,7 @@ public GroupsMetadata() {
58
58
* types after checking they don't conflict.
59
59
*/
60
60
public Registration getOrCreateGroup (String groupName , HttpServiceGroup .ClientType clientType ) {
61
- return this .groupMap .computeIfAbsent (groupName , name -> new DefaultRegistration (name , clientType ))
61
+ return this .groupMap .computeIfAbsent (groupName , name -> new Registration (name , clientType ))
62
62
.clientType (clientType );
63
63
}
64
64
@@ -94,71 +94,51 @@ public Collection<HttpServiceGroup> groups(@Nullable ClassLoader classLoader) {
94
94
/**
95
95
* Return the raw {@link DefaultRegistration registrations}.
96
96
*/
97
- Stream <DefaultRegistration > registrations () {
97
+ Stream <Registration > registrations () {
98
98
return this .groupMap .values ().stream ();
99
99
}
100
100
101
101
102
102
/**
103
103
* Registration metadata for an {@link HttpServiceGroup}.
104
104
*/
105
- interface Registration {
106
-
107
- String name ();
108
-
109
- HttpServiceGroup .ClientType clientType ();
110
-
111
- Set <String > httpServiceTypeNames ();
112
- }
113
-
114
-
115
- /**
116
- * Default implementation of {@link Registration}.
117
- */
118
- static class DefaultRegistration implements Registration {
105
+ static class Registration {
119
106
120
107
private final String name ;
121
108
122
109
private HttpServiceGroup .ClientType clientType ;
123
110
124
- private final Set <String > typeNames ;
111
+ private final Set <String > httpServiceTypeNames ;
125
112
126
- DefaultRegistration (String name , HttpServiceGroup .ClientType clientType ) {
113
+ Registration (String name , HttpServiceGroup .ClientType clientType ) {
127
114
this (name , clientType , new LinkedHashSet <>());
128
115
}
129
116
130
- DefaultRegistration (String name , HttpServiceGroup .ClientType clientType , Set <String > typeNames ) {
117
+ Registration (String name , HttpServiceGroup .ClientType clientType , Set <String > httpServiceTypeNames ) {
131
118
this .name = name ;
132
119
this .clientType = clientType ;
133
- this .typeNames = typeNames ;
120
+ this .httpServiceTypeNames = httpServiceTypeNames ;
134
121
}
135
122
136
- @ Override
137
- public String name () {
123
+ String name () {
138
124
return this .name ;
139
125
}
140
126
141
- @ Override
142
- public HttpServiceGroup .ClientType clientType () {
127
+ HttpServiceGroup .ClientType clientType () {
143
128
return this .clientType ;
144
129
}
145
130
146
- @ Override
147
- public Set <String > httpServiceTypeNames () {
148
- return this .typeNames ;
131
+ Set <String > httpServiceTypeNames () {
132
+ return this .httpServiceTypeNames ;
149
133
}
150
134
151
135
/**
152
136
* Update the client type if it does not conflict with the existing value.
153
137
*/
154
- public DefaultRegistration clientType (HttpServiceGroup .ClientType other ) {
155
- if (this .clientType .isUnspecified ()) {
156
- this .clientType = other ;
157
- }
158
- else {
159
- Assert .isTrue (this .clientType == other || other .isUnspecified (),
160
- "ClientType conflict for HttpServiceGroup '" + this .name + "'" );
161
- }
138
+ public Registration clientType (HttpServiceGroup .ClientType other ) {
139
+ this .clientType = (this .clientType .isUnspecified () ? other : this .clientType );
140
+ Assert .isTrue (this .clientType == other || other .isUnspecified (),
141
+ "ClientType conflict for HttpServiceGroup '" + this .name + "'" );
162
142
return this ;
163
143
}
164
144
@@ -168,15 +148,16 @@ public DefaultRegistration clientType(HttpServiceGroup.ClientType other) {
168
148
public HttpServiceGroup toHttpServiceGroup (@ Nullable ClassLoader classLoader ) {
169
149
return new RegisteredGroup (this .name ,
170
150
(this .clientType .isUnspecified () ? HttpServiceGroup .ClientType .REST_CLIENT : this .clientType ),
171
- this .typeNames .stream ()
151
+ this .httpServiceTypeNames .stream ()
172
152
.map (typeName -> ClassUtils .resolveClassName (typeName , classLoader ))
173
153
.collect (Collectors .toSet ()));
174
154
}
175
155
176
156
@ Override
177
157
public String toString () {
178
- return "Group '" + this .name + "', ClientType." + this .clientType + ", " + this .typeNames ;
158
+ return "Group '" + this .name + "', ClientType." + this .clientType + ", " + this .httpServiceTypeNames ;
179
159
}
160
+
180
161
}
181
162
182
163
0 commit comments