Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 //========================================================================
 //Copyright 2007-2011 David Yu dyuproject@gmail.com
 //------------------------------------------------------------------------
 //Licensed under the Apache License, Version 2.0 (the "License");
 //you may not use this file except in compliance with the License.
 //You may obtain a copy of the License at 
 //http://www.apache.org/licenses/LICENSE-2.0
 //Unless required by applicable law or agreed to in writing, software
 //distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//========================================================================
package io.protostuff.runtime;
A runtime field for a java.util.Collection. Null values are not written.

Author(s):
David Yu
Created:
Jan 26, 2011
abstract class RuntimeCollectionField<T, V> extends Field<T>
{

    
Since we cannot inherit multiple classes, we create this Collection schema simply to delegate to the wrapping class' abstract methods.
    protected final CollectionSchema<V> schema;
    public RuntimeCollectionField(FieldType typeint numberString name,
            Tag tagMessageFactory messageFactory)
    {
        super(typenumbernamefalsetag);
         = new CollectionSchema<V>(messageFactory)
        {
            @Override
            protected void addValueFrom(Input inputCollection<V> collection)
                    throws IOException
            {
                RuntimeCollectionField.this.addValueFrom(inputcollection);
            }
            @Override
            protected void writeValueTo(Output outputint fieldNumber,
                    V valueboolean repeatedthrows IOException
            {
                RuntimeCollectionField.this.writeValueTo(outputfieldNumber,
                        valuerepeated);
            }
            @Override
            protected void transferValue(Pipe pipeInput inputOutput output,
                    int numberboolean repeatedthrows IOException
            {
                RuntimeCollectionField.this.transferValue(pipeinputoutput,
                        numberrepeated);
            }
        };
    }
    protected abstract void addValueFrom(Input inputCollection<V> collection)
            throws IOException;
    protected abstract void writeValueTo(Output outputint fieldNumber,
            V valueboolean repeatedthrows IOException;
    protected abstract void transferValue(Pipe pipeInput input,
            Output outputint numberboolean repeatedthrows IOException;
New to GrepCode? Check out our FAQ X