@@ -10,23 +10,32 @@ import com.tryfinch.api.core.ExcludeMissing
1010import com.tryfinch.api.core.JsonField
1111import com.tryfinch.api.core.JsonMissing
1212import com.tryfinch.api.core.JsonValue
13+ import com.tryfinch.api.core.checkRequired
1314import com.tryfinch.api.errors.FinchInvalidDataException
1415import java.util.Collections
1516import java.util.Objects
1617import java.util.Optional
1718
1819class Paging
1920private constructor (
20- private val count: JsonField <Long >,
2121 private val offset: JsonField <Long >,
22+ private val count: JsonField <Long >,
2223 private val additionalProperties: MutableMap <String , JsonValue >,
2324) {
2425
2526 @JsonCreator
2627 private constructor (
27- @JsonProperty(" count" ) @ExcludeMissing count: JsonField <Long > = JsonMissing .of(),
2828 @JsonProperty(" offset" ) @ExcludeMissing offset: JsonField <Long > = JsonMissing .of(),
29- ) : this (count, offset, mutableMapOf ())
29+ @JsonProperty(" count" ) @ExcludeMissing count: JsonField <Long > = JsonMissing .of(),
30+ ) : this (offset, count, mutableMapOf ())
31+
32+ /* *
33+ * The current start index of the returned list of elements
34+ *
35+ * @throws FinchInvalidDataException if the JSON field has an unexpected type or is unexpectedly
36+ * missing or null (e.g. if the server responded with an unexpected value).
37+ */
38+ fun offset (): Long = offset.getRequired(" offset" )
3039
3140 /* *
3241 * The total number of elements for the entire query (not just the given page)
@@ -37,12 +46,11 @@ private constructor(
3746 fun count (): Optional <Long > = count.getOptional(" count" )
3847
3948 /* *
40- * The current start index of the returned list of elements
49+ * Returns the raw JSON value of [offset].
4150 *
42- * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
43- * server responded with an unexpected value).
51+ * Unlike [offset], this method doesn't throw if the JSON field has an unexpected type.
4452 */
45- fun offset (): Optional <Long > = offset.getOptional( " offset " )
53+ @JsonProperty( " offset " ) @ExcludeMissing fun _offset (): JsonField <Long > = offset
4654
4755 /* *
4856 * Returns the raw JSON value of [count].
@@ -51,13 +59,6 @@ private constructor(
5159 */
5260 @JsonProperty(" count" ) @ExcludeMissing fun _count (): JsonField <Long > = count
5361
54- /* *
55- * Returns the raw JSON value of [offset].
56- *
57- * Unlike [offset], this method doesn't throw if the JSON field has an unexpected type.
58- */
59- @JsonProperty(" offset" ) @ExcludeMissing fun _offset (): JsonField <Long > = offset
60-
6162 @JsonAnySetter
6263 private fun putAdditionalProperty (key : String , value : JsonValue ) {
6364 additionalProperties.put(key, value)
@@ -72,45 +73,52 @@ private constructor(
7273
7374 companion object {
7475
75- /* * Returns a mutable builder for constructing an instance of [Paging]. */
76+ /* *
77+ * Returns a mutable builder for constructing an instance of [Paging].
78+ *
79+ * The following fields are required:
80+ * ```java
81+ * .offset()
82+ * ```
83+ */
7684 @JvmStatic fun builder () = Builder ()
7785 }
7886
7987 /* * A builder for [Paging]. */
8088 class Builder internal constructor() {
8189
90+ private var offset: JsonField <Long >? = null
8291 private var count: JsonField <Long > = JsonMissing .of()
83- private var offset: JsonField <Long > = JsonMissing .of()
8492 private var additionalProperties: MutableMap <String , JsonValue > = mutableMapOf ()
8593
8694 @JvmSynthetic
8795 internal fun from (paging : Paging ) = apply {
88- count = paging.count
8996 offset = paging.offset
97+ count = paging.count
9098 additionalProperties = paging.additionalProperties.toMutableMap()
9199 }
92100
93- /* * The total number of elements for the entire query (not just the given page) */
94- fun count ( count : Long ) = count (JsonField .of(count ))
101+ /* * The current start index of the returned list of elements */
102+ fun offset ( offset : Long ) = offset (JsonField .of(offset ))
95103
96104 /* *
97- * Sets [Builder.count ] to an arbitrary JSON value.
105+ * Sets [Builder.offset ] to an arbitrary JSON value.
98106 *
99- * You should usually call [Builder.count ] with a well-typed [Long] value instead. This
107+ * You should usually call [Builder.offset ] with a well-typed [Long] value instead. This
100108 * method is primarily for setting the field to an undocumented or not yet supported value.
101109 */
102- fun count ( count : JsonField <Long >) = apply { this .count = count }
110+ fun offset ( offset : JsonField <Long >) = apply { this .offset = offset }
103111
104- /* * The current start index of the returned list of elements */
105- fun offset ( offset : Long ) = offset (JsonField .of(offset ))
112+ /* * The total number of elements for the entire query (not just the given page) */
113+ fun count ( count : Long ) = count (JsonField .of(count ))
106114
107115 /* *
108- * Sets [Builder.offset ] to an arbitrary JSON value.
116+ * Sets [Builder.count ] to an arbitrary JSON value.
109117 *
110- * You should usually call [Builder.offset ] with a well-typed [Long] value instead. This
118+ * You should usually call [Builder.count ] with a well-typed [Long] value instead. This
111119 * method is primarily for setting the field to an undocumented or not yet supported value.
112120 */
113- fun offset ( offset : JsonField <Long >) = apply { this .offset = offset }
121+ fun count ( count : JsonField <Long >) = apply { this .count = count }
114122
115123 fun additionalProperties (additionalProperties : Map <String , JsonValue >) = apply {
116124 this .additionalProperties.clear()
@@ -135,8 +143,16 @@ private constructor(
135143 * Returns an immutable instance of [Paging].
136144 *
137145 * Further updates to this [Builder] will not mutate the returned instance.
146+ *
147+ * The following fields are required:
148+ * ```java
149+ * .offset()
150+ * ```
151+ *
152+ * @throws IllegalStateException if any required field is unset.
138153 */
139- fun build (): Paging = Paging (count, offset, additionalProperties.toMutableMap())
154+ fun build (): Paging =
155+ Paging (checkRequired(" offset" , offset), count, additionalProperties.toMutableMap())
140156 }
141157
142158 private var validated: Boolean = false
@@ -146,8 +162,8 @@ private constructor(
146162 return @apply
147163 }
148164
149- count()
150165 offset()
166+ count()
151167 validated = true
152168 }
153169
@@ -166,22 +182,22 @@ private constructor(
166182 */
167183 @JvmSynthetic
168184 internal fun validity (): Int =
169- (if (count .asKnown().isPresent) 1 else 0 ) + (if (offset .asKnown().isPresent) 1 else 0 )
185+ (if (offset .asKnown().isPresent) 1 else 0 ) + (if (count .asKnown().isPresent) 1 else 0 )
170186
171187 override fun equals (other : Any? ): Boolean {
172188 if (this == = other) {
173189 return true
174190 }
175191
176- return /* spotless:off */ other is Paging && count == other.count && offset == other.offset && additionalProperties == other.additionalProperties /* spotless:on */
192+ return /* spotless:off */ other is Paging && offset == other.offset && count == other.count && additionalProperties == other.additionalProperties /* spotless:on */
177193 }
178194
179195 /* spotless:off */
180- private val hashCode: Int by lazy { Objects .hash(count, offset , additionalProperties) }
196+ private val hashCode: Int by lazy { Objects .hash(offset, count , additionalProperties) }
181197 /* spotless:on */
182198
183199 override fun hashCode (): Int = hashCode
184200
185201 override fun toString () =
186- " Paging{count= $count , offset= $offset , additionalProperties=$additionalProperties }"
202+ " Paging{offset= $offset , count= $count , additionalProperties=$additionalProperties }"
187203}
0 commit comments