Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.skife.jdbi.v2;
  
  
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
 
 {
     private final Map<Class<?>, ContainerFactory<?>> cache     = new ConcurrentHashMap<Class<?>, ContainerFactory<?>>();
     private final List<ContainerFactory>             factories = new CopyOnWriteArrayList<ContainerFactory>();
 
     {
         .add(new ListContainerFactory());
         .add(new SetContainerFactory());
         .add(new SortedSetContainerFactory());
         .add(new UnwrappedSingleValueFactory());
     }
 
     {
         .putAll(parent.cache);
         .addAll(parent.factories);
     }
 
     void register(ContainerFactory<?> factory)
     {
         .add(factory);
         .clear();
     }
 
     {
         return new ContainerFactoryRegistry(this);
     }
 
     public ContainerBuilder createBuilderFor(Class<?> type)
     {
         if (.containsKey(type)) {
             return .get(type).newContainerBuilderFor(type);
         }
 
 
         for (int i = .size(); i > 0; i--) {
             ContainerFactory factory = .get(i - 1);
             if (factory.accepts(type)) {
                 .put(typefactory);
                 return factory.newContainerBuilderFor(type);
             }
         }
 
         throw new IllegalStateException("No container builder available for " + type.getName());
     }
 
     static class SortedSetContainerFactory implements ContainerFactory<SortedSet<?>> {
 
         public boolean accepts(Class<?> type)
         {
             return type.equals(SortedSet.class);
         }
 
         public ContainerBuilder<SortedSet<?>> newContainerBuilderFor(Class<?> type)
         {
             return new ContainerBuilder<SortedSet<?>>()
             {
                 private SortedSet<Objects = new TreeSet<Object>();
 
                 public ContainerBuilder<SortedSet<?>> add(Object it)
                 {
                     .add(it);
                     return this;
                 }
 
                 public SortedSet<?> build()
                 {
                     return ;
                 }
             };
         }
     }
 
     static class SetContainerFactory implements ContainerFactory<Set<?>>
     {
 
         public boolean accepts(Class<?> type)
         {
             return Set.class.equals(type) || LinkedHashSet.class.equals(type);
         }
 
         public ContainerBuilder<Set<?>> newContainerBuilderFor(Class<?> type)
         {
            return new ContainerBuilder<Set<?>>()
            {
                private Set<Objects = new LinkedHashSet<Object>();
                public ContainerBuilder<Set<?>> add(Object it)
                {
                    .add(it);
                    return this;
                }
                public Set<?> build()
                {
                    return ;
                }
            };
        }
    }
    static class ListContainerFactory implements ContainerFactory<List<?>>
    {
        public boolean accepts(Class<?> type)
        {
            return type.equals(List.class) || type.equals(Collection.class) || type.equals(Iterable.class);
        }
        public ContainerBuilder<List<?>> newContainerBuilderFor(Class<?> type)
        {
            return new ListContainerBuilder();
        }
    }
New to GrepCode? Check out our FAQ X