orpiske commented on code in PR #11225: URL: https://github.com/apache/camel/pull/11225#discussion_r1309933015
########## core/camel-base/src/main/java/org/apache/camel/impl/converter/TypeResolverHelper.java: ########## @@ -0,0 +1,192 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.impl.converter; + +import java.util.Map; +import java.util.Optional; + +import org.apache.camel.TypeConverter; +import org.apache.camel.converter.TypeConvertible; + +/** + * Helper methods for resolving the type conversions. This is an internal API and not meant for public usages. + * + * In a broader sense: the methods of this code help with traversing the class hierarchy of the types involved in a + * conversion, so that the correct TypeConverter can be used. This is a helper class to CoreTypeConverterRegistry. + * + * In the CoreTypeConverterRegistry class, the registry of types if maintained in a ConcurrentMap that associates a type + * pair with the resolver for it (i.e.: it associates pair representing a conversion from String to Integer to a type + * converter - such as CamelBaseBulkConverterLoader). + * + * NOTE 1: a lot of this code is in the hot path of the core engine, so change with extreme caution to prevent + * performance issues on the core code. + * + * NOTE 2: also, a lot of this code runs rather slow operations, so calling these methods should be avoided as much as + * possible + * + */ +final class TypeResolverHelper { + private TypeResolverHelper() { + + } + + /** + * Lookup the type converter in the registry (given a type to convert to and a type to convert from, along with a + * mapping of all known converters) + * + * @param toType the type to convert to + * @param fromType the type to convert from + * @param converters the map of all known converters + * @return the type converter or null if unknown + */ + static TypeConverter doLookup( + Class<?> toType, Class<?> fromType, Map<TypeConvertible<?, ?>, TypeConverter> converters) { + return doLookup(new TypeConvertible<>(fromType, toType), converters); + } + + private static TypeConverter doLookup( + TypeConvertible<?, ?> typeConvertible, Map<TypeConvertible<?, ?>, TypeConverter> converters) { + + // try with base converters first + final TypeConverter typeConverter = converters.get(typeConvertible); + if (typeConverter != null) { + return typeConverter; + } + + final TypeConverter superConverterTc = tryMatch(typeConvertible, converters); + if (superConverterTc != null) { + return superConverterTc; + } + + final TypeConverter arrayConverterTc = tryObjectArrayConverters(typeConvertible, converters); Review Comment: It seems we can remove this, so this code is not longer valid. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org