MtasSolrResultMerge.java.html 26.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasSolrResultMerge.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> &gt; <a href="index.source.html" class="el_package">mtas.solr.handler.component.util</a> &gt; <span class="el_source">MtasSolrResultMerge.java</span></div><h1>MtasSolrResultMerge.java</h1><pre class="source lang-java linenums">package mtas.solr.handler.component.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.SortedSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.ShardRequest;
import org.apache.solr.handler.component.ShardResponse;

import mtas.codec.util.CodecComponent.ComponentFields;
import mtas.solr.handler.component.MtasSolrSearchComponent;

/**
 * The Class MtasSolrResultMerge.
 */
<span class="fc" id="L24">public class MtasSolrResultMerge {</span>

  /** The Constant log. */
<span class="fc" id="L27">  private static final Log log = LogFactory.getLog(MtasSolrResultMerge.class);</span>

  /**
   * Merge.
   *
   * @param rb the rb
   */
  @SuppressWarnings(&quot;unchecked&quot;)
  public void merge(ResponseBuilder rb) { 
<span class="pc bpc" id="L36" title="1 of 2 branches missed.">    if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {</span>
      // mtas response
<span class="fc" id="L38">      NamedList&lt;Object&gt; mtasResponse = null;</span>
      try {
<span class="fc" id="L40">        mtasResponse = (NamedList&lt;Object&gt;) rb.rsp.getValues().get(&quot;mtas&quot;);</span>
<span class="nc" id="L41">      } catch (ClassCastException e) {</span>
<span class="nc" id="L42">        log.debug(e);</span>
<span class="nc" id="L43">        mtasResponse = null;</span>
<span class="fc" id="L44">      }</span>
<span class="fc bfc" id="L45" title="All 2 branches covered.">      if (mtasResponse == null) {</span>
<span class="fc" id="L46">        mtasResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="fc" id="L47">        rb.rsp.add(&quot;mtas&quot;, mtasResponse);</span>
      }

<span class="fc bfc" id="L50" title="All 2 branches covered.">      for (ShardRequest sreq : rb.finished) {</span>
<span class="fc bfc" id="L51" title="All 2 branches covered.">        if (rb.stage == ResponseBuilder.STAGE_EXECUTE_QUERY) {</span>
          // merge stats
<span class="fc" id="L53">          if (rb.req.getParams()</span>
<span class="fc bfc" id="L54" title="All 2 branches covered.">              .getBool(MtasSolrComponentStats.PARAM_MTAS_STATS, false)) {</span>
<span class="fc" id="L55">            mergeNamedList(sreq, mtasResponse, &quot;stats&quot;, null);</span>
          }
          // merge group
<span class="fc" id="L58">          if (rb.req.getParams()</span>
<span class="pc bpc" id="L59" title="1 of 2 branches missed.">              .getBool(MtasSolrComponentGroup.PARAM_MTAS_GROUP, false)) {</span>
<span class="nc" id="L60">            mergeArrayList(sreq, mtasResponse, &quot;group&quot;, null, false);</span>
          }
          // merge facet
<span class="fc" id="L63">          if (rb.req.getParams()</span>
<span class="pc bpc" id="L64" title="1 of 2 branches missed.">              .getBool(MtasSolrComponentFacet.PARAM_MTAS_FACET, false)) {</span>
<span class="nc" id="L65">            mergeArrayList(sreq, mtasResponse, &quot;facet&quot;, null, false);</span>
          }
          // merge join
<span class="pc bpc" id="L68" title="1 of 2 branches missed.">          if (rb.req.getParams().getBool(MtasSolrComponentJoin.PARAM_MTAS_JOIN,</span>
              false)) {
<span class="nc" id="L70">            ComponentFields componentFields = (ComponentFields) rb.req</span>
<span class="nc" id="L71">                .getContext().get(ComponentFields.class);</span>
<span class="nc" id="L72">            mtasResponse.add(&quot;join&quot;,</span>
                new MtasSolrJoinResult(componentFields.join));
<span class="nc" id="L74">            mergeJoinResult(sreq, mtasResponse, &quot;join&quot;, null);</span>

          }
          // merge prefix
<span class="fc" id="L78">          if (rb.req.getParams()</span>
<span class="pc bpc" id="L79" title="1 of 2 branches missed.">              .getBool(MtasSolrComponentPrefix.PARAM_MTAS_PREFIX, false)) {</span>
<span class="nc" id="L80">            mergeArrayList(sreq, mtasResponse, &quot;prefix&quot;, null, false);</span>
          }
<span class="fc bfc" id="L82" title="All 2 branches covered.">        } else if (rb.stage == MtasSolrSearchComponent.STAGE_TERMVECTOR_MISSING_KEY) {</span>
          // merge termvector
<span class="pc bpc" id="L84" title="1 of 2 branches missed.">          if (rb.req.getParams().getBool(</span>
              MtasSolrComponentTermvector.PARAM_MTAS_TERMVECTOR, false)) {
<span class="fc" id="L86">            mergeArrayList(sreq, mtasResponse, &quot;termvector&quot;, null, false);</span>
          }
<span class="pc bpc" id="L88" title="1 of 2 branches missed.">        } else if (rb.stage == MtasSolrSearchComponent.STAGE_LIST) {</span>
          // merge list
<span class="nc bnc" id="L90" title="All 2 branches missed.">          if (rb.req.getParams().getBool(MtasSolrComponentList.PARAM_MTAS_LIST,</span>
              false)) {
<span class="nc" id="L92">            mergeArrayList(sreq, mtasResponse, &quot;list&quot;,</span>
<span class="nc" id="L93">                ShardRequest.PURPOSE_PRIVATE, true);</span>
          }
<span class="fc bfc" id="L95" title="All 2 branches covered.">        } else if (rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {</span>
          // merge document
<span class="fc" id="L97">          if (rb.req.getParams()</span>
<span class="pc bpc" id="L98" title="1 of 2 branches missed.">              .getBool(MtasSolrComponentDocument.PARAM_MTAS_DOCUMENT, false)) {</span>
<span class="nc" id="L99">            mergeArrayList(sreq, mtasResponse, &quot;document&quot;,</span>
<span class="nc" id="L100">                ShardRequest.PURPOSE_PRIVATE, true);</span>
          }
          // merge kwic
<span class="pc bpc" id="L103" title="1 of 2 branches missed.">          if (rb.req.getParams().getBool(MtasSolrComponentKwic.PARAM_MTAS_KWIC,</span>
              false)) {
<span class="nc" id="L105">            mergeArrayList(sreq, mtasResponse, &quot;kwic&quot;,</span>
<span class="nc" id="L106">                ShardRequest.PURPOSE_PRIVATE, true);</span>
          }
        }
<span class="fc" id="L109">      }</span>
    }
<span class="fc" id="L111">  }</span>

  /**
   * Merge join result.
   *
   * @param sreq the sreq
   * @param mtasResponse the mtas response
   * @param key the key
   * @param preferredPurpose the preferred purpose
   */
  @SuppressWarnings(&quot;unchecked&quot;)
  private void mergeJoinResult(ShardRequest sreq,
      NamedList&lt;Object&gt; mtasResponse, String key, Integer preferredPurpose) {
<span class="nc" id="L124">    Object o = mtasResponse.get(key);</span>
    MtasSolrJoinResult mtasJoinResponse;
<span class="nc bnc" id="L126" title="All 2 branches missed.">    if (o instanceof MtasSolrJoinResult) {</span>
<span class="nc" id="L127">      mtasJoinResponse = (MtasSolrJoinResult) o;</span>
    } else {
<span class="nc" id="L129">      mtasJoinResponse = null;</span>
    }
    // collect responses for each shard
<span class="nc" id="L132">    HashMap&lt;String, NamedList&lt;Object&gt;&gt; mtasListShardResponses = new HashMap&lt;&gt;();</span>
<span class="nc bnc" id="L133" title="All 2 branches missed.">    for (ShardResponse response : sreq.responses) {</span>
      // only continue if new shard or preferred purpose
<span class="nc bnc" id="L135" title="All 4 branches missed.">      if (mtasListShardResponses.containsKey(response.getShard())</span>
          &amp;&amp; ((preferredPurpose == null)
<span class="nc bnc" id="L137" title="All 2 branches missed.">              || (sreq.purpose != preferredPurpose))) {</span>
<span class="nc" id="L138">        break;</span>
      }
      // update
      try {
<span class="nc" id="L142">        NamedList&lt;Object&gt; result = response.getSolrResponse().getResponse();</span>
<span class="nc" id="L143">        String data = (String) result.findRecursive(&quot;mtas&quot;, key);</span>
<span class="nc bnc" id="L144" title="All 2 branches missed.">        if (data != null) {</span>
<span class="nc" id="L145">          MtasSolrJoinResult decodedData = (MtasSolrJoinResult) MtasSolrResultUtil</span>
<span class="nc" id="L146">              .decode(data);</span>
<span class="nc bnc" id="L147" title="All 2 branches missed.">          if (mtasJoinResponse == null) {</span>
<span class="nc" id="L148">            mtasJoinResponse = decodedData;</span>
          } else {
<span class="nc" id="L150">            mtasJoinResponse.merge(decodedData);</span>
          }
        }
<span class="nc" id="L153">      } catch (ClassCastException e) {</span>
<span class="nc" id="L154">        log.debug(e);</span>
<span class="nc" id="L155">      }</span>
<span class="nc" id="L156">    }</span>
<span class="nc bnc" id="L157" title="All 2 branches missed.">    if (mtasJoinResponse != null) {</span>
<span class="nc" id="L158">      mtasResponse.removeAll(key);</span>
<span class="nc" id="L159">      mtasResponse.add(key, mtasJoinResponse);</span>
    }
<span class="nc" id="L161">  }</span>

  /**
   * Merge named list.
   *
   * @param sreq the sreq
   * @param mtasResponse the mtas response
   * @param key the key
   * @param preferredPurpose the preferred purpose
   */
  @SuppressWarnings(&quot;unchecked&quot;)
  private void mergeNamedList(ShardRequest sreq, NamedList&lt;Object&gt; mtasResponse,
      String key, Integer preferredPurpose) {
    // create new response for key
    NamedList&lt;Object&gt; mtasListResponse;
<span class="fc" id="L176">    Object o = mtasResponse.get(key);</span>
<span class="pc bpc" id="L177" title="1 of 2 branches missed.">    if (o instanceof NamedList) {</span>
<span class="nc" id="L178">      mtasListResponse = (NamedList&lt;Object&gt;) o;</span>
    } else {
<span class="fc" id="L180">      mtasListResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="fc" id="L181">      mtasResponse.removeAll(key);</span>
<span class="fc" id="L182">      mtasResponse.add(key, mtasListResponse);</span>
    }
    // collect responses for each shard
<span class="fc" id="L185">    HashMap&lt;String, NamedList&lt;Object&gt;&gt; mtasListShardResponses = new HashMap&lt;&gt;();</span>
<span class="fc bfc" id="L186" title="All 2 branches covered.">    for (ShardResponse response : sreq.responses) {</span>
      // only continue if new shard or preferred purpose
<span class="pc bpc" id="L188" title="3 of 4 branches missed.">      if (mtasListShardResponses.containsKey(response.getShard())</span>
          &amp;&amp; ((preferredPurpose == null)
<span class="nc bnc" id="L190" title="All 2 branches missed.">              || (sreq.purpose != preferredPurpose))) {</span>
<span class="nc" id="L191">        break;</span>
      }
      // update
      try {
<span class="fc" id="L195">        NamedList&lt;Object&gt; result = response.getSolrResponse().getResponse();</span>
<span class="fc" id="L196">        NamedList&lt;Object&gt; data = (NamedList&lt;Object&gt;) result</span>
<span class="fc" id="L197">            .findRecursive(&quot;mtas&quot;, key);</span>
<span class="pc bpc" id="L198" title="1 of 2 branches missed.">        if (data != null) {</span>
<span class="fc" id="L199">          mtasListShardResponses.put(response.getShard(),</span>
<span class="fc" id="L200">              MtasSolrResultUtil.decode(data));</span>
        }
<span class="nc" id="L202">      } catch (ClassCastException e) {</span>
<span class="nc" id="L203">        log.debug(e);</span>
<span class="fc" id="L204">      }</span>
<span class="fc" id="L205">    }</span>
    try {
<span class="fc bfc" id="L207" title="All 2 branches covered.">      for (NamedList&lt;Object&gt; mtasListShardResponse : mtasListShardResponses</span>
<span class="fc" id="L208">          .values()) {</span>
<span class="fc" id="L209">        mergeResponsesNamedList(mtasListResponse, mtasListShardResponse);</span>
<span class="fc" id="L210">      }</span>
<span class="nc" id="L211">    } catch (IOException e) {</span>
<span class="nc" id="L212">      log.error(e);</span>
<span class="fc" id="L213">    }</span>
<span class="fc" id="L214">  }</span>

  /**
   * Merge array list.
   *
   * @param sreq the sreq
   * @param mtasResponse the mtas response
   * @param key the key
   * @param preferredPurpose the preferred purpose
   * @param mergeAllShardResponses the merge all shard responses
   */
  @SuppressWarnings(&quot;unchecked&quot;)
  private void mergeArrayList(ShardRequest sreq, NamedList&lt;Object&gt; mtasResponse,
      String key, Integer preferredPurpose, boolean mergeAllShardResponses) {
    // create new response for key
    ArrayList&lt;Object&gt; mtasListResponse;
<span class="fc" id="L230">    Object o = mtasResponse.get(key);</span>
<span class="fc bfc" id="L231" title="All 2 branches covered.">    if (o instanceof ArrayList) {</span>
<span class="fc" id="L232">      mtasListResponse = (ArrayList&lt;Object&gt;) o;</span>
    } else {
<span class="fc" id="L234">      mtasListResponse = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L235">      mtasResponse.removeAll(key);</span>
<span class="fc" id="L236">      mtasResponse.add(key, mtasListResponse);</span>
    }
    // collect responses for each shard
<span class="fc" id="L239">    HashMap&lt;String, ArrayList&lt;Object&gt;&gt; mtasListShardResponses = new HashMap&lt;&gt;();</span>
<span class="fc" id="L240">    ArrayList&lt;ArrayList&lt;Object&gt;&gt; mtasListShardResponsesExtra = new ArrayList&lt;&gt;();</span>
<span class="fc bfc" id="L241" title="All 2 branches covered.">    for (ShardResponse response : sreq.responses) {</span>
      // only continue if new shard or preferred purpose
<span class="pc bpc" id="L243" title="3 of 4 branches missed.">      if (mtasListShardResponses.containsKey(response.getShard())</span>
          &amp;&amp; ((preferredPurpose == null)
<span class="nc bnc" id="L245" title="All 2 branches missed.">              || (sreq.purpose != preferredPurpose))) {</span>
<span class="nc" id="L246">        break;</span>
      }
      // update
      try {
<span class="fc" id="L250">        NamedList&lt;Object&gt; result = response.getSolrResponse().getResponse();</span>
<span class="fc" id="L251">        ArrayList&lt;Object&gt; data = (ArrayList&lt;Object&gt;) result</span>
<span class="fc" id="L252">            .findRecursive(&quot;mtas&quot;, key);</span>
<span class="pc bpc" id="L253" title="1 of 2 branches missed.">        if (data != null) {</span>
<span class="pc bpc" id="L254" title="1 of 2 branches missed.">          if (mtasListShardResponses.containsKey(response.getShardAddress())) {</span>
<span class="nc bnc" id="L255" title="All 2 branches missed.">            if (mergeAllShardResponses) {</span>
<span class="nc" id="L256">              mtasListShardResponsesExtra.add(data);</span>
            }
          } else {
<span class="fc" id="L259">            mtasListShardResponses.put(response.getShardAddress(), data);</span>
          }
        }
<span class="nc" id="L262">      } catch (ClassCastException e) {</span>
<span class="nc" id="L263">        log.error(e);</span>
<span class="fc" id="L264">      }</span>
<span class="fc" id="L265">    }</span>
   
    try {
<span class="fc bfc" id="L268" title="All 2 branches covered.">      for (ArrayList&lt;Object&gt; mtasListShardResponse : mtasListShardResponses</span>
<span class="fc" id="L269">          .values()) {</span>
<span class="fc" id="L270">        mergeResponsesArrayList(mtasListResponse, mtasListShardResponse);</span>
<span class="fc" id="L271">      }</span>
<span class="pc bpc" id="L272" title="1 of 2 branches missed.">      for (ArrayList&lt;Object&gt; mtasListShardResponse : mtasListShardResponsesExtra) {</span>
<span class="nc" id="L273">        mergeResponsesArrayList(mtasListResponse, mtasListShardResponse);</span>
<span class="nc" id="L274">      }      </span>
<span class="nc" id="L275">    } catch (IOException e) {</span>
<span class="nc" id="L276">      log.error(e);</span>
<span class="fc" id="L277">    }    </span>
<span class="fc" id="L278">  }</span>

  /**
   * Merge responses sorted set.
   *
   * @param originalList the original list
   * @param shardList the shard list
   */
  private void mergeResponsesSortedSet(SortedSet&lt;Object&gt; originalList,
      SortedSet&lt;Object&gt; shardList) {
<span class="nc bnc" id="L288" title="All 2 branches missed.">    for (Object item : shardList) {</span>
<span class="nc" id="L289">      originalList.add(item);</span>
<span class="nc" id="L290">    }</span>
<span class="nc" id="L291">  }</span>

  /**
   * Merge responses array list.
   *
   * @param originalList the original list
   * @param shardList the shard list
   * @throws IOException Signals that an I/O exception has occurred.
   */
  @SuppressWarnings(&quot;unchecked&quot;)
  private void mergeResponsesArrayList(ArrayList&lt;Object&gt; originalList,
      ArrayList&lt;Object&gt; shardList) throws IOException {
    // get keys from original
<span class="fc" id="L304">    HashMap&lt;String, Object&gt; originalKeyList = new HashMap&lt;&gt;();</span>
<span class="fc bfc" id="L305" title="All 2 branches covered.">    for (Object item : originalList) {</span>
<span class="pc bpc" id="L306" title="1 of 2 branches missed.">      if (item instanceof NamedList&lt;?&gt;) {</span>
<span class="fc" id="L307">        NamedList&lt;Object&gt; itemList = (NamedList&lt;Object&gt;) item;</span>
<span class="fc" id="L308">        Object key = itemList.get(&quot;key&quot;);</span>
<span class="pc bpc" id="L309" title="2 of 4 branches missed.">        if ((key != null) &amp;&amp; (key instanceof String)) {</span>
<span class="fc" id="L310">          originalKeyList.put((String) key, item);</span>
        }                
      }
<span class="fc" id="L313">    }</span>
<span class="fc bfc" id="L314" title="All 2 branches covered.">    for (Object item : shardList) {</span>
<span class="pc bpc" id="L315" title="1 of 2 branches missed.">      if (item instanceof NamedList&lt;?&gt;) {</span>
<span class="fc" id="L316">        NamedList&lt;Object&gt; itemList = (NamedList&lt;Object&gt;) item;</span>
<span class="fc" id="L317">        Object key = itemList.get(&quot;key&quot;);</span>
        // item with key
<span class="pc bpc" id="L319" title="2 of 4 branches missed.">        if ((key != null) &amp;&amp; (key instanceof String)) {</span>
          // merge
<span class="fc bfc" id="L321" title="All 2 branches covered.">          if (originalKeyList.containsKey(key)) {</span>
<span class="fc" id="L322">            Object originalItem = originalKeyList.get(key);</span>
<span class="pc bpc" id="L323" title="1 of 2 branches missed.">            if (originalItem.getClass().equals(item.getClass())) {</span>
<span class="fc" id="L324">              mergeResponsesNamedList((NamedList&lt;Object&gt;) originalItem,</span>
                  (NamedList&lt;Object&gt;) item);              
            } else {
              // ignore?
            }
            // add
<span class="fc" id="L330">          } else {</span>
<span class="fc" id="L331">            Object clonedItem = adjustablePartsCloned(item);</span>
<span class="fc" id="L332">            originalList.add(clonedItem);</span>
<span class="fc" id="L333">            originalKeyList.put((String) key, clonedItem);</span>
<span class="fc" id="L334">          }</span>
        } else {
<span class="nc" id="L336">          originalList.add(item);</span>
        }
<span class="fc" id="L338">      } else {</span>
<span class="nc" id="L339">        originalList.add(item);</span>
      }
<span class="fc" id="L341">    }</span>
<span class="fc" id="L342">  }</span>

  /**
   * Merge responses named list.
   *
   * @param mainResponse the main response
   * @param shardResponse the shard response
   * @throws IOException Signals that an I/O exception has occurred.
   */
  @SuppressWarnings({ &quot;rawtypes&quot;, &quot;unchecked&quot; })
  private void mergeResponsesNamedList(NamedList&lt;Object&gt; mainResponse,
      NamedList&lt;Object&gt; shardResponse) throws IOException {
<span class="fc" id="L354">    Iterator&lt;Entry&lt;String, Object&gt;&gt; it = shardResponse.iterator();</span>
<span class="fc bfc" id="L355" title="All 2 branches covered.">    while (it.hasNext()) {</span>
<span class="fc" id="L356">      Entry&lt;String, Object&gt; entry = it.next();</span>
<span class="fc" id="L357">      String name = entry.getKey();</span>
<span class="fc" id="L358">      Object shardValue = entry.getValue();</span>
<span class="fc" id="L359">      int originalId = mainResponse.indexOf(name, 0);</span>
<span class="fc bfc" id="L360" title="All 2 branches covered.">      if (originalId &lt; 0) {</span>
<span class="fc" id="L361">        mainResponse.add(name, adjustablePartsCloned(shardValue));</span>
      } else {
<span class="fc" id="L363">        Object original = mainResponse.getVal(originalId);</span>
<span class="pc bpc" id="L364" title="1 of 2 branches missed.">        if (original == null) {</span>
<span class="nc" id="L365">          original = adjustablePartsCloned(shardValue);</span>
<span class="pc bpc" id="L366" title="1 of 2 branches missed.">        } else if (shardValue != null</span>
<span class="pc bpc" id="L367" title="1 of 2 branches missed.">            &amp;&amp; original.getClass().equals(shardValue.getClass())) {</span>
          // merge ArrayList 
<span class="fc bfc" id="L369" title="All 2 branches covered.">          if (original instanceof ArrayList) {</span>
<span class="fc" id="L370">            ArrayList originalList = (ArrayList) original;</span>
<span class="fc" id="L371">            ArrayList shardList = (ArrayList) shardValue;</span>
<span class="fc" id="L372">            mergeResponsesArrayList(originalList, shardList);</span>
            // merge Namedlist
<span class="pc bpc" id="L374" title="1 of 2 branches missed.">          } else if (original instanceof NamedList&lt;?&gt;) {</span>
<span class="nc" id="L375">            mergeResponsesNamedList((NamedList&lt;Object&gt;) original,</span>
                (NamedList&lt;Object&gt;) shardValue);
            // merge SortedSet
<span class="pc bpc" id="L378" title="1 of 2 branches missed.">          } else if (original instanceof SortedSet&lt;?&gt;) {</span>
<span class="nc" id="L379">            mergeResponsesSortedSet((SortedSet&lt;Object&gt;) original,</span>
                (SortedSet&lt;Object&gt;) shardValue);
<span class="fc bfc" id="L381" title="All 2 branches covered.">          } else if (original instanceof MtasSolrMtasResult) {</span>
<span class="fc" id="L382">            MtasSolrMtasResult originalComponentResult = (MtasSolrMtasResult) original;</span>
<span class="fc" id="L383">            originalComponentResult.merge((MtasSolrMtasResult) shardValue);            </span>
<span class="pc bpc" id="L384" title="1 of 2 branches missed.">          } else if (original instanceof MtasSolrJoinResult) {</span>
<span class="nc" id="L385">            MtasSolrJoinResult originalComponentResult = (MtasSolrJoinResult) original;</span>
<span class="nc" id="L386">            originalComponentResult.merge((MtasSolrJoinResult) shardValue);</span>
<span class="pc bpc" id="L387" title="1 of 2 branches missed.">          } else if (original instanceof String) {</span>
            // ignore?
<span class="nc bnc" id="L389" title="All 2 branches missed.">          } else if (original instanceof Integer) {</span>
<span class="nc" id="L390">            original = (Integer) original + ((Integer) shardValue);</span>
<span class="nc bnc" id="L391" title="All 2 branches missed.">          } else if (original instanceof Long) {</span>
<span class="nc" id="L392">            original = (Long) original + ((Long) shardValue);</span>
          } else {
            // ignore?
          }
<span class="fc" id="L396">          mainResponse.setVal(originalId, original);</span>
        } else {
          // ignore?
        }
      }
<span class="fc" id="L401">    }</span>
<span class="fc" id="L402">  }</span>

  /**
   * Adjustable parts cloned.
   *
   * @param original the original
   * @return the object
   */
  @SuppressWarnings({ &quot;rawtypes&quot;, &quot;unchecked&quot; })
  private Object adjustablePartsCloned(Object original) {
<span class="fc bfc" id="L412" title="All 2 branches covered.">    if (original instanceof NamedList) {</span>
<span class="fc" id="L413">      NamedList&lt;Object&gt; newObject = new SimpleOrderedMap();</span>
<span class="fc" id="L414">      NamedList&lt;Object&gt; originalObject = (NamedList&lt;Object&gt;) original;</span>
<span class="fc bfc" id="L415" title="All 2 branches covered.">      for (int i = 0; i &lt; originalObject.size(); i++) {</span>
<span class="fc" id="L416">        newObject.add(originalObject.getName(i),</span>
<span class="fc" id="L417">            adjustablePartsCloned(originalObject.getVal(i)));</span>
      }
<span class="fc" id="L419">      return newObject;</span>
<span class="fc bfc" id="L420" title="All 2 branches covered.">    } else if (original instanceof ArrayList) {</span>
<span class="fc" id="L421">      ArrayList&lt;Object&gt; newObject = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L422">      ArrayList&lt;Object&gt; originalObject = (ArrayList&lt;Object&gt;) original;</span>
<span class="fc bfc" id="L423" title="All 2 branches covered.">      for (int i = 0; i &lt; originalObject.size(); i++) {</span>
<span class="fc" id="L424">        newObject.add(adjustablePartsCloned(originalObject.get(i)));</span>
      }
<span class="fc" id="L426">      return newObject;</span>
<span class="pc bpc" id="L427" title="1 of 2 branches missed.">    } else if (original instanceof Integer) {</span>
<span class="nc" id="L428">      return original;</span>
    }
<span class="fc" id="L430">    return original;</span>
  }

}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>