Converts this map to the given map type. @param mt map type @param qc query context @param ii input info (can be null) @param cc compilation context (null during runtime) @return coerced map @throws QueryException query exception
(final MapType mt, final QueryContext qc, final InputInfo ii,
final CompileContext cc)
| 330 | * @throws QueryException query exception |
| 331 | */ |
| 332 | public final XQMap coerceTo(final MapType mt, final QueryContext qc, final InputInfo ii, |
| 333 | final CompileContext cc) throws QueryException { |
| 334 | |
| 335 | final SeqType kt = mt.keyType().seqType(), vt = mt.valueType(); |
| 336 | final MapBuilder mb = new MapBuilder(structSize()); |
| 337 | forEach((key, value) -> { |
| 338 | qc.checkStop(); |
| 339 | final Item k = (Item) kt.coerce(key, qc, ii, null, cc); |
| 340 | if(mb.contains(k)) throw typeError(this, mt, ii); |
| 341 | mb.put(k, vt.coerce(value, qc, ii, null, cc)); |
| 342 | }); |
| 343 | return mb.map(); |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * Converts this map to the given record type. |