44import java .util .Map ;
55import java .util .Optional ;
66
7+ import org .jspecify .annotations .Nullable ;
8+
79import com .fasterxml .jackson .annotation .JsonInclude ;
810import com .fasterxml .jackson .annotation .JsonProperty ;
911import tools .jackson .databind .annotation .JsonDeserialize ;
1214@ JsonInclude (JsonInclude .Include .NON_ABSENT )
1315@ JsonDeserialize (builder = DocumentResponse .Builder .class )
1416public interface DocumentResponse {
17+ /**
18+ * Retrieves the content of the doc tags, if available.
19+ *
20+ * @return the content of the doc tags, or null if not present
21+ */
22+ @ Nullable
1523 String doctagsContent ();
24+
25+ /**
26+ * Retrieves the filename associated with the document.
27+ *
28+ * @return the filename of the document as a string
29+ */
1630 String filename ();
31+
32+ /**
33+ * Retrieves the HTML content associated with the document, if available.
34+ *
35+ * @return the HTML content as a string, or null if not present
36+ */
37+ @ Nullable
1738 String htmlContent ();
39+
40+ /**
41+ * Retrieves the JSON content associated with the document.
42+ *
43+ * @return a map representing the JSON content, or an empty map if no JSON content is present
44+ */
1845 Map <String , Object > jsonContent ();
46+
47+ /**
48+ * Retrieves the Markdown content associated with the document, if available.
49+ *
50+ * @return the Markdown content as a string, or null if no Markdown content is present
51+ */
52+ @ Nullable
1953 String markdownContent ();
54+
55+ /**
56+ * Retrieves the plain text content associated with the document, if available.
57+ *
58+ * @return the plain text content as a string, or null if no text content is present
59+ */
60+ @ Nullable
2061 String textContent ();
2162
63+ /**
64+ * Creates a new {@code Builder} instance initialized with the current state of the {@code DocumentResponse}.
65+ *
66+ * @return a {@code Builder} instance populated with the values from this {@code DocumentResponse}
67+ */
2268 default Builder toBuilder () {
2369 return new Builder (this );
2470 }
2571
72+ /**
73+ * Creates and returns a new instance of the {@code Builder} class, which can be used to
74+ * construct a {@code DocumentResponse} object in a step-by-step manner.
75+ *
76+ * @return a new {@code Builder} instance
77+ */
2678 static Builder builder () {
2779 return new Builder ();
2880 }
2981
82+ /**
83+ * Default implementation of the {@link DocumentResponse} interface.
84+ * This record represents the response containing document data in various formats.
85+ * It is an immutable data structure that consolidates information related to a document,
86+ * such as its filename, content in multiple formats, and metadata.
87+ *
88+ * Each instance ensures the provided JSON content is unmodifiable by copying
89+ * the input map if it is present, or initializing it to an empty map otherwise.
90+ */
3091 record DefaultDocumentResponse (String doctagsContent ,
3192 String filename ,
3293 String htmlContent ,
@@ -50,6 +111,26 @@ public DefaultDocumentResponse(Builder builder) {
50111 }
51112 }
52113
114+ /**
115+ * A builder class for constructing instances of {@code DocumentResponse}.
116+ *
117+ * This class provides a step-by-step approach to configure and create a
118+ * {@code DocumentResponse} object. Each method in this class sets a specific
119+ * property of the object being built. Once all the desired properties are set,
120+ * the {@code build} method is used to create the final {@code DocumentResponse}
121+ * instance.
122+ *
123+ * The builder supports customization of various document-related attributes,
124+ * including doc tags content, filename, HTML content, JSON content, Markdown
125+ * content, and plain text content.
126+ *
127+ * By default, the builder initializes attributes with an empty state or default
128+ * values. If a {@code DocumentResponse} instance is provided to the constructor,
129+ * the builder is pre-populated with the attributes from the given response.
130+ *
131+ * This class is intended for internal use and is protected to restrict its
132+ * accessibility outside the defining package or class hierarchy.
133+ */
53134 @ JsonPOJOBuilder (withPrefix = "" )
54135 class Builder {
55136 protected String doctagsContent ;
@@ -59,10 +140,30 @@ class Builder {
59140 protected String markdownContent ;
60141 protected String textContent ;
61142
143+ /**
144+ * Constructs a new {@code Builder} instance.
145+ *
146+ * This constructor initializes a builder with default or empty states for all
147+ * attributes. It is protected to restrict direct instantiation outside of the
148+ * defining package or class hierarchy.
149+ *
150+ * The {@code Builder} class is primarily used to facilitate the creation of
151+ * {@code DocumentResponse} objects through a step-by-step configuration process.
152+ */
62153 protected Builder () {
63154
64155 }
65156
157+ /**
158+ * Constructs a new {@code Builder} instance using the provided {@code DocumentResponse}.
159+ *
160+ * This constructor initializes the builder's fields with the data from the given
161+ * {@code DocumentResponse} object. It allows for the creation of a {@code Builder}
162+ * instance pre-populated with the state of an existing {@code DocumentResponse}.
163+ *
164+ * @param documentResponse the {@code DocumentResponse} instance whose data will
165+ * populate the fields of this builder
166+ */
66167 protected Builder (DocumentResponse documentResponse ) {
67168 this .doctagsContent = documentResponse .doctagsContent ();
68169 this .filename = documentResponse .filename ();
@@ -72,42 +173,95 @@ protected Builder(DocumentResponse documentResponse) {
72173 this .textContent = documentResponse .textContent ();
73174 }
74175
176+ /**
177+ * Sets the doctags content for the builder instance.
178+ *
179+ * @param doctagsContent the doctags content to be set
180+ * @return this Builder instance for method chaining
181+ */
75182 @ JsonProperty ("doctags_content" )
76183 public Builder doctagsContent (String doctagsContent ) {
77184 this .doctagsContent = doctagsContent ;
78185 return this ;
79186 }
80187
188+ /**
189+ * Sets the filename for the builder instance.
190+ *
191+ * @param filename the filename to be set
192+ * @return this Builder instance for method chaining
193+ */
81194 @ JsonProperty ("filename" )
82195 public Builder filename (String filename ) {
83196 this .filename = filename ;
84197 return this ;
85198 }
86199
200+ /**
201+ * Sets the HTML content for the builder instance.
202+ *
203+ * @param htmlContent the HTML content to be set
204+ * @return this Builder instance for method chaining
205+ */
87206 @ JsonProperty ("html_content" )
88207 public Builder htmlContent (String htmlContent ) {
89208 this .htmlContent = htmlContent ;
90209 return this ;
91210 }
92211
212+ /**
213+ * Sets the JSON content for the builder instance.
214+ *
215+ * The JSON content is represented as a map of key-value pairs, where the keys
216+ * are {@code String} objects, and the values are {@code Object} instances.
217+ *
218+ * @param jsonContent the JSON content to be set, represented as a {@code Map<String, Object>}
219+ * @return this {@link Builder} instance for method chaining
220+ */
93221 @ JsonProperty ("json_content" )
94222 public Builder jsonContent (Map <String , Object > jsonContent ) {
95223 this .jsonContent = jsonContent ;
96224 return this ;
97225 }
98226
227+ /**
228+ * Sets the Markdown content for this builder instance.
229+ *
230+ * The Markdown content represents the textual data formatted in Markdown syntax,
231+ * which can include headings, lists, links, and other Markdown elements.
232+ *
233+ * @param markdownContent the Markdown content to be set, represented as a {@code String}
234+ * @return this {@link Builder} instance for method chaining
235+ */
99236 @ JsonProperty ("md_content" )
100237 public Builder markdownContent (String markdownContent ) {
101238 this .markdownContent = markdownContent ;
102239 return this ;
103240 }
104241
242+ /**
243+ * Sets the plain text content for this builder instance.
244+ *
245+ * The plain text content represents unformatted textual data that can be
246+ * used for display or processing purposes within the application.
247+ *
248+ * @param textContent the plain text content to be set, represented as a {@code String}
249+ * @return this {@link Builder} instance for method chaining
250+ */
105251 @ JsonProperty ("text_content" )
106252 public Builder textContent (String textContent ) {
107253 this .textContent = textContent ;
108254 return this ;
109255 }
110256
257+ /**
258+ * Creates and returns a {@link DocumentResponse} instance based on the current state of this {@link Builder}.
259+ *
260+ * <p>The returned {@link DocumentResponse} will encapsulate the values configured in the builder,
261+ * and further modifications to the builder instance will not affect the created {@code DocumentResponse}.
262+ *
263+ * @return a new {@code DocumentResponse} instance constructed from the builder's state
264+ */
111265 public DocumentResponse build () {
112266 return new DefaultDocumentResponse (this );
113267 }
0 commit comments