com.dyuproject.protostuff
Class MapSchema<K,V>

java.lang.Object
  extended by com.dyuproject.protostuff.MapSchema<K,V>
All Implemented Interfaces:
Schema<java.util.Map<K,V>>
Direct Known Subclasses:
MessageMapSchema, StringMapSchema

public abstract class MapSchema<K,V>
extends java.lang.Object
implements Schema<java.util.Map<K,V>>

A schema for a Map. The key and value can be null (depending on the particular map impl). The default Map message created will be an instance of HashMap.

Author:
David Yu
Date created:
Jun 26, 2010

Nested Class Summary
static class MapSchema.MapWrapper<K,V>
          A Map.Entry w/c wraps a Map.
static class MapSchema.MessageFactories
          A message factory for standard Map implementations.
static interface MapSchema.MessageFactory
          Creates new Map messages.
 
Field Summary
static java.lang.String FIELD_NAME_ENTRY
          The field name of the Map.Entry.
static java.lang.String FIELD_NAME_KEY
          The field name of the key.
static java.lang.String FIELD_NAME_VALUE
          The field name of the value;
 MapSchema.MessageFactory messageFactory
          Factory for creating Map messages.
 Pipe.Schema<java.util.Map<K,V>> pipeSchema
          The pipe schema of the Map.
 
Constructor Summary
MapSchema()
           
MapSchema(MapSchema.MessageFactory messageFactory)
           
 
Method Summary
 java.lang.String getFieldName(int number)
           
 int getFieldNumber(java.lang.String name)
           
 boolean isInitialized(java.util.Map<K,V> map)
           
 void mergeFrom(Input input, java.util.Map<K,V> map)
           
 java.lang.String messageFullName()
           
 java.lang.String messageName()
           
 java.util.Map<K,V> newMessage()
           
protected abstract  void putValueFrom(Input input, MapSchema.MapWrapper<K,V> wrapper, K key)
          Puts the entry(key and value), obtained from the input, into the MapWrapper.
protected abstract  K readKeyFrom(Input input, MapSchema.MapWrapper<K,V> wrapper)
          Reads the key from the input.
protected abstract  void transferKey(Pipe pipe, Input input, Output output, int number, boolean repeated)
          Transfers the key from the input to the output.
protected abstract  void transferValue(Pipe pipe, Input input, Output output, int number, boolean repeated)
          Transfers the value from the input to the output.
 java.lang.Class<? super java.util.Map<K,V>> typeClass()
           
protected abstract  void writeKeyTo(Output output, int fieldNumber, K value, boolean repeated)
          Writes the key to the output.
 void writeTo(Output output, java.util.Map<K,V> map)
           
protected abstract  void writeValueTo(Output output, int fieldNumber, V value, boolean repeated)
          Writes the value to the output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIELD_NAME_ENTRY

public static final java.lang.String FIELD_NAME_ENTRY
The field name of the Map.Entry.

See Also:
Constant Field Values

FIELD_NAME_KEY

public static final java.lang.String FIELD_NAME_KEY
The field name of the key.

See Also:
Constant Field Values

FIELD_NAME_VALUE

public static final java.lang.String FIELD_NAME_VALUE
The field name of the value;

See Also:
Constant Field Values

messageFactory

public final MapSchema.MessageFactory messageFactory
Factory for creating Map messages.


pipeSchema

public final Pipe.Schema<java.util.Map<K,V>> pipeSchema
The pipe schema of the Map.

Constructor Detail

MapSchema

public MapSchema()

MapSchema

public MapSchema(MapSchema.MessageFactory messageFactory)
Method Detail

readKeyFrom

protected abstract K readKeyFrom(Input input,
                                 MapSchema.MapWrapper<K,V> wrapper)
                          throws java.io.IOException
Reads the key from the input. The extra wrapper arg is internally used as an object placeholder during polymorhic deserialization.

Throws:
java.io.IOException

putValueFrom

protected abstract void putValueFrom(Input input,
                                     MapSchema.MapWrapper<K,V> wrapper,
                                     K key)
                              throws java.io.IOException
Puts the entry(key and value), obtained from the input, into the MapWrapper.

Throws:
java.io.IOException

writeKeyTo

protected abstract void writeKeyTo(Output output,
                                   int fieldNumber,
                                   K value,
                                   boolean repeated)
                            throws java.io.IOException
Writes the key to the output.

Throws:
java.io.IOException

writeValueTo

protected abstract void writeValueTo(Output output,
                                     int fieldNumber,
                                     V value,
                                     boolean repeated)
                              throws java.io.IOException
Writes the value to the output.

Throws:
java.io.IOException

transferKey

protected abstract void transferKey(Pipe pipe,
                                    Input input,
                                    Output output,
                                    int number,
                                    boolean repeated)
                             throws java.io.IOException
Transfers the key from the input to the output.

Throws:
java.io.IOException

transferValue

protected abstract void transferValue(Pipe pipe,
                                      Input input,
                                      Output output,
                                      int number,
                                      boolean repeated)
                               throws java.io.IOException
Transfers the value from the input to the output.

Throws:
java.io.IOException

getFieldName

public final java.lang.String getFieldName(int number)
Specified by:
getFieldName in interface Schema<java.util.Map<K,V>>

getFieldNumber

public final int getFieldNumber(java.lang.String name)
Specified by:
getFieldNumber in interface Schema<java.util.Map<K,V>>

isInitialized

public final boolean isInitialized(java.util.Map<K,V> map)
Specified by:
isInitialized in interface Schema<java.util.Map<K,V>>

messageFullName

public final java.lang.String messageFullName()
Specified by:
messageFullName in interface Schema<java.util.Map<K,V>>

messageName

public final java.lang.String messageName()
Specified by:
messageName in interface Schema<java.util.Map<K,V>>

typeClass

public final java.lang.Class<? super java.util.Map<K,V>> typeClass()
Specified by:
typeClass in interface Schema<java.util.Map<K,V>>

newMessage

public final java.util.Map<K,V> newMessage()
Specified by:
newMessage in interface Schema<java.util.Map<K,V>>

mergeFrom

public final void mergeFrom(Input input,
                            java.util.Map<K,V> map)
                     throws java.io.IOException
Specified by:
mergeFrom in interface Schema<java.util.Map<K,V>>
Throws:
java.io.IOException

writeTo

public final void writeTo(Output output,
                          java.util.Map<K,V> map)
                   throws java.io.IOException
Specified by:
writeTo in interface Schema<java.util.Map<K,V>>
Throws:
java.io.IOException


Copyright © 2009-2014. All Rights Reserved.