// 
// Decompiled by Procyon v0.6.0
// 

package com.google.protobuf;

import java.util.Collection;
import java.util.List;

final class ListFieldSchemaLite implements ListFieldSchema
{
    @Override
    public <L> List<L> mutableListAt(final Object message, final long offset) {
        Internal.ProtobufList<L> list = getProtobufList(message, offset);
        if (!list.isModifiable()) {
            final int size = list.size();
            list = list.mutableCopyWithCapacity((size == 0) ? 10 : (size * 2));
            UnsafeUtil.putObject(message, offset, list);
        }
        return list;
    }
    
    @Override
    public void makeImmutableListAt(final Object message, final long offset) {
        final Internal.ProtobufList<?> list = getProtobufList(message, offset);
        list.makeImmutable();
    }
    
    @Override
    public <E> void mergeListsAt(final Object msg, final Object otherMsg, final long offset) {
        Internal.ProtobufList<E> mine = getProtobufList(msg, offset);
        final Internal.ProtobufList<E> other = getProtobufList(otherMsg, offset);
        final int size = mine.size();
        final int otherSize = other.size();
        if (size > 0 && otherSize > 0) {
            if (!mine.isModifiable()) {
                mine = mine.mutableCopyWithCapacity(size + otherSize);
            }
            mine.addAll((Collection<?>)other);
        }
        final Internal.ProtobufList<E> merged = (size > 0) ? mine : other;
        UnsafeUtil.putObject(msg, offset, merged);
    }
    
    static <E> Internal.ProtobufList<E> getProtobufList(final Object message, final long offset) {
        return (Internal.ProtobufList)UnsafeUtil.getObject(message, offset);
    }
}
