Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.databind.type;
 
Simple replacement for java.lang.Class (and/or various Type subtypes) that is used as part of single-path extends/implements chain to express specific relationship between one subtype and one supertype. This is needed for resolving type parameters. Instances are doubly-linked so that chain can be traversed in both directions
public class HierarchicType
{
    
Type which will be either plain java.lang.Class or java.lang.reflect.ParameterizedType.
    protected final Type _actualType;
    
    protected final Class<?> _rawClass;
    protected final ParameterizedType _genericType;
    
    protected HierarchicType _superType;
    protected HierarchicType _subType;
    
    public HierarchicType(Type type)
    {
        this. = type;
        if (type instanceof Class<?>) {
             = (Class<?>) type;
             = null;
        } else if (type instanceof ParameterizedType) {
             = (ParameterizedTypetype;
             = (Class<?>) .getRawType();
        } else { // should never happen... can't extend GenericArrayType?
            throw new IllegalArgumentException("Type "+type.getClass().getName()+" can not be used to construct HierarchicType");
        }
    }
    private HierarchicType(Type actualTypeClass<?> rawClassParameterizedType genericType,
        HierarchicType superTypeHierarchicType subType)
    {
         = actualType;
         = rawClass;
         = genericType;
         = superType;
         = subType;
    }
    
    
Method that can be used to create a deep clone of this hierarchic type, including super types (but not subtypes)
    {
        HierarchicType sup = ( == null) ? null : .deepCloneWithoutSubtype();
        HierarchicType result = new HierarchicType(supnull);
        if (sup != null) {
            sup.setSubType(result);
        }
        return result;
    }
    
    public void setSuperType(HierarchicType sup) {  = sup; }
    public final HierarchicType getSuperType() { return ; }
    public void setSubType(HierarchicType sub) {  = sub; }
    public final HierarchicType getSubType() { return ; }
    
    public final boolean isGeneric() { return  != null; }
    public final ParameterizedType asGeneric() { return ; }
    public final Class<?> getRawClass() { return ; }
    
    @Override
    public String toString() {
        if ( != null) {
            return .toString();
        }
        return .getName();
    }
    
New to GrepCode? Check out our FAQ X