Package org.apache.beam.sdk.coders
Class SetCoder<T>
- java.lang.Object
-
- org.apache.beam.sdk.coders.Coder<T>
-
- org.apache.beam.sdk.coders.StructuredCoder<IterableT>
-
- org.apache.beam.sdk.coders.IterableLikeCoder<T,java.util.Set<T>>
-
- org.apache.beam.sdk.coders.SetCoder<T>
-
- Type Parameters:
T
- the type of the elements of the set
- All Implemented Interfaces:
java.io.Serializable
public class SetCoder<T> extends IterableLikeCoder<T,java.util.Set<T>>
ASetCoder
encodes anySet
using the format ofIterableLikeCoder
. The elements may not be in a deterministic order, depending on theSet
implementation.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.beam.sdk.coders.Coder
Coder.Context, Coder.NonDeterministicException
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Set<T>
decodeToIterable(java.util.List<T> decodedElements)
Builds an instance ofIterableT
, this coder's associatedIterable
-like subtype, from a list of decoded elements.TypeDescriptor<java.util.Set<T>>
getEncodedTypeDescriptor()
Returns theTypeDescriptor
for the type encoded.static <T> SetCoder<T>
of(Coder<T> elementCoder)
Produces aSetCoder
with the givenelementCoder
.void
verifyDeterministic()
ThrowCoder.NonDeterministicException
if the coding is not deterministic.-
Methods inherited from class org.apache.beam.sdk.coders.IterableLikeCoder
decode, decodeToIterable, encode, getCoderArguments, getElemCoder, isRegisterByteSizeObserverCheap, registerByteSizeObserver
-
Methods inherited from class org.apache.beam.sdk.coders.StructuredCoder
equals, getComponents, hashCode, toString
-
Methods inherited from class org.apache.beam.sdk.coders.Coder
consistentWithEquals, decode, encode, getEncodedElementByteSize, structuralValue, verifyDeterministic, verifyDeterministic
-
-
-
-
Method Detail
-
of
public static <T> SetCoder<T> of(Coder<T> elementCoder)
Produces aSetCoder
with the givenelementCoder
.
-
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.
- Overrides:
verifyDeterministic
in classIterableLikeCoder<T,java.util.Set<T>>
- Throws:
Coder.NonDeterministicException
- always. Sets are not ordered, but they are encoded in the order of an arbitrary iteration.
- two values that compare as equal (via
-
getEncodedTypeDescriptor
public TypeDescriptor<java.util.Set<T>> getEncodedTypeDescriptor()
Description copied from class:Coder
Returns theTypeDescriptor
for the type encoded.- Overrides:
getEncodedTypeDescriptor
in classCoder<java.util.Set<T>>
-
decodeToIterable
protected final java.util.Set<T> decodeToIterable(java.util.List<T> decodedElements)
Builds an instance ofIterableT
, this coder's associatedIterable
-like subtype, from a list of decoded elements.Override
IterableLikeCoder.decodeToIterable(List, long, InputStream)
if you need access to the terminator value and theInputStream
.- Specified by:
decodeToIterable
in classIterableLikeCoder<T,java.util.Set<T>>
- Returns:
- A new
Set
built from the elements in theList
decoded byIterableLikeCoder
.
-
-