Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.type;
  
  
Type that represents things that act similar to java.util.Collection; but may or may not be instances of that interface. This specifically allows framework to check for configuration and annotation settings used for Map types, and pass these to custom handlers that may be more familiar with actual type.
 
 public class CollectionLikeType extends TypeBase
 {
     private static final long serialVersionUID = -2079769185110719683L;

    
Type of elements in collection
 
     protected final JavaType _elementType;
 
     /*
     /**********************************************************
     /* Life-cycle
     /**********************************************************
      */
 
     protected CollectionLikeType(Class<?> collTJavaType elemT,
             Object valueHandlerObject typeHandler)
     {
         super(collTelemT.hashCode(), valueHandlertypeHandler);
          = elemT;
     }
     
     @Override
     protected JavaType _narrow(Class<?> subclass) {
         return new CollectionLikeType(subclass,
                 );
     }
 
     @Override
     public JavaType narrowContentsBy(Class<?> contentClass)
     {
         // Can do a quick check first:
         if (contentClass == .getRawClass()) {
             return this;
         }
         return new CollectionLikeType(.narrowBy(contentClass),
                 );    }
 
     @Override
     public JavaType widenContentsBy(Class<?> contentClass)
     {
         // Can do a quick check first:
         if (contentClass == .getRawClass()) {
             return this;
         }
         return new CollectionLikeType(.widenBy(contentClass),
                 );
     }
     
     public static CollectionLikeType construct(Class<?> rawTypeJavaType elemT)
     {
         // nominally component types will be just Object.class
         return new CollectionLikeType(rawTypeelemTnullnull);
     }
 
     @Override
     {
         return new CollectionLikeType(h);
     }
 
     @Override
     {
         return new CollectionLikeType(.withTypeHandler(h),
                 );
     }
 
     @Override
     public CollectionLikeType withValueHandler(Object h) {
         return new CollectionLikeType(h);
     }
 
     @Override
         return new CollectionLikeType(.withValueHandler(h),
                 );
     }
     
     /*
     /**********************************************************
     /* Public API
     /**********************************************************
      */
 
     @Override
    public boolean isContainerType() { return true; }
    @Override
    public boolean isCollectionLikeType() { return true; }
    
    @Override
    public JavaType getContentType() { return ; }
    @Override
    public int containedTypeCount() { return 1; }
    @Override
    public JavaType containedType(int index) {
            return (index == 0) ?  : null;
    }

    
Not sure if we should count on this, but type names for core interfaces use "E" for element type
    @Override
    public String containedTypeName(int index) {
        if (index == 0) return "E";
        return null;
    }
    @Override
        return _classSignature(sbtrue);
    }
    
    @Override
        _classSignature(sbfalse);
        sb.append('<');
        sb.append(">;");
        return sb;
    }
    
    @Override
    protected String buildCanonicalName() {
        StringBuilder sb = new StringBuilder();
        sb.append(.getName());
        if ( != null) {
            sb.append('<');
            sb.append(.toCanonical());
            sb.append('>');
        }
        return sb.toString();
    }
    /*
    /**********************************************************
    /* Extended API
    /**********************************************************
     */

    
Method that can be used for checking whether this type is a "real" Collection type; meaning whether it represents a parameterized subtype of java.util.Collection or just something that acts like one.
    public boolean isTrueCollectionType() {
        return Collection.class.isAssignableFrom();
    }
    /*
    /**********************************************************
    /* Standard methods
    /**********************************************************
     */
    @Override
    public boolean equals(Object o)
    {
        if (o == thisreturn true;
        if (o == nullreturn false;
        if (o.getClass() != getClass()) return false;
        CollectionLikeType other = (CollectionLikeTypeo;
        return  ( == other._class) && .equals(other._elementType);
    }
    @Override
    public String toString()
    {
        return "[collection-like type; class "+.getName()+", contains "++"]";
    }
New to GrepCode? Check out our FAQ X