Build returns a JSON object built from a key value pair sequence. After that, it should not be modified any longer.
()
| 268 | // Build returns a JSON object built from a key value pair sequence. After that, |
| 269 | // it should not be modified any longer. |
| 270 | func (b *ObjectBuilder) Build() JSON { |
| 271 | if b.pairs == nil { |
| 272 | panic(errors.AssertionFailedf(msgModifyAfterBuild)) |
| 273 | } |
| 274 | orders := make([]int, len(b.pairs)) |
| 275 | for i := range orders { |
| 276 | orders[i] = i |
| 277 | } |
| 278 | sorter := pairSorter{ |
| 279 | pairs: b.pairs, |
| 280 | orders: orders, |
| 281 | hasNonUnique: false, |
| 282 | } |
| 283 | b.pairs = nil |
| 284 | sort.Sort(&sorter) |
| 285 | sorter.unique() |
| 286 | return jsonObject(sorter.pairs) |
| 287 | } |
| 288 | |
| 289 | // pairSorter sorts and uniqueifies JSON pairs. In order to keep |
| 290 | // the last one for pairs with the same key while sort.Sort is |
no test coverage detected