Package io.protostuff
Class CollectionSchema<V>
- java.lang.Object
-
- io.protostuff.CollectionSchema<V>
-
- All Implemented Interfaces:
Schema<java.util.Collection<V>>
- Direct Known Subclasses:
MessageCollectionSchema
public abstract class CollectionSchema<V> extends java.lang.Object implements Schema<java.util.Collection<V>>
A schema for standard jdkcollections
. Null values are not serialized/written.If
preserveNull
is false and your application relies onObject.equals(Object)
, it will fail when a serialized collection contains null values.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CollectionSchema.MessageFactories
static interface
CollectionSchema.MessageFactory
Creates newCollection
messages.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
FIELD_NAME_NULL
static java.lang.String
FIELD_NAME_VALUE
(package private) static java.util.Set<java.lang.String>
MESSAGE_FACTORIES_NAMES
This is used byCollectionSchema.MessageFactories.accept(String)
method.CollectionSchema.MessageFactory
messageFactory
Factory for creatingCollection
messages.Pipe.Schema<java.util.Collection<V>>
pipeSchema
boolean
preserveNull
-
Constructor Summary
Constructors Constructor Description CollectionSchema(boolean preserveNull)
CollectionSchema(CollectionSchema.MessageFactory messageFactory, boolean preserveNull)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
addValueFrom(Input input, java.util.Collection<V> collection)
Adds the value from the input into theCollection
.static java.lang.String
fieldName(int number)
static int
fieldNumber(java.lang.String name)
java.lang.String
getFieldName(int number)
Gets the field name associated with the number.int
getFieldNumber(java.lang.String name)
Gets the field number associated with the name.boolean
isInitialized(java.util.Collection<V> map)
Returns true if there is no required field or if all the required fields are set.void
mergeFrom(Input input, java.util.Collection<V> message)
Deserializes a message/object from theinput
.java.lang.String
messageFullName()
Returns the full name of the message tied to this schema.java.lang.String
messageName()
Returns the simple name of the message tied to this schema.java.util.Collection<V>
newMessage()
Creates the message/object tied to this schema.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.Collection<V>>
typeClass()
Gets the class of the message.void
writeTo(Output output, java.util.Collection<V> message)
Serializes a message/object to theoutput
.protected abstract void
writeValueTo(Output output, int fieldNumber, V value, boolean repeated)
Writes the value to the output.private void
writeWithNullTo(Output output, java.util.Collection<V> message)
private void
writeWithoutNullTo(Output output, java.util.Collection<V> message)
-
-
-
Field Detail
-
FIELD_NAME_VALUE
public static final java.lang.String FIELD_NAME_VALUE
- See Also:
- Constant Field Values
-
FIELD_NAME_NULL
public static final java.lang.String FIELD_NAME_NULL
- See Also:
- Constant Field Values
-
MESSAGE_FACTORIES_NAMES
static final java.util.Set<java.lang.String> MESSAGE_FACTORIES_NAMES
This is used byCollectionSchema.MessageFactories.accept(String)
method. Rather than iterating enums in runtime which can be an expensive way to do, caching all the enums as static property will be a good way.
-
messageFactory
public final CollectionSchema.MessageFactory messageFactory
Factory for creatingCollection
messages.
-
preserveNull
public final boolean preserveNull
-
pipeSchema
public final Pipe.Schema<java.util.Collection<V>> pipeSchema
-
-
Constructor Detail
-
CollectionSchema
public CollectionSchema(boolean preserveNull)
-
CollectionSchema
public CollectionSchema(CollectionSchema.MessageFactory messageFactory, boolean preserveNull)
-
-
Method Detail
-
fieldName
public static final java.lang.String fieldName(int number)
-
fieldNumber
public static final int fieldNumber(java.lang.String name)
-
addValueFrom
protected abstract void addValueFrom(Input input, java.util.Collection<V> collection) throws java.io.IOException
Adds the value from the input into theCollection
.- 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
-
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)
Description copied from interface:Schema
Gets the field name associated with the number. This is particularly useful when serializing to different formats (Eg. JSON). When using numeric field names:return String.valueOf(number);
- Specified by:
getFieldName
in interfaceSchema<V>
-
getFieldNumber
public final int getFieldNumber(java.lang.String name)
Description copied from interface:Schema
Gets the field number associated with the name. This is particularly useful when serializing to different formats (Eg. JSON). When using numeric field names:return Integer.parseInt(name);
- Specified by:
getFieldNumber
in interfaceSchema<V>
-
isInitialized
public final boolean isInitialized(java.util.Collection<V> map)
Description copied from interface:Schema
Returns true if there is no required field or if all the required fields are set.- Specified by:
isInitialized
in interfaceSchema<V>
-
messageFullName
public final java.lang.String messageFullName()
Description copied from interface:Schema
Returns the full name of the message tied to this schema. Allows custom schemas to provide a custom name other than typeClass().getName();- Specified by:
messageFullName
in interfaceSchema<V>
-
messageName
public final java.lang.String messageName()
Description copied from interface:Schema
Returns the simple name of the message tied to this schema. Allows custom schemas to provide a custom name other than typeClass().getSimpleName();- Specified by:
messageName
in interfaceSchema<V>
-
typeClass
public final java.lang.Class<? super java.util.Collection<V>> typeClass()
Description copied from interface:Schema
Gets the class of the message.
-
newMessage
public final java.util.Collection<V> newMessage()
Description copied from interface:Schema
Creates the message/object tied to this schema.- Specified by:
newMessage
in interfaceSchema<V>
-
mergeFrom
public void mergeFrom(Input input, java.util.Collection<V> message) throws java.io.IOException
Description copied from interface:Schema
Deserializes a message/object from theinput
.
-
writeWithNullTo
private void writeWithNullTo(Output output, java.util.Collection<V> message) throws java.io.IOException
- Throws:
java.io.IOException
-
writeWithoutNullTo
private void writeWithoutNullTo(Output output, java.util.Collection<V> message) throws java.io.IOException
- Throws:
java.io.IOException
-
-