TypeParameterMatcher.java — netty Source File
Architecture documentation for TypeParameterMatcher.java, a java file in the netty codebase.
Entity Profile
Relationship Graph
Source Code
/*
* Copyright 2013 The Netty Project
*
* The Netty Project 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:
*
* https://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 io.netty.util.internal;
import java.util.HashMap;
import java.util.Map;
public abstract class TypeParameterMatcher {
private static final TypeParameterMatcher NOOP = new TypeParameterMatcher() {
@Override
public boolean match(Object msg) {
return true;
}
};
public static TypeParameterMatcher get(final Class<?> parameterType) {
final Map<Class<?>, TypeParameterMatcher> getCache =
InternalThreadLocalMap.get().typeParameterMatcherGetCache();
TypeParameterMatcher matcher = getCache.get(parameterType);
if (matcher == null) {
if (parameterType == Object.class) {
matcher = NOOP;
} else {
matcher = new ReflectiveMatcher(parameterType);
}
getCache.put(parameterType, matcher);
}
return matcher;
}
public static TypeParameterMatcher find(
final Object object, final Class<?> parametrizedSuperclass, final String typeParamName) {
final Map<Class<?>, Map<String, TypeParameterMatcher>> findCache =
InternalThreadLocalMap.get().typeParameterMatcherFindCache();
final Class<?> thisClass = object.getClass();
Map<String, TypeParameterMatcher> map = findCache.get(thisClass);
if (map == null) {
map = new HashMap<String, TypeParameterMatcher>();
findCache.put(thisClass, map);
}
TypeParameterMatcher matcher = map.get(typeParamName);
if (matcher == null) {
matcher = get(ReflectionUtil.resolveTypeParameter(object, parametrizedSuperclass, typeParamName));
map.put(typeParamName, matcher);
}
return matcher;
}
public abstract boolean match(Object msg);
private static final class ReflectiveMatcher extends TypeParameterMatcher {
private final Class<?> type;
ReflectiveMatcher(Class<?> type) {
this.type = type;
}
@Override
public boolean match(Object msg) {
return type.isInstance(msg);
}
}
TypeParameterMatcher() { }
}
Domain
Subdomains
Source
Frequently Asked Questions
What does TypeParameterMatcher.java do?
TypeParameterMatcher.java is a source file in the netty codebase, written in java. It belongs to the CommonUtil domain, Internal subdomain.
Where is TypeParameterMatcher.java in the architecture?
TypeParameterMatcher.java is located at common/src/main/java/io/netty/util/internal/TypeParameterMatcher.java (domain: CommonUtil, subdomain: Internal, directory: common/src/main/java/io/netty/util/internal).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free