Build returns a JSON object built from a key value pair sequence. After that, it should not be modified any longer.
()
| 384 | // Build returns a JSON object built from a key value pair sequence. After that, |
| 385 | // it should not be modified any longer. |
| 386 | func (b *ObjectBuilder) Build() JSON { |
| 387 | if b.built { |
| 388 | panic(errors.AssertionFailedf(msgModifyAfterBuild)) |
| 389 | } |
| 390 | b.built = true |
| 391 | if b.unordered { |
| 392 | return jsonObject(b.pairs) |
| 393 | } |
| 394 | |
| 395 | orders := make([]int, len(b.pairs)) |
| 396 | for i := range orders { |
| 397 | orders[i] = i |
| 398 | } |
| 399 | sorter := pairSorter{ |
| 400 | pairs: b.pairs, |
| 401 | orders: orders, |
| 402 | hasNonUnique: false, |
| 403 | } |
| 404 | b.pairs = nil |
| 405 | sort.Sort(&sorter) |
| 406 | sorter.unique() |
| 407 | return jsonObject(sorter.pairs) |
| 408 | } |
| 409 | |
| 410 | // FixedKeysObjectBuilder is a JSON object builder that builds |
| 411 | // an object for the specified fixed set of unique keys. |
no test coverage detected