Skip to content

Commit b89eb5f

Browse files
committed
fix: polish
1 parent 617a3a1 commit b89eb5f

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/IntrospectionUtils.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,22 @@ public EntityIntrospectionResult(Class<?> entity) {
108108
}
109109

110110
this.entity = entity;
111-
this.descriptors = Stream.of(beanInfo.getPropertyDescriptors())
112-
.map(AttributePropertyDescriptor::new)
113-
.collect(Collectors.toMap(AttributePropertyDescriptor::getName, it -> it));
111+
112+
Map<String, PropertyDescriptor> map = Stream.of(beanInfo.getPropertyDescriptors())
113+
.collect(Collectors.toMap(PropertyDescriptor::getName,
114+
Function.identity()));
114115

115116
this.fields = getClasses().flatMap(k -> Arrays.stream(k.getDeclaredFields()))
116-
.filter(f -> descriptors.containsKey(Introspector.decapitalize(f.getName())))
117-
.collect(Collectors.toMap(Field::getName, it -> it));
117+
.filter(f -> map.containsKey(Introspector.decapitalize(f.getName())))
118+
.collect(Collectors.toMap(Field::getName,
119+
Function.identity()));
120+
121+
this.descriptors = map.values()
122+
.stream()
123+
.map(AttributePropertyDescriptor::new)
124+
.collect(Collectors.toMap(AttributePropertyDescriptor::getName,
125+
Function.identity()));
126+
118127
}
119128

120129
public Collection<AttributePropertyDescriptor> getPropertyDescriptors() {
@@ -168,9 +177,12 @@ public Stream<Class<?>> getClasses() {
168177
public class AttributePropertyDescriptor {
169178

170179
private final PropertyDescriptor delegate;
180+
private final Optional<Field> field;
171181

172182
public AttributePropertyDescriptor(PropertyDescriptor delegate) {
173183
this.delegate = delegate;
184+
this.field = Optional.ofNullable(fields.getOrDefault(getName(),
185+
fields.get(capitalize(getName()))));
174186
}
175187

176188
public PropertyDescriptor getDelegate() {
@@ -185,16 +197,8 @@ public String getName() {
185197
return delegate.getName();
186198
}
187199

188-
private String getFieldName() {
189-
String name = getName();
190-
191-
return fields.containsKey(name)
192-
? name
193-
: Character.toUpperCase(name.charAt(0)) + name.substring(1);
194-
}
195-
196200
public Optional<Field> getField() {
197-
return Optional.ofNullable(fields.get(getFieldName()));
201+
return field;
198202
}
199203

200204
public boolean hasField() {
@@ -344,5 +348,9 @@ public T next() {
344348
Spliterators.spliteratorUnknownSize( iterator, Spliterator.ORDERED | Spliterator.IMMUTABLE),
345349
false
346350
);
347-
}
351+
}
352+
353+
private static String capitalize(String str) {
354+
return Character.toUpperCase(str.charAt(0)) + str.substring(1);
355+
}
348356
}

0 commit comments

Comments
 (0)