Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   //================================================================================
   //Copyright (c) 2012, David Yu
   //All rights reserved.
   //--------------------------------------------------------------------------------
   // Redistribution and use in source and binary forms, with or without
   // modification, are permitted provided that the following conditions are met:
   // 1. Redistributions of source code must retain the above copyright notice,
   //    this list of conditions and the following disclaimer.
   // 2. Redistributions in binary form must reproduce the above copyright notice,
  //    this list of conditions and the following disclaimer in the documentation
  //    and/or other materials provided with the distribution.
  // 3. Neither the name of protostuff nor the names of its contributors may be used
  //    to endorse or promote products derived from this software without
  //    specific prior written permission.
  //
  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  // POSSIBILITY OF SUCH DAMAGE.
  //================================================================================
  
  package io.protostuff.runtime;
  
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_COLLECTION;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_ENUM;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_ENUM_SET;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_COLLECTION;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_ENUM;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_ENUM_SET;
  
  import java.util.EnumSet;
  import java.util.List;
  import java.util.Map;
  
Used when the type is an interface (Collection/List/Set/SortedSet).

Author(s):
David Yu
Created:
Apr 24, 2012
  
  public abstract class PolymorphicCollectionSchema extends PolymorphicSchema
  {
  
      static final int ID_EMPTY_SET = 1, ID_EMPTY_LIST = 2,
  
              ID_SINGLETON_SET = 3, ID_SINGLETON_LIST = 4,
  
              ID_SET_FROM_MAP = 5, ID_COPIES_LIST = 6,
  
              ID_UNMODIFIABLE_COLLECTION = 7, ID_UNMODIFIABLE_SET = 8,
              ID_UNMODIFIABLE_SORTED_SET = 9, ID_UNMODIFIABLE_LIST = 10,
              ID_UNMODIFIABLE_RANDOM_ACCESS_LIST = 11,
  
              ID_SYNCHRONIZED_COLLECTION = 12, ID_SYNCHRONIZED_SET = 13,
              ID_SYNCHRONIZED_SORTED_SET = 14, ID_SYNCHRONIZED_LIST = 15,
              ID_SYNCHRONIZED_RANDOM_ACCESS_LIST = 16,
  
              ID_CHECKED_COLLECTION = 17, ID_CHECKED_SET = 18,
              ID_CHECKED_SORTED_SET = 19, ID_CHECKED_LIST = 20,
              ID_CHECKED_RANDOM_ACCESS_LIST = 21;
  
      static final String STR_EMPTY_SET = "a"STR_EMPTY_LIST = "b",
  
              STR_SINGLETON_SET = "c"STR_SINGLETON_LIST = "d",
  
              STR_SET_FROM_MAP = "e"STR_COPIES_LIST = "f",
  
              STR_UNMODIFIABLE_COLLECTION = "g"STR_UNMODIFIABLE_SET = "h",
              STR_UNMODIFIABLE_SORTED_SET = "i"STR_UNMODIFIABLE_LIST = "j",
              STR_UNMODIFIABLE_RANDOM_ACCESS_LIST = "k",
  
              STR_SYNCHRONIZED_COLLECTION = "l"STR_SYNCHRONIZED_SET = "m",
              STR_SYNCHRONIZED_SORTED_SET = "n"STR_SYNCHRONIZED_LIST = "o",
              STR_SYNCHRONIZED_RANDOM_ACCESS_LIST = "p",
  
              STR_CHECKED_COLLECTION = "q"STR_CHECKED_SET = "r",
              STR_CHECKED_SORTED_SET = "s"STR_CHECKED_LIST = "t",
             STR_CHECKED_RANDOM_ACCESS_LIST = "u";
 
     static final IdentityHashMap<Class<?>, Integer__nonPublicCollections = new IdentityHashMap<>();
 
 
             fUnmodifiableList_list,
 
 
             fCheckedCollection_type,
 
             fSetFromMap_mfSetFromMap_s,
 
             fCopiesList_nfCopiesList_element;
 
     static final Instantiator<?> iSingletonSetiSingletonList,
 
 
 
             iCheckedRandomAccessList,
 
             iSetFromMap,
 
             iCopiesList;
 
     static
     {
         map("java.util.Collections$EmptySet");
         map("java.util.Collections$EmptyList");
 
         Class<?> cSingletonSet = map("java.util.Collections$SingletonSet",
                 );
 
         Class<?> cSingletonList = map("java.util.Collections$SingletonList",
                 );
 
         Class<?> cSetFromMap = map("java.util.Collections$SetFromMap",
                 );
 
         Class<?> cCopiesList = map("java.util.Collections$CopiesList",
                 );
 
         Class<?> cUnmodifiableCollection = map(
                 "java.util.Collections$UnmodifiableCollection",
                 );
         Class<?> cUnmodifiableSet = map(
                 "java.util.Collections$UnmodifiableSet");
         Class<?> cUnmodifiableSortedSet = map(
                 "java.util.Collections$UnmodifiableSortedSet",
                 );
         Class<?> cUnmodifiableList = map(
                 "java.util.Collections$UnmodifiableList");
         Class<?> cUnmodifiableRandomAccessList = map(
                 "java.util.Collections$UnmodifiableRandomAccessList",
                 );
 
         Class<?> cSynchronizedCollection = map(
                 "java.util.Collections$SynchronizedCollection",
                 );
         Class<?> cSynchronizedSet = map(
                 "java.util.Collections$SynchronizedSet");
         Class<?> cSynchronizedSortedSet = map(
                 "java.util.Collections$SynchronizedSortedSet",
                 );
         Class<?> cSynchronizedList = map(
                 "java.util.Collections$SynchronizedList");
         Class<?> cSynchronizedRandomAccessList = map(
                 "java.util.Collections$SynchronizedRandomAccessList",
                 );
 
         Class<?> cCheckedCollection = map(
                 "java.util.Collections$CheckedCollection",
                 );
         Class<?> cCheckedSet = map("java.util.Collections$CheckedSet",
                 );
         Class<?> cCheckedSortedSet = map(
                 "java.util.Collections$CheckedSortedSet");
         Class<?> cCheckedList = map("java.util.Collections$CheckedList",
                 );
         Class<?> cCheckedRandomAccessList = map(
                 "java.util.Collections$CheckedRandomAccessList",
                 );
 
         try
         {
              = cSingletonSet.getDeclaredField("element");
 
              = cSingletonList.getDeclaredField("element");
 
              = cSetFromMap.getDeclaredField("m");
              = cSetFromMap.getDeclaredField("s");
 
              = cCopiesList.getDeclaredField("n");
              = cCopiesList.getDeclaredField("element");
 
              = cUnmodifiableCollection
                     .getDeclaredField("c");
              = cUnmodifiableSortedSet
                     .getDeclaredField("ss");
              = cUnmodifiableList.getDeclaredField("list");
 
              = cSynchronizedCollection
                     .getDeclaredField("c");
              = cSynchronizedCollection
                     .getDeclaredField("mutex");
              = cSynchronizedSortedSet
                     .getDeclaredField("ss");
              = cSynchronizedList.getDeclaredField("list");
 
              = cCheckedCollection.getDeclaredField("c");
              = cCheckedCollection
                     .getDeclaredField("type");
              = cCheckedSortedSet.getDeclaredField("ss");
              = cCheckedList.getDeclaredField("list");
         }
         catch (Exception e)
         {
             throw new RuntimeException(e);
         }
 
         // field accessors
 
         .setAccessible(true);
 
         .setAccessible(true);
 
         .setAccessible(true);
         .setAccessible(true);
 
         .setAccessible(true);
         .setAccessible(true);
 
         .setAccessible(true);
 
         .setAccessible(true);
 
         .setAccessible(true);
         .setAccessible(true);
         .setAccessible(true);
         .setAccessible(true);
 
         // instantiators
 
          = RuntimeEnv.newInstantiator(cSingletonSet);
 
          = RuntimeEnv.newInstantiator(cSingletonList);
 
          = RuntimeEnv.newInstantiator(cSetFromMap);
 
          = RuntimeEnv.newInstantiator(cCopiesList);
 
          = RuntimeEnv
                 .newInstantiator(cUnmodifiableCollection);
          = RuntimeEnv.newInstantiator(cUnmodifiableSet);
          = RuntimeEnv
                 .newInstantiator(cUnmodifiableSortedSet);
          = RuntimeEnv.newInstantiator(cUnmodifiableList);
          = RuntimeEnv
                 .newInstantiator(cUnmodifiableRandomAccessList);
 
          = RuntimeEnv
                 .newInstantiator(cSynchronizedCollection);
          = RuntimeEnv.newInstantiator(cSynchronizedSet);
          = RuntimeEnv
                 .newInstantiator(cSynchronizedSortedSet);
          = RuntimeEnv.newInstantiator(cSynchronizedList);
          = RuntimeEnv
                 .newInstantiator(cSynchronizedRandomAccessList);
 
          = RuntimeEnv.newInstantiator(cCheckedCollection);
          = RuntimeEnv.newInstantiator(cCheckedSet);
          = RuntimeEnv.newInstantiator(cCheckedSortedSet);
          = RuntimeEnv.newInstantiator(cCheckedList);
          = RuntimeEnv
                 .newInstantiator(cCheckedRandomAccessList);
     }
 
     private static Class<?> map(String classNameint id)
     {
         Class<?> clazz = RuntimeEnv.loadClass(className);
         .put(clazzid);
         return clazz;
     }
 
     static String name(int number)
     {
         switch (number)
         {
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             default:
                 return null;
         }
     }
 
     static int number(String name)
     {
         if (name.length() != 1)
             return 0;
 
         switch (name.charAt(0))
         {
             case 'a':
                 return 1;
             case 'b':
                 return 2;
             case 'c':
                 return 3;
             case 'd':
                 return 4;
             case 'e':
                 return 5;
             case 'f':
                 return 6;
             case 'g':
                 return 7;
             case 'h':
                 return 8;
             case 'i':
                 return 9;
             case 'j':
                 return 10;
             case 'k':
                 return 11;
             case 'l':
                 return 12;
             case 'm':
                 return 13;
             case 'n':
                 return 14;
             case 'o':
                 return 15;
             case 'p':
                 return 16;
             case 'q':
                 return 17;
             case 'r':
                 return 18;
             case 's':
                 return 19;
             case 't':
                 return 20;
             case 'u':
                 return 21;
             case 'v':
                 return ;
             case 'x':
                 return ;
             case 'y':
                 return ;
             default:
                 return 0;
         }
     }
 
     protected final Pipe.Schema<ObjectpipeSchema = new Pipe.Schema<Object>(
             this)
     {
         @Override
         protected void transfer(Pipe pipeInput inputOutput output)
                 throws IOException
         {
             transferObject(thispipeinputoutput);
         }
     };
 
     public PolymorphicCollectionSchema(IdStrategy strategy)
     {
         super(strategy);
     }
 
     @Override
     public Pipe.Schema<ObjectgetPipeSchema()
     {
         return ;
     }
 
     @Override
     public String getFieldName(int number)
     {
         return name(number);
     }
 
     @Override
     public int getFieldNumber(String name)
     {
         return number(name);
     }
 
     @Override
     public String messageFullName()
     {
         return Collection.class.getName();
     }
 
     @Override
     public String messageName()
     {
         return Collection.class.getSimpleName();
     }
 
     @Override
     public void mergeFrom(Input inputObject ownerthrows IOException
     {
         setValue(readObjectFrom(inputthisowner), owner);
     }
 
     @Override
     public void writeTo(Output outputObject valuethrows IOException
     {
         writeObjectTo(outputvaluethis);
     }
 
     static int idFrom(Class<?> clazz)
     {
         final Integer id = .get(clazz);
         if (id == null)
             throw new RuntimeException("Unknown collection: " + clazz);
 
         return id.intValue();
     }
 
     static Object instanceFrom(final int id)
     {
         switch (id)
         {
             case :
                 return .;
             case :
                 return .;
 
             case :
                 return .newInstance();
             case :
                 return .newInstance();
 
             case :
                 return .newInstance();
             case :
                 return .newInstance();
 
             case :
                 return .newInstance();
             case :
                 return .newInstance();
             case :
                 return .newInstance();
             case :
                 return .newInstance();
             case :
                 return .newInstance();
 
             case :
                 return .newInstance();
             case :
                 return .newInstance();
             case :
                 return .newInstance();
             case :
                 return .newInstance();
             case :
                 return .newInstance();
 
             case :
                 return .newInstance();
             case :
                 return .newInstance();
             case :
                 return .newInstance();
             case :
                 return .newInstance();
             case :
                 return .newInstance();
 
             default:
                 throw new RuntimeException("Unknown id: " + id);
         }
     }
 
     @SuppressWarnings("unchecked")
     static void writeObjectTo(Output outputObject value,
             Schema<?> currentSchemaIdStrategy strategythrows IOException
     {
         if (Collections.class == value.getClass().getDeclaringClass())
         {
             writeNonPublicCollectionTo(outputvaluecurrentSchemastrategy);
             return;
         }
 
         if (EnumSet.class.isAssignableFrom(value.getClass()))
         {
             strategy.writeEnumIdTo(output,
                     EnumIO.getElementTypeFromEnumSet(value));
 
             // TODO optimize
         }
         else
         {
             strategy.writeCollectionIdTo(output,
                     value.getClass());
         }
 
         if (output instanceof StatefulOutput)
         {
             // update using the derived schema.
             ((StatefulOutputoutput).updateLast(strategy.COLLECTION_SCHEMA,
                     currentSchema);
         }
 
         strategy.COLLECTION_SCHEMA.writeTo(output, (Collection<Object>) value);
     }
 
     static void writeNonPublicCollectionTo(Output outputObject value,
             Schema<?> currentSchemaIdStrategy strategythrows IOException
     {
         final Integer num = .get(value.getClass());
         if (num == null)
             throw new RuntimeException("Unknown collection: "
                     + value.getClass());
         final int id = num.intValue();
         switch (id)
         {
             case :
                 output.writeUInt32(id, 0, false);
                 break;
 
             case :
                 output.writeUInt32(id, 0, false);
                 break;
 
             case :
             {
                 output.writeUInt32(id, 0, false);
 
                 final Object element;
                 try
                 {
                     element = .get(value);
                 }
                 catch (IllegalArgumentException | IllegalAccessException e)
                 {
                     throw new RuntimeException(e);
                 }
 
                 if (element != null)
                     output.writeObject(1, elementstrategy.OBJECT_SCHEMAfalse);
 
                 break;
             }
 
             case :
             {
                 output.writeUInt32(id, 0, false);
 
                 // faster path (reflection not needed to get the single element).
                 final Object element = ((List<?>) value).get(0);
 
                 if (element != null)
                     output.writeObject(1, elementstrategy.OBJECT_SCHEMAfalse);
 
                 break;
             }
 
             case :
             {
                 final Object m;
                 try
                 {
                     m = .get(value);
                 }
                 catch (IllegalArgumentException | IllegalAccessException e)
                 {
                     throw new RuntimeException(e);
                 }
 
                 output.writeObject(idmstrategy.POLYMORPHIC_MAP_SCHEMAfalse);
 
                 break;
             }
 
             case :
             {
                 output.writeUInt32(id, 0, false);
 
                 final int n = ((List<?>) value).size();
                 final Object element;
                 try
                 {
                     element = .get(value);
                 }
                 catch (IllegalArgumentException | IllegalAccessException e)
                 {
                     throw new RuntimeException(e);
                 }
 
                 output.writeUInt32(1, nfalse);
 
                 if (element != null)
                     output.writeObject(2, elementstrategy.OBJECT_SCHEMAfalse);
 
                 break;
             }
             case :
                 writeUnmodifiableCollectionTo(outputvaluecurrentSchema,
                         strategyid);
                 break;
             case :
                 writeUnmodifiableCollectionTo(outputvaluecurrentSchema,
                         strategyid);
                 break;
             case :
                 writeUnmodifiableCollectionTo(outputvaluecurrentSchema,
                         strategyid);
                 break;
             case :
                 writeUnmodifiableCollectionTo(outputvaluecurrentSchema,
                         strategyid);
                 break;
             case :
                 writeUnmodifiableCollectionTo(outputvaluecurrentSchema,
                         strategyid);
                 break;
 
             case :
                 writeSynchronizedCollectionTo(outputvaluecurrentSchema,
                         strategyid);
                 break;
             case :
                 writeSynchronizedCollectionTo(outputvaluecurrentSchema,
                         strategyid);
                 break;
             case :
                 writeSynchronizedCollectionTo(outputvaluecurrentSchema,
                         strategyid);
                 break;
             case :
                 writeSynchronizedCollectionTo(outputvaluecurrentSchema,
                         strategyid);
                 break;
             case :
                 writeSynchronizedCollectionTo(outputvaluecurrentSchema,
                         strategyid);
                 break;
 
             case :
                 writeCheckedCollectionTo(outputvaluecurrentSchemastrategyid);
                 break;
             case :
                 writeCheckedCollectionTo(outputvaluecurrentSchemastrategyid);
                 break;
             case :
                 writeCheckedCollectionTo(outputvaluecurrentSchemastrategyid);
                 break;
             case :
                 writeCheckedCollectionTo(outputvaluecurrentSchemastrategyid);
                 break;
             case :
                 writeCheckedCollectionTo(outputvaluecurrentSchemastrategyid);
                 break;
 
             default:
                 throw new RuntimeException("Should not happen.");
         }
     }
 
     private static void writeUnmodifiableCollectionTo(Output output,
             Object valueSchema<?> currentSchemaIdStrategy strategyint id)
             throws IOException
     {
         final Object c;
         try
         {
             c = .get(value);
         }
         catch (IllegalArgumentException | IllegalAccessException e)
         {
             throw new RuntimeException(e);
         }
 
         output.writeObject(idcstrategy.POLYMORPHIC_COLLECTION_SCHEMAfalse);
     }
 
     private static void writeSynchronizedCollectionTo(Output output,
             Object valueSchema<?> currentSchemaIdStrategy strategyint id)
             throws IOException
     {
         final Object cmutex;
         try
         {
             c = .get(value);
             mutex = .get(value);
         }
         catch (IllegalArgumentException | IllegalAccessException e)
         {
             throw new RuntimeException(e);
         }
 
         if (mutex != value)
         {
             // TODO for future release, introduce an interface(GraphOutput) so
             // we
             // can check whether the output can retain references.
             throw new RuntimeException(
                     "This exception is thrown to fail fast. "
                             + "Synchronized collections with a different mutex would only "
                             + "work if graph format is used, since the reference is retained.");
         }
 
         output.writeObject(idcstrategy.POLYMORPHIC_COLLECTION_SCHEMAfalse);
     }
 
     private static void writeCheckedCollectionTo(Output outputObject value,
             Schema<?> currentSchemaIdStrategy strategyint id)
             throws IOException
     {
         final Object ctype;
         try
         {
             c = .get(value);
             type = .get(value);
         }
         catch (IllegalArgumentException | IllegalAccessException e)
         {
             throw new RuntimeException(e);
         }
 
         output.writeObject(idcstrategy.POLYMORPHIC_COLLECTION_SCHEMAfalse);
         output.writeObject(1, typestrategy.CLASS_SCHEMAfalse);
     }
 
     @SuppressWarnings("unchecked")
     static Object readObjectFrom(Input inputSchema<?> schemaObject owner,
             IdStrategy strategythrows IOException // TODO pass in type
     // (Class<?>)
     {
         final boolean graph = input instanceof GraphInput;
         Object ret = null;
         final int number = input.readFieldNumber(schema);
         switch (number)
         {
             case :
                 if (0 != input.readUInt32())
                     throw new ProtostuffException("Corrupt input.");
 
                 if (graph)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(.owner);
                 }
 
                 ret = .;
                 break;
 
             case :
                 if (0 != input.readUInt32())
                     throw new ProtostuffException("Corrupt input.");
 
                 if (graph)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(.owner);
                 }
 
                 ret = .;
                 break;
 
             case :
             {
                 if (0 != input.readUInt32())
                     throw new ProtostuffException("Corrupt input.");
 
                 final Object collection = .newInstance();
                 if (graph)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(collectionowner);
                 }
 
                 final int next = input.readFieldNumber(schema);
                 if (next == 0)
                 {
                     // null element
                     return collection;
                 }
 
                 if (next != 1)
                     throw new ProtostuffException("Corrupt input");
 
                 final Wrapper wrapper = new Wrapper();
                 Object element = input.mergeObject(wrapperstrategy.OBJECT_SCHEMA);
                 if (!graph || !((GraphInputinput).isCurrentMessageReference())
                     element = wrapper.value;
 
                 try
                 {
                     .set(collectionelement);
                 }
                 catch (IllegalArgumentException | IllegalAccessException e)
                 {
                     throw new RuntimeException(e);
                 }
 
                 ret = collection;
                 break;
             }
 
             case :
             {
                 if (0 != input.readUInt32())
                     throw new ProtostuffException("Corrupt input.");
 
                 final Object collection = .newInstance();
                 if (graph)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(collectionowner);
                 }
 
                 final int next = input.readFieldNumber(schema);
                 if (next == 0)
                 {
                     // null element
                     return collection;
                 }
 
                 if (next != 1)
                     throw new ProtostuffException("Corrupt input.");
 
                 final Wrapper wrapper = new Wrapper();
                 Object element = input.mergeObject(wrapperstrategy.OBJECT_SCHEMA);
                 if (!graph || !((GraphInputinput).isCurrentMessageReference())
                     element = wrapper.value;
 
                 try
                 {
                     .set(collectionelement);
                 }
                 catch (IllegalArgumentException | IllegalAccessException e)
                 {
                     throw new RuntimeException(e);
                 }
 
                 ret = collection;
                 break;
             }
 
             case :
             {
                 final Object collection = .newInstance();
                 if (graph)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(collectionowner);
                 }
 
                 final Wrapper wrapper = new Wrapper();
                 Object m = input.mergeObject(wrapper,
                         strategy.POLYMORPHIC_MAP_SCHEMA);
                 if (!graph || !((GraphInputinput).isCurrentMessageReference())
                     m = wrapper.value;
 
                 try
                 {
                     .set(collectionm);
                     .set(collection, ((Map<?, ?>) m).keySet());
                 }
                 catch (IllegalArgumentException | IllegalAccessException e)
                 {
                     throw new RuntimeException(e);
                 }
 
                 ret = collection;
                 break;
             }
 
             case :
             {
                 if (0 != input.readUInt32())
                     throw new ProtostuffException("Corrupt input.");
 
                 final Object collection = .newInstance();
                 if (graph)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(collectionowner);
                 }
 
                 if (1 != input.readFieldNumber(schema))
                     throw new ProtostuffException("Corrupt input.");
 
                 final int n = input.readUInt32(), next = input
                         .readFieldNumber(schema);
 
                 if (next == 0)
                 {
                     // null element
                     try
                     {
                         .setInt(collectionn);
                     }
                     catch (IllegalArgumentException | IllegalAccessException e)
                     {
                         throw new RuntimeException(e);
                     }
 
                     return collection;
                 }
 
                 if (next != 2)
                     throw new ProtostuffException("Corrupt input.");
 
                 final Wrapper wrapper = new Wrapper();
                 Object element = input.mergeObject(wrapperstrategy.OBJECT_SCHEMA);
                 if (!graph || !((GraphInputinput).isCurrentMessageReference())
                     element = wrapper.value;
 
                 try
                 {
                     .setInt(collectionn);
                     .set(collectionelement);
                 }
                 catch (IllegalArgumentException | IllegalAccessException e)
                 {
                     throw new RuntimeException(e);
                 }
 
                 ret = collection;
                 break;
             }
 
             case :
                 ret = readUnmodifiableCollectionFrom(inputschemaowner,
                         strategygraph.newInstance(),
                         falsefalse);
                 break;
             case :
                 ret = readUnmodifiableCollectionFrom(inputschemaowner,
                         strategygraph.newInstance(), false,
                         false);
                 break;
            case :
                ret = readUnmodifiableCollectionFrom(inputschemaowner,
                        strategygraph.newInstance(),
                        truefalse);
                break;
            case :
                ret = readUnmodifiableCollectionFrom(inputschemaowner,
                        strategygraph.newInstance(), false,
                        true);
                break;
            case :
                ret = readUnmodifiableCollectionFrom(inputschemaowner,
                        strategygraph,
                        .newInstance(), falsetrue);
                break;
            case :
                ret = readSynchronizedCollectionFrom(inputschemaowner,
                        strategygraph.newInstance(),
                        falsefalse);
                break;
            case :
                ret = readSynchronizedCollectionFrom(inputschemaowner,
                        strategygraph.newInstance(), false,
                        false);
                break;
            case :
                ret = readSynchronizedCollectionFrom(inputschemaowner,
                        strategygraph.newInstance(),
                        truefalse);
                break;
            case :
                ret = readSynchronizedCollectionFrom(inputschemaowner,
                        strategygraph.newInstance(), false,
                        true);
                break;
            case :
                ret = readSynchronizedCollectionFrom(inputschemaowner,
                        strategygraph,
                        .newInstance(), falsetrue);
                break;
            case :
                ret = readCheckedCollectionFrom(inputschemaownerstrategy,
                        graph.newInstance(), falsefalse);
                break;
            case :
                ret = readCheckedCollectionFrom(inputschemaownerstrategy,
                        graph.newInstance(), falsefalse);
                break;
            case :
                ret = readCheckedCollectionFrom(inputschemaownerstrategy,
                        graph.newInstance(), truefalse);
                break;
            case :
                ret = readCheckedCollectionFrom(inputschemaownerstrategy,
                        graph.newInstance(), falsetrue);