Package com.anthropic.models.messages
Class DocumentBlock.Source
-
- All Implemented Interfaces:
public final class DocumentBlock.Source
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceDocumentBlock.Source.VisitorAn interface that defines how to map each variant of Source to a value of type T.
public final classDocumentBlock.Source.Type
-
Method Summary
Modifier and Type Method Description final Optional<Base64PdfSource>base64()final Optional<PlainTextSource>text()final Optional<JsonValue>_json()final DocumentBlock.Source.Typetype()final Stringdata()final BooleanisBase64()final BooleanisText()final Base64PdfSourceasBase64()final PlainTextSourceasText()final <T extends Any> Taccept(DocumentBlock.Source.Visitor<T> visitor)Maps this instance's current variant to a value of type T using the given visitor. final DocumentBlock.Sourcevalidate()Validates that the types of all values in this object match their expected types recursively. final BooleanisValid()Booleanequals(Object other)IntegerhashCode()StringtoString()final static DocumentBlock.SourceofBase64(Base64PdfSource base64)final static DocumentBlock.SourceofBase64(String data)Returns an immutable instance of Source whose ofBase64 variant is built from the given required data. final static DocumentBlock.SourceofText(PlainTextSource text)final static DocumentBlock.SourceofText(String data)Returns an immutable instance of Source whose ofText variant is built from the given required data. -
-
Method Detail
-
base64
final Optional<Base64PdfSource> base64()
-
text
final Optional<PlainTextSource> text()
-
type
final DocumentBlock.Source.Type type()
-
asBase64
final Base64PdfSource asBase64()
-
asText
final PlainTextSource asText()
-
accept
final <T extends Any> T accept(DocumentBlock.Source.Visitor<T> visitor)
Maps this instance's current variant to a value of type T using the given visitor.
Note that this method is not forwards compatible with new variants from the API, unless visitor overrides Visitor.unknown. To handle variants not known to this version of the SDK gracefully, consider overriding Visitor.unknown:
import com.anthropic.core.JsonValue; import java.util.Optional; Optional<String> result = source.accept(new Source.Visitor<Optional<String>>() { @Override public Optional<String> visitBase64(Base64PdfSource base64) { return Optional.of(base64.toString()); } // ... @Override public Optional<String> unknown(JsonValue json) { // Or inspect the `json`. return Optional.empty(); } });
-
validate
final DocumentBlock.Source validate()
Validates that the types of all values in this object match their expected types recursively.
This method is not forwards compatible with new types from the API for existing fields.
-
ofBase64
final static DocumentBlock.Source ofBase64(Base64PdfSource base64)
-
ofBase64
final static DocumentBlock.Source ofBase64(String data)
Returns an immutable instance of Source whose ofBase64 variant is built from the given required data.
-
ofText
final static DocumentBlock.Source ofText(PlainTextSource text)
-
ofText
final static DocumentBlock.Source ofText(String data)
-
-
-
-