Google Cloud Dataflow SDK for Java, version 1.9.1
Class DoubleCoder
- java.lang.Object
-
- com.google.cloud.dataflow.sdk.coders.StandardCoder<T>
-
- com.google.cloud.dataflow.sdk.coders.DeterministicStandardCoder<T>
-
- com.google.cloud.dataflow.sdk.coders.AtomicCoder<Double>
-
- com.google.cloud.dataflow.sdk.coders.DoubleCoder
-
- All Implemented Interfaces:
- Coder<Double>, Serializable
public class DoubleCoder extends AtomicCoder<Double>
ADoubleCoder
encodesDouble
values in 8 bytes using Java serialization.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.google.cloud.dataflow.sdk.coders.Coder
Coder.Context, Coder.NonDeterministicException
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description boolean
consistentWithEquals()
Double
decode(InputStream inStream, Coder.Context context)
Decodes a value of typeT
from the given input stream in the given context.void
encode(Double value, OutputStream outStream, Coder.Context context)
Encodes the given value of typeT
onto the given output stream in the given context.protected long
getEncodedElementByteSize(Double value, Coder.Context context)
Returns the size in bytes of the encoded value using this coder.boolean
isRegisterByteSizeObserverCheap(Double value, Coder.Context context)
Returns whetherCoder.registerByteSizeObserver(T, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver, com.google.cloud.dataflow.sdk.coders.Coder.Context)
cheap enough to call for every element, that is, if thisCoder
can calculate the byte size of the element to be coded in roughly constant time (or lazily).static DoubleCoder
of()
void
verifyDeterministic()
ThrowCoder.NonDeterministicException
if the coding is not deterministic.-
Methods inherited from class com.google.cloud.dataflow.sdk.coders.AtomicCoder
getCoderArguments, getInstanceComponents
-
Methods inherited from class com.google.cloud.dataflow.sdk.coders.StandardCoder
asCloudObject, equals, getAllowedEncodings, getComponents, getEncodingId, hashCode, registerByteSizeObserver, structuralValue, toString, verifyDeterministic, verifyDeterministic
-
-
-
-
Method Detail
-
of
public static DoubleCoder of()
-
encode
public void encode(Double value, OutputStream outStream, Coder.Context context) throws IOException, CoderException
Description copied from interface:Coder
Encodes the given value of typeT
onto the given output stream in the given context.- Throws:
IOException
- if writing to theOutputStream
fails for some reasonCoderException
- if the value could not be encoded for some reason
-
decode
public Double decode(InputStream inStream, Coder.Context context) throws IOException, CoderException
Description copied from interface:Coder
Decodes a value of typeT
from the given input stream in the given context. Returns the decoded value.- Throws:
IOException
- if reading from theInputStream
fails for some reasonCoderException
- if the value could not be decoded for some reason
-
verifyDeterministic
public void verifyDeterministic() throws Coder.NonDeterministicException
ThrowCoder.NonDeterministicException
if the coding is not deterministic.In order for a
Coder
to be considered deterministic, the following must be true:- two values that compare as equal (via
Object.equals()
orComparable.compareTo()
, if supported) have the same encoding. - the
Coder
always produces a canonical encoding, which is the same for an instance of an object even if produced on different computers at different times.
- Specified by:
verifyDeterministic
in interfaceCoder<Double>
- Overrides:
verifyDeterministic
in classDeterministicStandardCoder<Double>
- Throws:
NonDeterministicException
- always. Floating-point operations are not guaranteed to be deterministic, even if the storage format might be, so floating point representations are not recommended for use in operations that require deterministic inputs.Coder.NonDeterministicException
- if this coder is not deterministic.
- two values that compare as equal (via
-
consistentWithEquals
public boolean consistentWithEquals()
Returnstrue
if thisCoder
is injective with respect toObject.equals(java.lang.Object)
.Whenever the encoded bytes of two values are equal, then the original values are equal according to
Objects.equals()
. Note that this is well-defined fornull
.This condition is most notably false for arrays. More generally, this condition is false whenever
equals()
compares object identity, rather than performing a semantic/structural comparison.- Specified by:
consistentWithEquals
in interfaceCoder<Double>
- Overrides:
consistentWithEquals
in classStandardCoder<Double>
- Returns:
true
. This coder is injective.
-
isRegisterByteSizeObserverCheap
public boolean isRegisterByteSizeObserverCheap(Double value, Coder.Context context)
Returns whetherCoder.registerByteSizeObserver(T, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver, com.google.cloud.dataflow.sdk.coders.Coder.Context)
cheap enough to call for every element, that is, if thisCoder
can calculate the byte size of the element to be coded in roughly constant time (or lazily).Not intended to be called by user code, but instead by
PipelineRunner
implementations.- Specified by:
isRegisterByteSizeObserverCheap
in interfaceCoder<Double>
- Overrides:
isRegisterByteSizeObserverCheap
in classStandardCoder<Double>
- Returns:
true
.getEncodedElementByteSize(java.lang.Double, com.google.cloud.dataflow.sdk.coders.Coder.Context)
returns a constant.
-
getEncodedElementByteSize
protected long getEncodedElementByteSize(Double value, Coder.Context context) throws Exception
Returns the size in bytes of the encoded value using this coder.- Overrides:
getEncodedElementByteSize
in classStandardCoder<Double>
- Returns:
8
, the byte size of aDouble
encoded using Java serialization.- Throws:
Exception
-
-