MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / apply

Method apply

java/src/org/openqa/selenium/json/MapCoercer.java:50–94  ·  view source on GitHub ↗
(Type type)

Source from the content-addressed store, hash-verified

48 }
49
50 @Override
51 public BiFunction<JsonInput, PropertySetting, T> apply(Type type) {
52 Type keyType;
53 Type valueType;
54
55 if (type instanceof ParameterizedType) {
56 Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments();
57 keyType = typeArguments[0];
58 valueType = typeArguments[1];
59 } else if (type instanceof Class) {
60 keyType = Object.class;
61 valueType = Object.class;
62 } else {
63 throw new IllegalArgumentException("Unhandled type: " + type.getClass());
64 }
65
66 // JSON should always have a string key, so we can take the fastpath
67 boolean stringKey = String.class.equals(keyType);
68 // Resolve the element coercers once rather than paying a cache lookup per entry.
69 BiFunction<JsonInput, PropertySetting, Object> keyCoercer =
70 stringKey ? null : coercer.lazyResolve(keyType);
71 BiFunction<JsonInput, PropertySetting, Object> valueCoercer = coercer.lazyResolve(valueType);
72
73 return (jsonInput, setting) -> {
74 jsonInput.beginObject();
75 I toReturn = supplier.get();
76 BiConsumer<Object, Object> consumer = consumerFactory.apply(toReturn);
77
78 while (jsonInput.hasNext()) {
79 Object key;
80
81 if (stringKey) {
82 key = jsonInput.nextName();
83 } else {
84 key = keyCoercer.apply(jsonInput, setting);
85 }
86 Object value = valueCoercer.apply(jsonInput, setting);
87
88 consumer.accept(key, value);
89 }
90 jsonInput.endObject();
91
92 return toReturn;
93 };
94 }
95}

Callers

nothing calls this directly

Calls 9

lazyResolveMethod · 0.80
hasNextMethod · 0.80
nextNameMethod · 0.80
getClassMethod · 0.65
getMethod · 0.65
acceptMethod · 0.65
equalsMethod · 0.45
beginObjectMethod · 0.45
endObjectMethod · 0.45

Tested by

no test coverage detected