Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.type;
  
  import java.util.*;
  
Simple types are defined as anything other than one of recognized container types (arrays, Collections, Maps). For our needs we need not know anything further, since we have no way of dealing with generic types other than Collections and Maps.
 
 public final class SimpleType
     extends TypeBase
 {
     private static final long serialVersionUID = -800374828948534376L;

    
Generic type arguments for this type.
 
     protected final JavaType[] _typeParameters;

    
Names of generic type arguments for this type; will match values in _typeParameters
 
     protected final String[] _typeNames;
     
     /*
     /**********************************************************
     /* Life-cycle
     /**********************************************************
      */
 
     protected SimpleType(Class<?> cls) {
         this(clsnullnullnullnull);
     }
 
     protected SimpleType(Class<?> clsString[] typeNamesJavaType[] typeParams,
             Object valueHandlerObject typeHandler)
     {
         super(cls, 0, valueHandlertypeHandler);
         if (typeNames == null || typeNames.length == 0) {
              = null;
              = null;
         } else {
              = typeNames;
              = typeParams;
         }
     }

    
Method used by core Jackson classes: NOT to be used by application code.

NOTE: public only because it is called by ObjectMapper which is not in same package

 
     public static SimpleType constructUnsafe(Class<?> raw) {
         return new SimpleType(rawnullnullnullnull);
     }
     
     @Override
     protected JavaType _narrow(Class<?> subclass)
     {
         // Should we check that there is a sub-class relationship?
         return new SimpleType(subclass);
     }
 
     @Override
     public JavaType narrowContentsBy(Class<?> subclass)
     {
         // should never get called
         throw new IllegalArgumentException("Internal error: SimpleType.narrowContentsBy() should never be called");
     }
 
     @Override
     public JavaType widenContentsBy(Class<?> subclass)
     {
         // should never get called
         throw new IllegalArgumentException("Internal error: SimpleType.widenContentsBy() should never be called");
     }
     
     public static SimpleType construct(Class<?> cls)
     {
         /* Let's add sanity checks, just to ensure no
          * Map/Collection entries are constructed
          */
         if (Map.class.isAssignableFrom(cls)) {
             throw new IllegalArgumentException("Can not construct SimpleType for a Map (class: "+cls.getName()+")");
         }
         if (Collection.class.isAssignableFrom(cls)) {
             throw new IllegalArgumentException("Can not construct SimpleType for a Collection (class: "+cls.getName()+")");
         }
         // ... and while we are at it, not array types either
         if (cls.isArray()) {
             throw new IllegalArgumentException("Can not construct SimpleType for an array (class: "+cls.getName()+")");
         }
         return new SimpleType(cls);
     }
    // Since 1.7:
    @Override
    public SimpleType withTypeHandler(Object h)
    {
        return new SimpleType(h);
    }
    // Since 1.7:
    @Override
    public JavaType withContentTypeHandler(Object h) {
        // no content type, so:
        throw new IllegalArgumentException("Simple types have no content types; can not call withContenTypeHandler()");
    }
    // Since 1.9:
    @Override
    public SimpleType withValueHandler(Object h) {
        if (h == ) {
            return this;
        }
        return new SimpleType(h);
    }
    
    // Since 1.9:
    @Override
    public  SimpleType withContentValueHandler(Object h) {
        // no content type, so:
        throw new IllegalArgumentException("Simple types have no content types; can not call withContenValueHandler()");
    }
    
    @Override
    protected String buildCanonicalName()
    {
        StringBuilder sb = new StringBuilder();
        sb.append(.getName());
        if ( != null && . > 0) {
            sb.append('<');
            boolean first = true;
            for (JavaType t : ) {
                if (first) {
                    first = false;
                } else {
                    sb.append(',');
                }
                sb.append(t.toCanonical());
            }
            sb.append('>');
        }
        return sb.toString();
    }
    
    /*
    /**********************************************************
    /* Public API
    /**********************************************************
     */
    @Override
    public boolean isContainerType() { return false; }
    
    @Override
    public int containedTypeCount() {
        return ( == null) ? 0 : .;
    }
    @Override
    public JavaType containedType(int index)
    {
        if (index < 0 ||  == null || index >= .) {
            return null;
        }
        return [index];
    }
    @Override
    public String containedTypeName(int index)
    {
        if (index < 0 ||  == null || index >= .) {
            return null;
        }
        return [index];
    }
    
    @Override
        return _classSignature(sbtrue);
    }
    
    @Override
    {
        _classSignature(sbfalse);
        if ( != null) {
            sb.append('<');
            for (JavaType param : ) {
                sb = param.getGenericSignature(sb);
            }
            sb.append('>');
        }
        sb.append(';');
        return sb;
    }
    
    /*
    /**********************************************************
    /* Standard methods
    /**********************************************************
     */
    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder(40);
        sb.append("[simple type, class ").append(buildCanonicalName()).append(']');
        return sb.toString();
    }
    @Override
    public boolean equals(Object o)
    {
        if (o == thisreturn true;
        if (o == nullreturn false;
        if (o.getClass() != getClass()) return false;
        SimpleType other = (SimpleTypeo;
        // Classes must be identical... 
        if (other._class != this.return false;
        // And finally, generic bindings, if any
        JavaType[] p1 = ;
        JavaType[] p2 = other._typeParameters;
        if (p1 == null) {
            return (p2 == null) || p2.length == 0;
        }
        if (p2 == nullreturn false;
        if (p1.length != p2.lengthreturn false;
        for (int i = 0, len = p1.lengthi < len; ++i) {
            if (!p1[i].equals(p2[i])) {
                return false;
            }
        }
        return true;
    }
New to GrepCode? Check out our FAQ X