T
- type of the accessed objectspublic interface Data<T>
Modifier and Type | Method and Description |
---|---|
RandomDataInput |
bytes()
Returns the accessor object to the
Data 's bytes. |
static boolean |
bytesEquivalent(Data<?> d1,
Data<?> d2)
Utility method, compares two
Data instances represent equivalent bytes sequences:
by comparing their sizes, then calling d1.equivalent(d2.bytes(), d2.offset()) . |
default boolean |
dataEquals(Object obj)
Data implementations should override Object.equals(Object) with delegation to
this method. |
default int |
dataHashCode()
Data implementations should override Object.hashCode() with delegation to
this method. |
default boolean |
equivalent(RandomDataInput source,
long sourceOffset)
Compares bytes of this
Data to the given bytes source , starting from the
given offset. |
T |
get()
Returns "cached" object, generally not eligible for using outside some context, or a block,
synchronized with locks, or lambda, etc.
|
T |
getUsing(T using)
Reads the object from the value's bytes, trying to reuse the given object (might be
null ). |
default long |
hash(LongHashFunction f)
Computes hash code on the bytes representation of this
Data , using the given hash
function. |
long |
offset()
Returns the offset to the
Data 's bytes sequence, within the bytes() object. |
long |
size()
Returns the size of this
Data 's bytes sequence. |
default void |
writeTo(RandomDataOutput target,
long targetOffset)
Writes bytes of this
Data to the given target from the given targetOffset . |
RandomDataInput bytes()
Data
's bytes. For safety, this interface returns
read-only object, because this object could expose bytes source that must be immutable, e. g.
an array behind String
object.long offset()
Data
's bytes sequence, within the bytes()
object.
For example, the first byte of the bytes representation of this Data
instance is
data.bytes().readByte(data.offset())
.long size()
default long hash(LongHashFunction f)
Data
, using the given hash
function.f
- the hash function to compute hash code usingData
's bytes, computed by the given functiondefault boolean equivalent(RandomDataInput source, long sourceOffset)
Data
to the given bytes source
, starting from the
given offset.
Default implementation compares bytes()
of this Data
, but custom
implementation may only check if object of this Data
would
be serialized to the same bytes sequence, if this Data
is object-based and obtaining
bytes()
requires serialization internally.
source
- the bytes source, to compare this Data
's bytes withsourceOffset
- the offset in the bytes source, the bytes sequence starts fromtrue
if the given bytes sequence is equivalent to this Data
's bytes,
byte-by-bytedefault void writeTo(RandomDataOutput target, long targetOffset)
Data
to the given target
from the given targetOffset
.
Default implementation copies bytes()
of this Data
using standard IO
methods of RandomDataInput
and RandomDataOutput
, but custom implementation
may write directly from object, if this Data
is object-based and
obtaining bytes()
requires serialization internally. This allows to avoid double
copy.
target
- the destination to write this data bytes totargetOffset
- the offset in the target, to write the bytes from.T get()
If the Data
is object wrapper -- this method just returns this object.
T getUsing(@Nullable T using)
null
).static boolean bytesEquivalent(Data<?> d1, Data<?> d2)
Data
instances represent equivalent bytes sequences:
by comparing their sizes, then calling d1.equivalent(d2.bytes(), d2.offset())
.d1
- the first Data
to compared2
- the second Data
to compareData
instances represent equivalent bytes sequencesdefault int dataHashCode()
Data
implementations should override Object.hashCode()
with delegation to
this method. Computes value's hash code by applying a hash function to Data
's
bytes representation.default boolean dataEquals(Object obj)
Data
implementations should override Object.equals(Object)
with delegation to
this method. Compares Data
s' bytes representations.Copyright © 2015. All rights reserved.