T - the element type of serialized Setspublic final class SetMarshaller<T> extends Object implements BytesReader<Set<T>>, BytesWriter<Set<T>>, StatefulCopyable<SetMarshaller<T>>
Set<T>. Uses HashSet (hence default element objects' equality and
hashCode()) as the set implementation to deserialize into.
This marshaller supports multimap emulation on top of Chronicle Map, that is possible but inefficient. See the README section.
Usage:
SetMarshaller<String> valueMarshaller = SetMarshaller.of(
new StringBytesReader(), CharSequenceBytesWriter.INSTANCE);
ChronicleMap<String, Set<String>> map = ChronicleMap
.of(String.class, (Class<Set<String>>) (Class) Set.class)
.averageKey("fruits")
.valueMarshaller(valueMarshaller)
.averageValue(ImmutableSet.of("apples", "bananas", "grapes"))
.entries(10_000)
.create();
Look for pre-defined element marshallers in net.openhft.chronicle.hash.serialization.impl package. This package is not included into
Javadocs, but present in Chronicle Map distribution. If there are no existing marshallers for
your Set element type, define BytesReader and BytesWriter yourself.
ListMarshaller,
MapMarshaller| Constructor and Description |
|---|
SetMarshaller(BytesReader<T> elementReader,
BytesWriter<? super T> elementWriter)
Constructs a
SetMarshaller with the given set elements' serializers. |
| Modifier and Type | Method and Description |
|---|---|
SetMarshaller<T> |
copy()
Creates a copy of this marshaller, with independent state.
|
static <T> SetMarshaller<T> |
of(BytesReader<T> elementReader,
BytesWriter<? super T> elementWriter)
Returns a
SetMarshaller which uses the given set elements' serializers. |
static <T,M extends BytesReader<T> & BytesWriter<? super T>> |
of(M elementMarshaller)
Returns a
SetMarshaller which uses the given marshaller as both reader and writer of
set elements. |
Set<T> |
read(net.openhft.chronicle.bytes.Bytes in,
Set<T> using)
Reads and returns the object from
RandomCommon.readPosition() (i. |
void |
readMarshallable(net.openhft.chronicle.wire.WireIn wireIn) |
void |
write(net.openhft.chronicle.bytes.Bytes out,
Set<T> toWrite)
Serializes the given object to the given
out. |
void |
writeMarshallable(net.openhft.chronicle.wire.WireOut wireOut) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait$equals, $fieldInfos, $hashCode, $toString, copyFrom, copyTo, deepCopy, fromFile, fromFile, fromFileAsMap, fromFileAsMap, fromHexString, fromString, fromString, fromString, getClassName, getField, mergeToMap, reset, setField, streamFromFile, streamFromFilecopyIfNeededpublic SetMarshaller(BytesReader<T> elementReader, BytesWriter<? super T> elementWriter)
SetMarshaller with the given set elements' serializers.
Use static factory of(BytesReader, BytesWriter) instead of this constructor
directly.
elementReader - set elements' readerelementWriter - set elements' writerpublic static <T> SetMarshaller<T> of(BytesReader<T> elementReader, BytesWriter<? super T> elementWriter)
SetMarshaller which uses the given set elements' serializers.T - type of set elementselementReader - set elements' readerelementWriter - set elements' writerSetMarshaller which uses the given set elements' serializerspublic static <T,M extends BytesReader<T> & BytesWriter<? super T>> SetMarshaller<T> of(M elementMarshaller)
SetMarshaller which uses the given marshaller as both reader and writer of
set elements. Example:
ChronicleMap
.of(String.class, (Class<Set<Integer>>) ((Class) Set.class))
.valueMarshaller(SetMarshaller.of(IntegerMarshaller.INSTANCE))
...T - type of set elementsM - type of set elements' marshallerelementMarshaller - set elements' marshallerSetMarshaller which uses the given set elements' marshaller@NotNull public Set<T> read(net.openhft.chronicle.bytes.Bytes in, @Nullable Set<T> using)
BytesReaderRandomCommon.readPosition() (i. e. the current position)
in the given in. Should attempt to reuse the given using object, i. e. to
read the deserialized data into the given object. If it is possible, this object then
returned from this method back. If it is impossible for any reason, a new object should be
created and returned. The given using object could be null, in this case this
method, of cause, should create a new object.
This method should increment the position in the given Bytes, i. e. consume the
read bytes. in bytes shouldn't be written.
read in interface BytesReader<Set<T>>in - the Bytes to read the object fromusing - the object to read the deserialized data into, could be nullpublic void write(net.openhft.chronicle.bytes.Bytes out,
@NotNull
Set<T> toWrite)
BytesWriterout.
Implementation of this method should increment the position of the given out by the number of bytes written. The given object should be
written into these range between the initial bytes' position and the position after
this method call returns. Bytes outside of this range shouldn't be written. Any bytes
shouldn't be read from out.
write in interface BytesWriter<Set<T>>out - the Bytes to write the given object totoWrite - the object to serializepublic SetMarshaller<T> copy()
StatefulCopyablecopy() is called, should be inherited in the copy (e. g. the class of objects
serialized). So, copy() should be transitive, i. e. marshaller.copy() and
marshaller.copy().copy() should result to identical instances.
The state of the instance on which copy() is called shouldn't be changed.
If some marshaller is ought to implement StatefulCopyable interface (e. g.
DataAccess) but is stateless actually, it could return this from this method.
copy in interface StatefulCopyable<SetMarshaller<T>>public void readMarshallable(@NotNull
net.openhft.chronicle.wire.WireIn wireIn)
readMarshallable in interface net.openhft.chronicle.wire.MarshallablereadMarshallable in interface net.openhft.chronicle.wire.ReadMarshallablepublic void writeMarshallable(@NotNull
net.openhft.chronicle.wire.WireOut wireOut)
writeMarshallable in interface net.openhft.chronicle.wire.MarshallablewriteMarshallable in interface net.openhft.chronicle.wire.WriteMarshallableCopyright © 2019. All rights reserved.