T - the type of marshaller, implementing this interfacepublic interface StatefulCopyable<T extends StatefulCopyable<T>>
SizedReader, SizedWriter,
BytesReader, BytesWriter, DataAccess), configured for ChronicleMap or ChronicleSet in builder, should implement the StatefulCopyable
interface. The marshaller instance is populated for each site by copy() method.
For example, see StringBytesReader implementation:
public class StringBytesReader
implements BytesReader<String>, StatefulCopyable<StringBytesReader> {
private final StringBuilder sb = new StringBuilder();
@NotNull
@Override
public String read(Bytes in, @Nullable String using) {
sb.setLength(0);
in.readUtf8(sb);
return sb.toString();
}
@Override
public StringBytesReader copy() {
return new StringBytesReader();
}
}
| Modifier and Type | Method and Description |
|---|---|
T |
copy()
Creates a copy of this marshaller, with independent state.
|
static <T> T |
copyIfNeeded(T possiblyStatefulCopyable)
Checks if
possiblyStatefulCopyable implements StatefulCopyable, then returns
copy() of it, otherwise returns the possiblyStatefulCopyable itself. |
T copy()
copy() 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.
static <T> T copyIfNeeded(T possiblyStatefulCopyable)
possiblyStatefulCopyable implements StatefulCopyable, then returns
copy() of it, otherwise returns the possiblyStatefulCopyable itself.T - the type of the passed instancepossiblyStatefulCopyable - the instance to copy() if it implements StatefulCopyable, or to return without modificationStatefulCopyableCopyright © 2016. All rights reserved.