static void writeNonPublicCollectionTo(Output output, Object value,
            Schema<?> currentSchema, IdStrategy strategy) throws IOException
    {
        final Integer num = __nonPublicCollections.get(value.getClass());
        if (num == null)
            throw new RuntimeException("Unknown collection: "
                    + value.getClass());
        final int id = num.intValue();
        switch (id)
        {
            case ID_EMPTY_SET:
                output.writeUInt32(id, 0, false);
                break;

            case ID_EMPTY_LIST:
                output.writeUInt32(id, 0, false);
                break;

            case ID_SINGLETON_SET:
            {
                output.writeUInt32(id, 0, false);

                final Object element;
                try
                {
                    element = fSingletonSet_element.get(value);
                }
                catch (IllegalAccessException e)
                {
                    throw new RuntimeException(e);
                }
                catch (IllegalArgumentException e)
                {
                    throw new RuntimeException(e);
                }

                if (element != null)
                    output.writeObject(1, element, strategy.OBJECT_SCHEMA, false);

                break;
            }

            case ID_SINGLETON_LIST:
            {
                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, element, strategy.OBJECT_SCHEMA, false);

                break;
            }

            case ID_SET_FROM_MAP:
            {
                final Object m;
                try
                {
                    m = fSetFromMap_m.get(value);
                }
                catch (IllegalAccessException e)
                {
                    throw new RuntimeException(e);
                }
                catch (IllegalArgumentException e)
                {
                    throw new RuntimeException(e);
                }

                output.writeObject(id, m, strategy.POLYMORPHIC_MAP_SCHEMA, false);

                break;
            }

            case ID_COPIES_LIST:
            {
                output.writeUInt32(id, 0, false);

                final int n = ((List<?>) value).size();
                final Object element;
                try
                {
                    element = fCopiesList_element.get(value);
                }
                catch (IllegalAccessException e)
                {
                    throw new RuntimeException(e);
                }
                catch (IllegalArgumentException e)
                {
                    throw new RuntimeException(e);
                }

                output.writeUInt32(1, n, false);

                if (element != null)
                    output.writeObject(2, element, strategy.OBJECT_SCHEMA, false);

                break;
            }
            case ID_UNMODIFIABLE_COLLECTION:
                writeUnmodifiableCollectionTo(output, value, currentSchema,
                        strategy, id);
                break;
            case ID_UNMODIFIABLE_SET:
                writeUnmodifiableCollectionTo(output, value, currentSchema,
                        strategy, id);
                break;
            case ID_UNMODIFIABLE_SORTED_SET:
                writeUnmodifiableCollectionTo(output, value, currentSchema,
                        strategy, id);
                break;
            case ID_UNMODIFIABLE_LIST:
                writeUnmodifiableCollectionTo(output, value, currentSchema,
                        strategy, id);
                break;
            case ID_UNMODIFIABLE_RANDOM_ACCESS_LIST:
                writeUnmodifiableCollectionTo(output, value, currentSchema,
                        strategy, id);
                break;

            case ID_SYNCHRONIZED_COLLECTION:
                writeSynchronizedCollectionTo(output, value, currentSchema,
                        strategy, id);
                break;
            case ID_SYNCHRONIZED_SET:
                writeSynchronizedCollectionTo(output, value, currentSchema,
                        strategy, id);
                break;
            case ID_SYNCHRONIZED_SORTED_SET:
                writeSynchronizedCollectionTo(output, value, currentSchema,
                        strategy, id);
                break;
            case ID_SYNCHRONIZED_LIST:
                writeSynchronizedCollectionTo(output, value, currentSchema,
                        strategy, id);
                break;
            case ID_SYNCHRONIZED_RANDOM_ACCESS_LIST:
                writeSynchronizedCollectionTo(output, value, currentSchema,
                        strategy, id);
                break;

            case ID_CHECKED_COLLECTION:
                writeCheckedCollectionTo(output, value, currentSchema, strategy, id);
                break;
            case ID_CHECKED_SET:
                writeCheckedCollectionTo(output, value, currentSchema, strategy, id);
                break;
            case ID_CHECKED_SORTED_SET:
                writeCheckedCollectionTo(output, value, currentSchema, strategy, id);
                break;
            case ID_CHECKED_LIST:
                writeCheckedCollectionTo(output, value, currentSchema, strategy, id);
                break;
            case ID_CHECKED_RANDOM_ACCESS_LIST:
                writeCheckedCollectionTo(output, value, currentSchema, strategy, id);
                break;

            default:
                throw new RuntimeException("Should not happen.");
        }
    }
Used when the type is an interface (Collection/List/Set/SortedSet).

@author David Yu
@created Apr 24, 2012
protostuff-runtime/src/main/java/io/protostuff/runtime/PolymorphicCollectionSchema.java