<?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>MtasBasicParser.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.analysis.parser</a> &gt; <span class="el_source">MtasBasicParser.java</span></div><h1>MtasBasicParser.java</h1><pre class="source lang-java linenums">package mtas.analysis.parser;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mtas.analysis.token.MtasToken;
import mtas.analysis.token.MtasTokenIdFactory;
import mtas.analysis.token.MtasTokenString;
import mtas.analysis.util.MtasConfigException;
import mtas.analysis.util.MtasConfiguration;
import mtas.analysis.util.MtasParserException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilter;
import org.apache.lucene.analysis.payloads.PayloadHelper;
import org.apache.lucene.util.BytesRef;

/**
 * The Class MtasBasicParser.
 */
public abstract class MtasBasicParser extends MtasParser {

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

  /** The Constant MAPPING_TYPE_REF. */
  protected static final String MAPPING_TYPE_REF = &quot;ref&quot;;

  /** The Constant MAPPING_TYPE_RELATION. */
  protected static final String MAPPING_TYPE_RELATION = &quot;relation&quot;;

  /** The Constant MAPPING_TYPE_RELATION_ANNOTATION. */
  protected static final String MAPPING_TYPE_RELATION_ANNOTATION = &quot;relationAnnotation&quot;;

  /** The Constant MAPPING_TYPE_GROUP. */
  protected static final String MAPPING_TYPE_GROUP = &quot;group&quot;;

  /** The Constant MAPPING_TYPE_GROUP_ANNOTATION. */
  protected static final String MAPPING_TYPE_GROUP_ANNOTATION = &quot;groupAnnotation&quot;;

  /** The Constant MAPPING_TYPE_WORD. */
  protected static final String MAPPING_TYPE_WORD = &quot;word&quot;;

  /** The Constant MAPPING_TYPE_WORD_ANNOTATION. */
  protected static final String MAPPING_TYPE_WORD_ANNOTATION = &quot;wordAnnotation&quot;;

  /** The Constant ITEM_TYPE_STRING. */
  protected static final String ITEM_TYPE_STRING = &quot;string&quot;;

  /** The Constant ITEM_TYPE_NAME. */
  protected static final String ITEM_TYPE_NAME = &quot;name&quot;;

  /** The Constant ITEM_TYPE_NAME_ANCESTOR. */
  protected static final String ITEM_TYPE_NAME_ANCESTOR = &quot;ancestorName&quot;;

  /** The Constant ITEM_TYPE_NAME_ANCESTOR_GROUP. */
  protected static final String ITEM_TYPE_NAME_ANCESTOR_GROUP = &quot;ancestorGroupName&quot;;

  /** The Constant ITEM_TYPE_NAME_ANCESTOR_GROUP_ANNOTATION. */
  protected static final String ITEM_TYPE_NAME_ANCESTOR_GROUP_ANNOTATION = &quot;ancestorGroupAnnotationName&quot;;

  /** The Constant ITEM_TYPE_NAME_ANCESTOR_WORD. */
  protected static final String ITEM_TYPE_NAME_ANCESTOR_WORD = &quot;ancestorWordName&quot;;

  /** The Constant ITEM_TYPE_NAME_ANCESTOR_WORD_ANNOTATION. */
  protected static final String ITEM_TYPE_NAME_ANCESTOR_WORD_ANNOTATION = &quot;ancestorWordAnnotationName&quot;;

  /** The Constant ITEM_TYPE_NAME_ANCESTOR_RELATION. */
  protected static final String ITEM_TYPE_NAME_ANCESTOR_RELATION = &quot;ancestorRelationName&quot;;

  /** The Constant ITEM_TYPE_NAME_ANCESTOR_RELATION_ANNOTATION. */
  protected static final String ITEM_TYPE_NAME_ANCESTOR_RELATION_ANNOTATION = &quot;ancestorRelationAnnotationName&quot;;

  /** The Constant ITEM_TYPE_ATTRIBUTE. */
  protected static final String ITEM_TYPE_ATTRIBUTE = &quot;attribute&quot;;

  /** The Constant ITEM_TYPE_ATTRIBUTE_ANCESTOR. */
  protected static final String ITEM_TYPE_ATTRIBUTE_ANCESTOR = &quot;ancestorAttribute&quot;;

  /** The Constant ITEM_TYPE_ATTRIBUTE_ANCESTOR_GROUP. */
  protected static final String ITEM_TYPE_ATTRIBUTE_ANCESTOR_GROUP = &quot;ancestorGroupAttribute&quot;;

  /** The Constant ITEM_TYPE_ATTRIBUTE_ANCESTOR_GROUP_ANNOTATION. */
  protected static final String ITEM_TYPE_ATTRIBUTE_ANCESTOR_GROUP_ANNOTATION = &quot;ancestorGroupAnnotationAttribute&quot;;

  /** The Constant ITEM_TYPE_ATTRIBUTE_ANCESTOR_WORD. */
  protected static final String ITEM_TYPE_ATTRIBUTE_ANCESTOR_WORD = &quot;ancestorWordAttribute&quot;;

  /** The Constant ITEM_TYPE_ATTRIBUTE_ANCESTOR_WORD_ANNOTATION. */
  protected static final String ITEM_TYPE_ATTRIBUTE_ANCESTOR_WORD_ANNOTATION = &quot;ancestorWordAnnotationAttribute&quot;;

  /** The Constant ITEM_TYPE_ATTRIBUTE_ANCESTOR_RELATION. */
  protected static final String ITEM_TYPE_ATTRIBUTE_ANCESTOR_RELATION = &quot;ancestorRelationAttribute&quot;;

  /** The Constant ITEM_TYPE_ATTRIBUTE_ANCESTOR_RELATION_ANNOTATION. */
  protected static final String ITEM_TYPE_ATTRIBUTE_ANCESTOR_RELATION_ANNOTATION = &quot;ancestorRelationAnnotationAttribute&quot;;

  /** The Constant ITEM_TYPE_TEXT. */
  protected static final String ITEM_TYPE_TEXT = &quot;text&quot;;

  /** The Constant ITEM_TYPE_TEXT_SPLIT. */
  protected static final String ITEM_TYPE_TEXT_SPLIT = &quot;textSplit&quot;;

  /** The Constant ITEM_TYPE_UNKNOWN_ANCESTOR. */
  protected static final String ITEM_TYPE_UNKNOWN_ANCESTOR = &quot;unknownAncestor&quot;;

  /** The Constant ITEM_TYPE_ANCESTOR. */
  protected static final String ITEM_TYPE_ANCESTOR = &quot;ancestor&quot;;

  /** The Constant ITEM_TYPE_ANCESTOR_GROUP. */
  protected static final String ITEM_TYPE_ANCESTOR_GROUP = &quot;ancestorGroup&quot;;

  /** The Constant ITEM_TYPE_ANCESTOR_GROUP_ANNOTATION. */
  protected static final String ITEM_TYPE_ANCESTOR_GROUP_ANNOTATION = &quot;ancestorGroupAnnotation&quot;;

  /** The Constant ITEM_TYPE_ANCESTOR_WORD. */
  protected static final String ITEM_TYPE_ANCESTOR_WORD = &quot;ancestorWord&quot;;

  /** The Constant ITEM_TYPE_ANCESTOR_WORD_ANNOTATION. */
  protected static final String ITEM_TYPE_ANCESTOR_WORD_ANNOTATION = &quot;ancestorWordAnnotation&quot;;

  /** The Constant ITEM_TYPE_ANCESTOR_RELATION. */
  protected static final String ITEM_TYPE_ANCESTOR_RELATION = &quot;ancestorRelation&quot;;

  /** The Constant ITEM_TYPE_ANCESTOR_RELATION_ANNOTATION. */
  protected static final String ITEM_TYPE_ANCESTOR_RELATION_ANNOTATION = &quot;ancestorRelationAnnotation&quot;;

  /** The Constant ITEM_TYPE_VARIABLE_FROM_ATTRIBUTE. */
  protected static final String ITEM_TYPE_VARIABLE_FROM_ATTRIBUTE = &quot;variableFromAttribute&quot;;

  /** The Constant VARIABLE_SUBTYPE_VALUE. */
  protected static final String VARIABLE_SUBTYPE_VALUE = &quot;value&quot;;

  /** The Constant VARIABLE_SUBTYPE_VALUE_ITEM. */
  protected static final String VARIABLE_SUBTYPE_VALUE_ITEM = &quot;item&quot;;

  /** The Constant MAPPING_SUBTYPE_TOKEN. */
  protected static final String MAPPING_SUBTYPE_TOKEN = &quot;token&quot;;

  /** The Constant MAPPING_SUBTYPE_TOKEN_PRE. */
  protected static final String MAPPING_SUBTYPE_TOKEN_PRE = &quot;pre&quot;;

  /** The Constant MAPPING_SUBTYPE_TOKEN_POST. */
  protected static final String MAPPING_SUBTYPE_TOKEN_POST = &quot;post&quot;;

  /** The Constant MAPPING_SUBTYPE_PAYLOAD. */
  protected static final String MAPPING_SUBTYPE_PAYLOAD = &quot;payload&quot;;

  /** The Constant MAPPING_SUBTYPE_CONDITION. */
  protected static final String MAPPING_SUBTYPE_CONDITION = &quot;condition&quot;;

  /** The Constant MAPPING_FILTER_UPPERCASE. */
  protected static final String MAPPING_FILTER_UPPERCASE = &quot;uppercase&quot;;

  /** The Constant MAPPING_FILTER_LOWERCASE. */
  protected static final String MAPPING_FILTER_LOWERCASE = &quot;lowercase&quot;;

  /** The Constant MAPPING_FILTER_ASCII. */
  protected static final String MAPPING_FILTER_ASCII = &quot;ascii&quot;;

  /** The Constant MAPPING_FILTER_SPLIT. */
  protected static final String MAPPING_FILTER_SPLIT = &quot;split&quot;;

  /** The Constant UPDATE_TYPE_OFFSET. */
  protected static final String UPDATE_TYPE_OFFSET = &quot;offsetUpdate&quot;;

  /** The Constant UPDATE_TYPE_POSITION. */
  protected static final String UPDATE_TYPE_POSITION = &quot;positionUpdate&quot;;

  /** The Constant UPDATE_TYPE_VARIABLE. */
  protected static final String UPDATE_TYPE_VARIABLE = &quot;variableUpdate&quot;;

  /** The Constant UPDATE_TYPE_LOCAL_REF_OFFSET_START. */
  protected static final String UPDATE_TYPE_LOCAL_REF_OFFSET_START = &quot;localRefOffsetStartUpdate&quot;;

  /** The Constant UPDATE_TYPE_LOCAL_REF_OFFSET_END. */
  protected static final String UPDATE_TYPE_LOCAL_REF_OFFSET_END = &quot;localRefOffsetEndUpdate&quot;;

  /** The Constant UPDATE_TYPE_LOCAL_REF_POSITION_START. */
  protected static final String UPDATE_TYPE_LOCAL_REF_POSITION_START = &quot;localRefPositionStartUpdate&quot;;

  /** The Constant UPDATE_TYPE_LOCAL_REF_POSITION_END. */
  protected static final String UPDATE_TYPE_LOCAL_REF_POSITION_END = &quot;localRefPositionEndUpdate&quot;;

  /** The Constant MAPPING_VALUE_VALUE. */
  protected static final String MAPPING_VALUE_VALUE = &quot;value&quot;;

  /** The Constant MAPPING_VALUE_TYPE. */
  protected static final String MAPPING_VALUE_TYPE = &quot;type&quot;;

  /** The Constant MAPPING_VALUE_NAME. */
  protected static final String MAPPING_VALUE_NAME = &quot;name&quot;;

  /** The Constant MAPPING_VALUE_PREFIX. */
  protected static final String MAPPING_VALUE_PREFIX = &quot;prefix&quot;;

  /** The Constant MAPPING_VALUE_FILTER. */
  protected static final String MAPPING_VALUE_FILTER = &quot;filter&quot;;

  /** The Constant MAPPING_VALUE_DISTANCE. */
  protected static final String MAPPING_VALUE_DISTANCE = &quot;distance&quot;;

  /** The Constant MAPPING_VALUE_SOURCE. */
  protected static final String MAPPING_VALUE_SOURCE = &quot;source&quot;;

  /** The Constant MAPPING_VALUE_ANCESTOR. */
  protected static final String MAPPING_VALUE_ANCESTOR = &quot;ancestor&quot;;

  /** The Constant MAPPING_VALUE_SPLIT. */
  protected static final String MAPPING_VALUE_SPLIT = &quot;split&quot;;

  /** The Constant MAPPING_VALUE_NUMBER. */
  protected static final String MAPPING_VALUE_NUMBER = &quot;number&quot;;

  /** The Constant MAPPING_VALUE_CONDITION. */
  protected static final String MAPPING_VALUE_CONDITION = &quot;condition&quot;;

  /** The Constant MAPPING_VALUE_TEXT. */
  protected static final String MAPPING_VALUE_TEXT = &quot;text&quot;;

  /** The Constant MAPPING_VALUE_NOT. */
  protected static final String MAPPING_VALUE_NOT = &quot;not&quot;;

  /** The enc. */
<span class="pc" id="L236">  private Base64.Encoder enc = Base64.getEncoder();</span>

  /** The dec. */
<span class="pc" id="L239">  private Base64.Decoder dec = Base64.getDecoder();</span>

  /**
   * Instantiates a new mtas basic parser.
   */
<span class="nc" id="L244">  public MtasBasicParser() {</span>
<span class="nc" id="L245">  }</span>

  /**
   * Instantiates a new mtas basic parser.
   *
   * @param config the config
   */
<span class="fc" id="L252">  public MtasBasicParser(MtasConfiguration config) {</span>
<span class="fc" id="L253">    this.config = config;</span>
<span class="fc" id="L254">  }</span>

  /**
   * Creates the current list.
   *
   * @return the map
   */
  protected Map&lt;String, List&lt;MtasParserObject&gt;&gt; createCurrentList() {
<span class="fc" id="L262">    Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList = new HashMap&lt;&gt;();</span>
<span class="fc" id="L263">    currentList.put(MAPPING_TYPE_RELATION, new ArrayList&lt;MtasParserObject&gt;());</span>
<span class="fc" id="L264">    currentList.put(MAPPING_TYPE_RELATION_ANNOTATION,</span>
        new ArrayList&lt;MtasParserObject&gt;());
<span class="fc" id="L266">    currentList.put(MAPPING_TYPE_REF, new ArrayList&lt;MtasParserObject&gt;());</span>
<span class="fc" id="L267">    currentList.put(MAPPING_TYPE_GROUP, new ArrayList&lt;MtasParserObject&gt;());</span>
<span class="fc" id="L268">    currentList.put(MAPPING_TYPE_GROUP_ANNOTATION,</span>
        new ArrayList&lt;MtasParserObject&gt;());
<span class="fc" id="L270">    currentList.put(MAPPING_TYPE_WORD, new ArrayList&lt;MtasParserObject&gt;());</span>
<span class="fc" id="L271">    currentList.put(MAPPING_TYPE_WORD_ANNOTATION,</span>
        new ArrayList&lt;MtasParserObject&gt;());
<span class="fc" id="L273">    return currentList;</span>
  }

  /**
   * Creates the update list.
   *
   * @return the map
   */
  protected Map&lt;String, Map&lt;Integer, Set&lt;String&gt;&gt;&gt; createUpdateList() {
<span class="fc" id="L282">    Map&lt;String, Map&lt;Integer, Set&lt;String&gt;&gt;&gt; updateList = new HashMap&lt;&gt;();</span>
<span class="fc" id="L283">    updateList.put(UPDATE_TYPE_OFFSET, new HashMap&lt;&gt;());</span>
<span class="fc" id="L284">    updateList.put(UPDATE_TYPE_POSITION, new HashMap&lt;&gt;());</span>
<span class="fc" id="L285">    updateList.put(UPDATE_TYPE_LOCAL_REF_POSITION_START, new HashMap&lt;&gt;());</span>
<span class="fc" id="L286">    updateList.put(UPDATE_TYPE_LOCAL_REF_POSITION_END, new HashMap&lt;&gt;());</span>
<span class="fc" id="L287">    updateList.put(UPDATE_TYPE_LOCAL_REF_OFFSET_START, new HashMap&lt;&gt;());</span>
<span class="fc" id="L288">    updateList.put(UPDATE_TYPE_LOCAL_REF_OFFSET_END, new HashMap&lt;&gt;());</span>
<span class="fc" id="L289">    updateList.put(UPDATE_TYPE_VARIABLE, new HashMap&lt;&gt;());</span>
<span class="fc" id="L290">    return updateList;</span>
  }

  /**
   * Creates the variables.
   *
   * @return the map
   */
  protected Map&lt;String, Map&lt;String, String&gt;&gt; createVariables() {
<span class="fc" id="L299">    return new HashMap&lt;&gt;();</span>
  }

  /**
   * Compute mappings from object.
   *
   * @param mtasTokenIdFactory the mtas token id factory
   * @param object the object
   * @param currentList the current list
   * @param updateList the update list
   * @throws MtasParserException the mtas parser exception
   * @throws MtasConfigException the mtas config exception
   */
  protected void computeMappingsFromObject(
      MtasTokenIdFactory mtasTokenIdFactory, MtasParserObject object,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList,
      Map&lt;String, Map&lt;Integer, Set&lt;String&gt;&gt;&gt; updateList)
      throws MtasParserException, MtasConfigException {
<span class="fc" id="L317">    MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; objectType = object.getType();</span>
<span class="fc" id="L318">    List&lt;MtasParserMapping&lt;?&gt;&gt; mappings = objectType.getItems();</span>
<span class="pc bpc" id="L319" title="1 of 2 branches missed.">    if (!object.updateableMappingsWithPosition.isEmpty()) {</span>
<span class="nc bnc" id="L320" title="All 2 branches missed.">      for (int tokenId : object.updateableMappingsWithPosition) {</span>
<span class="nc" id="L321">        updateList.get(UPDATE_TYPE_POSITION).put(tokenId, object.getRefIds());</span>
<span class="nc" id="L322">      }</span>
    }
<span class="fc bfc" id="L324" title="All 2 branches covered.">    if (!object.updateableMappingsWithOffset.isEmpty()) {</span>
<span class="fc bfc" id="L325" title="All 2 branches covered.">      for (int tokenId : object.updateableMappingsWithOffset) {</span>
<span class="fc" id="L326">        updateList.get(UPDATE_TYPE_OFFSET).put(tokenId, object.getRefIds());</span>
<span class="fc" id="L327">      }</span>
    }
<span class="fc bfc" id="L329" title="All 2 branches covered.">    for (MtasParserMapping&lt;?&gt; mapping : mappings) {</span>
      try {
<span class="fc bfc" id="L331" title="All 2 branches covered.">        if (mapping.getTokens().isEmpty()) {</span>
          // empty exception
        } else {
<span class="fc bfc" id="L334" title="All 2 branches covered.">          for (int i = 0; i &lt; mapping.getTokens().size(); i++) {</span>
<span class="fc" id="L335">            MtasParserMappingToken mappingToken = mapping.getTokens().get(i);</span>
            // empty exception
<span class="pc bpc" id="L337" title="1 of 2 branches missed.">            if (mappingToken.preValues.isEmpty()) {</span>
              // continue, but no token
            } else {
              // check conditions
<span class="fc" id="L341">              postcheckMappingConditions(object, mapping.getConditions(),</span>
                  currentList);
<span class="fc" id="L343">              boolean containsVariables = checkForVariables(</span>
                  mappingToken.preValues);
<span class="pc bpc" id="L345" title="1 of 2 branches missed.">              containsVariables = !containsVariables</span>
<span class="pc" id="L346">                  ? checkForVariables(mappingToken.postValues)</span>
                  : containsVariables;
              // construct preValue
<span class="fc" id="L349">              String[] preValue = computeValueFromMappingValues(object,</span>
                  mappingToken.preValues, currentList, containsVariables);
              // at least preValue
<span class="pc bpc" id="L352" title="2 of 4 branches missed.">              if (preValue == null || preValue.length == 0) {</span>
<span class="nc" id="L353">                throw new MtasParserException(&quot;no preValues&quot;);</span>
              } else {
                // no delimiter in preValue
<span class="fc bfc" id="L356" title="All 2 branches covered.">                for (int k = 0; k &lt; preValue.length; k++) {</span>
<span class="fc" id="L357">                  if ((preValue[k] = preValue[k].replace(MtasToken.DELIMITER,</span>
<span class="pc bpc" id="L358" title="1 of 2 branches missed.">                      &quot;&quot;)).isEmpty()) {</span>
<span class="nc" id="L359">                    throw new MtasParserException(&quot;empty preValue&quot;);</span>
                  }
                }
              }
              // construct postValue
<span class="fc" id="L364">              String[] postValue = computeValueFromMappingValues(object,</span>
                  mappingToken.postValues, currentList, containsVariables);
              // construct value
              String[] value;
<span class="pc bpc" id="L368" title="1 of 4 branches missed.">              if (postValue == null || postValue.length == 0) {</span>
<span class="fc" id="L369">                value = preValue.clone();</span>
<span class="fc bfc" id="L370" title="All 2 branches covered.">                for (int k = 0; k &lt; value.length; k++) {</span>
<span class="fc" id="L371">                  value[k] = value[k] + MtasToken.DELIMITER;</span>
                }
<span class="pc bpc" id="L373" title="1 of 2 branches missed.">              } else if (postValue.length == 1) {</span>
<span class="fc" id="L374">                value = preValue.clone();</span>
<span class="fc bfc" id="L375" title="All 2 branches covered.">                for (int k = 0; k &lt; value.length; k++) {</span>
<span class="fc" id="L376">                  value[k] = value[k] + MtasToken.DELIMITER + postValue[0];</span>
                }
<span class="nc bnc" id="L378" title="All 2 branches missed.">              } else if (preValue.length == 1) {</span>
<span class="nc" id="L379">                value = postValue.clone();</span>
<span class="nc bnc" id="L380" title="All 2 branches missed.">                for (int k = 0; k &lt; value.length; k++) {</span>
<span class="nc" id="L381">                  value[k] = preValue[0] + MtasToken.DELIMITER + value[k];</span>
                }
              } else {
<span class="nc" id="L384">                value = new String[preValue.length * postValue.length];</span>
<span class="nc" id="L385">                int number = 0;</span>
<span class="nc bnc" id="L386" title="All 2 branches missed.">                for (int k1 = 0; k1 &lt; preValue.length; k1++) {</span>
<span class="nc bnc" id="L387" title="All 2 branches missed.">                  for (int k2 = 0; k2 &lt; postValue.length; k2++) {</span>
<span class="nc" id="L388">                    value[number] = preValue[k1] + MtasToken.DELIMITER</span>
                        + postValue[k2];
<span class="nc" id="L390">                    number++;</span>
                  }
                }
              }
              // construct payload
<span class="fc" id="L395">              BytesRef payload = computePayloadFromMappingPayload(object,</span>
                  mappingToken.payload, currentList);
              // create token and get id: from now on, we must continue, no
              // exceptions allowed...
<span class="fc bfc" id="L399" title="All 2 branches covered.">              for (int k = 0; k &lt; value.length; k++) {</span>
<span class="fc" id="L400">                MtasTokenString token = new MtasTokenString(</span>
<span class="fc" id="L401">                    mtasTokenIdFactory.createTokenId(), value[k]);</span>
                // store settings offset, realoffset and parent
<span class="fc" id="L403">                token.setProvideOffset(mappingToken.offset);</span>
<span class="fc" id="L404">                token.setProvideRealOffset(mappingToken.realoffset);</span>
<span class="fc" id="L405">                token.setProvideParentId(mappingToken.parent);</span>
<span class="fc" id="L406">                String checkType = object.objectType.getType();</span>
                // register token if it contains variables
<span class="pc bpc" id="L408" title="1 of 2 branches missed.">                if (containsVariables) {</span>
<span class="nc" id="L409">                  updateList.get(UPDATE_TYPE_VARIABLE).put(token.getId(), null);</span>
                }
                // register id for update when parent is created
<span class="fc bfc" id="L412" title="All 2 branches covered.">                if (!currentList.get(checkType).isEmpty()) {</span>
<span class="pc bpc" id="L413" title="1 of 2 branches missed.">                  if (currentList.get(checkType).contains(object)) {</span>
<span class="nc" id="L414">                    int listPosition = currentList.get(checkType)</span>
<span class="nc" id="L415">                        .indexOf(object);</span>
<span class="nc bnc" id="L416" title="All 2 branches missed.">                    if (listPosition &gt; 0) {</span>
<span class="nc" id="L417">                      currentList.get(checkType).get(listPosition - 1)</span>
<span class="nc" id="L418">                          .registerUpdateableMappingAtParent(token.getId());</span>
                    }
<span class="nc" id="L420">                  } else {</span>
<span class="fc" id="L421">                    currentList.get(checkType)</span>
<span class="fc" id="L422">                        .get(currentList.get(checkType).size() - 1)</span>
<span class="fc" id="L423">                        .registerUpdateableMappingAtParent(token.getId());</span>
                  }
                  // if no real ancestor, register id update when group
                  // ancestor is created
<span class="fc bfc" id="L427" title="All 2 branches covered.">                } else if (!currentList.get(MAPPING_TYPE_GROUP).isEmpty()) {</span>
<span class="fc" id="L428">                  currentList.get(MAPPING_TYPE_GROUP)</span>
<span class="fc" id="L429">                      .get(currentList.get(MAPPING_TYPE_GROUP).size() - 1)</span>
<span class="fc" id="L430">                      .registerUpdateableMappingAtParent(token.getId());</span>
<span class="pc bpc" id="L431" title="1 of 2 branches missed.">                } else if (!currentList.get(MAPPING_TYPE_RELATION).isEmpty()) {</span>
<span class="nc" id="L432">                  currentList.get(MAPPING_TYPE_RELATION)</span>
<span class="nc" id="L433">                      .get(currentList.get(MAPPING_TYPE_RELATION).size() - 1)</span>
<span class="nc" id="L434">                      .registerUpdateableMappingAtParent(token.getId());</span>
                }
                // update children
<span class="fc bfc" id="L437" title="All 2 branches covered.">                for (Integer tmpId : object.getUpdateableMappingsAsParent()) {</span>
<span class="pc bpc" id="L438" title="1 of 2 branches missed.">                  if (tokenCollection.get(tmpId) != null) {</span>
<span class="fc" id="L439">                    tokenCollection.get(tmpId).setParentId(token.getId());</span>
                  }
<span class="fc" id="L441">                }</span>
<span class="fc" id="L442">                object.resetUpdateableMappingsAsParent();</span>
                // use own position
<span class="fc bfc" id="L444" title="All 2 branches covered.">                if (mapping.position.equals(MtasParserMapping.SOURCE_OWN)) {</span>
<span class="fc" id="L445">                  token.addPositions(object.getPositions());</span>
                  // use position from ancestorGroup
<span class="fc" id="L447">                } else if (mapping.position</span>
<span class="pc bpc" id="L448" title="1 of 2 branches missed.">                    .equals(MtasParserMapping.SOURCE_ANCESTOR_GROUP)</span>
<span class="nc bnc" id="L449" title="All 2 branches missed.">                    &amp;&amp; (!currentList.get(MAPPING_TYPE_GROUP).isEmpty())) {</span>
<span class="nc" id="L450">                  currentList.get(MAPPING_TYPE_GROUP)</span>
<span class="nc" id="L451">                      .get(currentList.get(MAPPING_TYPE_GROUP).size() - 1)</span>
<span class="nc" id="L452">                      .addUpdateableMappingWithPosition(token.getId());</span>
                  // use position from ancestorWord
<span class="fc" id="L454">                } else if (mapping.position</span>
<span class="pc bpc" id="L455" title="1 of 2 branches missed.">                    .equals(MtasParserMapping.SOURCE_ANCESTOR_WORD)</span>
<span class="nc bnc" id="L456" title="All 2 branches missed.">                    &amp;&amp; (!currentList.get(MAPPING_TYPE_WORD).isEmpty())) {</span>
<span class="nc" id="L457">                  currentList.get(MAPPING_TYPE_WORD)</span>
<span class="nc" id="L458">                      .get(currentList.get(MAPPING_TYPE_WORD).size() - 1)</span>
<span class="nc" id="L459">                      .addUpdateableMappingWithPosition(token.getId());</span>
                  // use position from ancestorRelation
<span class="fc" id="L461">                } else if (mapping.position</span>
<span class="pc bpc" id="L462" title="1 of 2 branches missed.">                    .equals(MtasParserMapping.SOURCE_ANCESTOR_RELATION)</span>
<span class="nc bnc" id="L463" title="All 2 branches missed.">                    &amp;&amp; (!currentList.get(MAPPING_TYPE_RELATION).isEmpty())) {</span>
<span class="nc" id="L464">                  currentList.get(MAPPING_TYPE_RELATION)</span>
<span class="nc" id="L465">                      .get(currentList.get(MAPPING_TYPE_RELATION).size() - 1)</span>
<span class="nc" id="L466">                      .addUpdateableMappingWithPosition(token.getId());</span>
                  // register id to get positions later from references
<span class="fc" id="L468">                } else if (mapping.position</span>
<span class="pc bpc" id="L469" title="1 of 2 branches missed.">                    .equals(MtasParserMapping.SOURCE_REFS)) {</span>
<span class="pc bpc" id="L470" title="1 of 2 branches missed.">                  if (mapping.type.equals(MAPPING_TYPE_GROUP_ANNOTATION)) {</span>
<span class="nc bnc" id="L471" title="All 4 branches missed.">                    if (mapping.start != null &amp;&amp; mapping.end != null) {</span>
<span class="nc" id="L472">                      String start = object.getAttribute(mapping.start);</span>
<span class="nc" id="L473">                      String end = object.getAttribute(mapping.end);</span>
<span class="nc bnc" id="L474" title="All 6 branches missed.">                      if (start != null &amp;&amp; !start.isEmpty() &amp;&amp; end != null</span>
<span class="nc bnc" id="L475" title="All 2 branches missed.">                          &amp;&amp; !end.isEmpty()) {</span>
<span class="nc bnc" id="L476" title="All 2 branches missed.">                        if (start.startsWith(&quot;#&quot;)) {</span>
<span class="nc" id="L477">                          start = start.substring(1);</span>
                        }
<span class="nc bnc" id="L479" title="All 2 branches missed.">                        if (end.startsWith(&quot;#&quot;)) {</span>
<span class="nc" id="L480">                          end = end.substring(1);</span>
                        }
<span class="nc" id="L482">                        updateList.get(UPDATE_TYPE_LOCAL_REF_POSITION_START)</span>
<span class="nc" id="L483">                            .put(token.getId(),</span>
<span class="nc" id="L484">                                new HashSet&lt;String&gt;(Arrays.asList(start)));</span>
<span class="nc" id="L485">                        updateList.get(UPDATE_TYPE_LOCAL_REF_POSITION_END).put(</span>
<span class="nc" id="L486">                            token.getId(),</span>
<span class="nc" id="L487">                            new HashSet&lt;String&gt;(Arrays.asList(end)));</span>
<span class="nc" id="L488">                        updateList.get(UPDATE_TYPE_LOCAL_REF_OFFSET_START).put(</span>
<span class="nc" id="L489">                            token.getId(),</span>
<span class="nc" id="L490">                            new HashSet&lt;String&gt;(Arrays.asList(start)));</span>
<span class="nc" id="L491">                        updateList.get(UPDATE_TYPE_LOCAL_REF_OFFSET_END).put(</span>
<span class="nc" id="L492">                            token.getId(),</span>
<span class="nc" id="L493">                            new HashSet&lt;String&gt;(Arrays.asList(end)));</span>
                      }
<span class="nc" id="L495">                    }</span>
                  } else {
<span class="fc" id="L497">                    updateList.get(UPDATE_TYPE_POSITION).put(token.getId(),</span>
<span class="fc" id="L498">                        object.getRefIds());</span>
                  }
                } else {
                  // should not happen
                }
                // use own offset
<span class="fc bfc" id="L504" title="All 2 branches covered.">                if (mapping.offset.equals(MtasParserMapping.SOURCE_OWN)) {</span>
<span class="fc" id="L505">                  token.setOffset(object.getOffsetStart(),</span>
<span class="fc" id="L506">                      object.getOffsetEnd());</span>
                  // use offset from ancestorGroup
<span class="fc" id="L508">                } else if (mapping.offset</span>
<span class="pc bpc" id="L509" title="1 of 2 branches missed.">                    .equals(MtasParserMapping.SOURCE_ANCESTOR_GROUP)</span>
<span class="nc bnc" id="L510" title="All 2 branches missed.">                    &amp;&amp; (!currentList.get(MAPPING_TYPE_GROUP).isEmpty())) {</span>
<span class="nc" id="L511">                  currentList.get(MAPPING_TYPE_GROUP)</span>
<span class="nc" id="L512">                      .get(currentList.get(MAPPING_TYPE_GROUP).size() - 1)</span>
<span class="nc" id="L513">                      .addUpdateableMappingWithOffset(token.getId());</span>
                  // use offset from ancestorWord
<span class="fc" id="L515">                } else if (mapping.offset</span>
<span class="fc bfc" id="L516" title="All 2 branches covered.">                    .equals(MtasParserMapping.SOURCE_ANCESTOR_WORD)</span>
<span class="pc bpc" id="L517" title="1 of 2 branches missed.">                    &amp;&amp; !currentList.get(MAPPING_TYPE_WORD).isEmpty()) {</span>
<span class="fc" id="L518">                  currentList.get(MAPPING_TYPE_WORD)</span>
<span class="fc" id="L519">                      .get(currentList.get(MAPPING_TYPE_WORD).size() - 1)</span>
<span class="fc" id="L520">                      .addUpdateableMappingWithOffset(token.getId());</span>
                  // use offset from ancestorRelation
<span class="fc" id="L522">                } else if (mapping.offset</span>
<span class="pc bpc" id="L523" title="1 of 2 branches missed.">                    .equals(MtasParserMapping.SOURCE_ANCESTOR_RELATION)</span>
<span class="nc bnc" id="L524" title="All 2 branches missed.">                    &amp;&amp; !currentList.get(MAPPING_TYPE_RELATION).isEmpty()) {</span>
<span class="nc" id="L525">                  currentList.get(MAPPING_TYPE_RELATION)</span>
<span class="nc" id="L526">                      .get(currentList.get(MAPPING_TYPE_RELATION).size() - 1)</span>
<span class="nc" id="L527">                      .addUpdateableMappingWithOffset(token.getId());</span>
                  // register id to get offset later from refs
<span class="fc" id="L529">                } else if (mapping.offset</span>
<span class="pc bpc" id="L530" title="1 of 2 branches missed.">                    .equals(MtasParserMapping.SOURCE_REFS)) {</span>
<span class="fc" id="L531">                  updateList.get(UPDATE_TYPE_OFFSET).put(token.getId(),</span>
<span class="fc" id="L532">                      object.getRefIds());</span>
                }
                // always use own realOffset
<span class="fc" id="L535">                token.setRealOffset(object.getRealOffsetStart(),</span>
<span class="fc" id="L536">                    object.getRealOffsetEnd());</span>
                // set payload
<span class="fc" id="L538">                token.setPayload(payload);</span>
                // add token to collection
<span class="fc" id="L540">                tokenCollection.add(token);</span>
              }
            }
          }
        }
        // register start and end
<span class="pc bpc" id="L546" title="3 of 4 branches missed.">        if (mapping.start != null &amp;&amp; mapping.end != null) {</span>
<span class="nc" id="L547">          String startAttribute = null;</span>
<span class="nc" id="L548">          String endAttribute = null;</span>
<span class="nc bnc" id="L549" title="All 2 branches missed.">          if (mapping.start.equals(&quot;#&quot;)) {</span>
<span class="nc" id="L550">            startAttribute = object.getId();</span>
          } else {
<span class="nc" id="L552">            startAttribute = object.getAttribute(mapping.start);</span>
<span class="nc bnc" id="L553" title="All 4 branches missed.">            if (startAttribute != null &amp;&amp; startAttribute.startsWith(&quot;#&quot;)) {</span>
<span class="nc" id="L554">              startAttribute = startAttribute.substring(1);</span>
            }
          }
<span class="nc bnc" id="L557" title="All 2 branches missed.">          if (mapping.end.equals(&quot;#&quot;)) {</span>
<span class="nc" id="L558">            endAttribute = object.getId();</span>
          } else {
<span class="nc" id="L560">            endAttribute = object.getAttribute(mapping.end);</span>
<span class="nc bnc" id="L561" title="All 4 branches missed.">            if (endAttribute != null &amp;&amp; endAttribute.startsWith(&quot;#&quot;)) {</span>
<span class="nc" id="L562">              endAttribute = endAttribute.substring(1);</span>
            }
          }
<span class="nc bnc" id="L565" title="All 4 branches missed.">          if (startAttribute != null &amp;&amp; endAttribute != null</span>
<span class="nc bnc" id="L566" title="All 2 branches missed.">              &amp;&amp; !object.getPositions().isEmpty()) {</span>
<span class="nc" id="L567">            object.setReferredStartPosition(startAttribute,</span>
<span class="nc" id="L568">                object.getPositions().first());</span>
<span class="nc" id="L569">            object.setReferredEndPosition(endAttribute,</span>
<span class="nc" id="L570">                object.getPositions().last());</span>
<span class="nc" id="L571">            object.setReferredStartOffset(startAttribute,</span>
<span class="nc" id="L572">                object.getOffsetStart());</span>
<span class="nc" id="L573">            object.setReferredEndOffset(endAttribute, object.getOffsetEnd());</span>
          }
        }
<span class="fc" id="L576">      } catch (MtasParserException e) {</span>
<span class="fc" id="L577">        log.debug(&quot;Rejected mapping &quot; + object.getType().getName(), e);</span>
        // ignore, no new token is created
<span class="fc" id="L579">      }</span>
<span class="fc" id="L580">    }</span>
    // copy remaining updateableMappings to new parent
<span class="fc bfc" id="L582" title="All 2 branches covered.">    if (!currentList.get(objectType.getType()).isEmpty()) {</span>
<span class="pc bpc" id="L583" title="1 of 2 branches missed.">      if (currentList.get(objectType.getType()).contains(object)) {</span>
<span class="nc" id="L584">        int listPosition = currentList.get(objectType.getType())</span>
<span class="nc" id="L585">            .indexOf(object);</span>
<span class="nc bnc" id="L586" title="All 2 branches missed.">        if (listPosition &gt; 0) {</span>
<span class="nc" id="L587">          currentList.get(objectType.getType()).get(listPosition - 1)</span>
<span class="nc" id="L588">              .registerUpdateableMappingsAtParent(</span>
<span class="nc" id="L589">                  object.getUpdateableMappingsAsParent());</span>
        }
<span class="nc" id="L591">      } else {</span>
<span class="fc" id="L592">        currentList.get(objectType.getType())</span>
<span class="fc" id="L593">            .get(currentList.get(objectType.getType()).size() - 1)</span>
<span class="fc" id="L594">            .registerUpdateableMappingsAtParent(</span>
<span class="fc" id="L595">                object.getUpdateableMappingsAsParent());</span>
      }
<span class="fc bfc" id="L597" title="All 2 branches covered.">    } else if (!currentList.get(MAPPING_TYPE_GROUP).isEmpty()) {</span>
<span class="fc" id="L598">      currentList.get(MAPPING_TYPE_GROUP)</span>
<span class="fc" id="L599">          .get(currentList.get(MAPPING_TYPE_GROUP).size() - 1)</span>
<span class="fc" id="L600">          .registerUpdateableMappingsAtParent(</span>
<span class="fc" id="L601">              object.getUpdateableMappingsAsParent());</span>
<span class="pc bpc" id="L602" title="1 of 2 branches missed.">    } else if (!currentList.get(MAPPING_TYPE_RELATION).isEmpty()) {</span>
<span class="nc" id="L603">      currentList.get(MAPPING_TYPE_RELATION)</span>
<span class="nc" id="L604">          .get(currentList.get(MAPPING_TYPE_RELATION).size() - 1)</span>
<span class="nc" id="L605">          .registerUpdateableMappingsAtParent(</span>
<span class="nc" id="L606">              object.getUpdateableMappingsAsParent());</span>
    }
<span class="fc" id="L608">    updateMappingsWithLocalReferences(object, currentList, updateList);</span>
<span class="fc" id="L609">  }</span>

  /**
   * Compute variables from object.
   *
   * @param object the object
   * @param currentList the current list
   * @param variables the variables
   */
  protected void computeVariablesFromObject(MtasParserObject object,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList,
      Map&lt;String, Map&lt;String, String&gt;&gt; variables) {
<span class="nc" id="L621">    MtasParserType&lt;MtasParserVariable&gt; parserType = object.getType();</span>
<span class="nc" id="L622">    String id = object.getId();</span>
<span class="nc bnc" id="L623" title="All 2 branches missed.">    if (id != null) {</span>
<span class="nc bnc" id="L624" title="All 2 branches missed.">      for (MtasParserVariable variable : parserType.getItems()) {</span>
<span class="nc bnc" id="L625" title="All 2 branches missed.">        if (!variables.containsKey(variable.variable)) {</span>
<span class="nc" id="L626">          variables.put(variable.variable, new HashMap&lt;String, String&gt;());</span>
        }
<span class="nc" id="L628">        StringBuilder builder = new StringBuilder();</span>
<span class="nc bnc" id="L629" title="All 2 branches missed.">        for (MtasParserVariableValue variableValue : variable.values) {</span>
<span class="nc bnc" id="L630" title="All 2 branches missed.">          if (variableValue.type.equals(&quot;attribute&quot;)) {</span>
<span class="nc" id="L631">            String subValue = object.getAttribute(variableValue.name);</span>
<span class="nc bnc" id="L632" title="All 2 branches missed.">            if (subValue != null) {</span>
<span class="nc" id="L633">              builder.append(subValue);</span>
            }
          }
<span class="nc" id="L636">        }</span>
<span class="nc" id="L637">        variables.get(variable.variable).put(id, builder.toString());</span>
<span class="nc" id="L638">      }</span>
    }
<span class="nc" id="L640">  }</span>

  /**
   * Check for variables.
   *
   * @param values the values
   * @return true, if successful
   */
  private boolean checkForVariables(List&lt;Map&lt;String, String&gt;&gt; values) {
<span class="pc bpc" id="L649" title="1 of 4 branches missed.">    if (values == null || values.isEmpty()) {</span>
<span class="fc" id="L650">      return false;</span>
    } else {
<span class="fc bfc" id="L652" title="All 2 branches covered.">      for (Map&lt;String, String&gt; list : values) {</span>
<span class="pc bpc" id="L653" title="1 of 2 branches missed.">        if (list.containsKey(&quot;type&quot;) &amp;&amp; list.get(&quot;type&quot;)</span>
<span class="pc bpc" id="L654" title="1 of 2 branches missed.">            .equals(MtasParserMapping.PARSER_TYPE_VARIABLE)) {</span>
<span class="nc" id="L655">          return true;</span>
        }
<span class="fc" id="L657">      }</span>
    }
<span class="fc" id="L659">    return false;</span>
  }

  /**
   * Update mappings with local references.
   *
   * @param currentObject the current object
   * @param currentList the current list
   * @param updateList the update list
   */
  private void updateMappingsWithLocalReferences(MtasParserObject currentObject,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList,
      Map&lt;String, Map&lt;Integer, Set&lt;String&gt;&gt;&gt; updateList) {
<span class="fc bfc" id="L672" title="All 2 branches covered.">    if (currentObject.getType().type.equals(MAPPING_TYPE_GROUP)) {</span>
      for (Integer tokenId : updateList
<span class="pc bpc" id="L674" title="1 of 2 branches missed.">          .get(UPDATE_TYPE_LOCAL_REF_POSITION_START).keySet()) {</span>
<span class="nc" id="L675">        if (updateList.get(UPDATE_TYPE_LOCAL_REF_POSITION_END)</span>
<span class="nc bnc" id="L676" title="All 2 branches missed.">            .containsKey(tokenId)</span>
<span class="nc" id="L677">            &amp;&amp; updateList.get(UPDATE_TYPE_LOCAL_REF_OFFSET_START)</span>
<span class="nc bnc" id="L678" title="All 2 branches missed.">                .containsKey(tokenId)</span>
<span class="nc" id="L679">            &amp;&amp; updateList.get(UPDATE_TYPE_LOCAL_REF_OFFSET_END)</span>
<span class="nc bnc" id="L680" title="All 2 branches missed.">                .containsKey(tokenId)) {</span>
<span class="nc" id="L681">          Iterator&lt;String&gt; startPositionIt = updateList</span>
<span class="nc" id="L682">              .get(UPDATE_TYPE_LOCAL_REF_POSITION_START).get(tokenId)</span>
<span class="nc" id="L683">              .iterator();</span>
<span class="nc" id="L684">          Iterator&lt;String&gt; endPositionIt = updateList</span>
<span class="nc" id="L685">              .get(UPDATE_TYPE_LOCAL_REF_POSITION_END).get(tokenId).iterator();</span>
<span class="nc" id="L686">          Iterator&lt;String&gt; startOffsetIt = updateList</span>
<span class="nc" id="L687">              .get(UPDATE_TYPE_LOCAL_REF_OFFSET_START).get(tokenId).iterator();</span>
<span class="nc" id="L688">          Iterator&lt;String&gt; endOffsetIt = updateList</span>
<span class="nc" id="L689">              .get(UPDATE_TYPE_LOCAL_REF_OFFSET_END).get(tokenId).iterator();</span>
<span class="nc" id="L690">          Integer startPosition = null;</span>
<span class="nc" id="L691">          Integer endPosition = null;</span>
<span class="nc" id="L692">          Integer startOffset = null;</span>
<span class="nc" id="L693">          Integer endOffset = null;</span>
<span class="nc" id="L694">          Integer newValue = null;</span>
<span class="nc bnc" id="L695" title="All 2 branches missed.">          while (startPositionIt.hasNext()) {</span>
<span class="nc" id="L696">            String localKey = startPositionIt.next();</span>
<span class="nc bnc" id="L697" title="All 2 branches missed.">            if (currentObject.referredStartPosition.containsKey(localKey)) {</span>
<span class="nc" id="L698">              newValue = currentObject.referredStartPosition.get(localKey);</span>
<span class="nc bnc" id="L699" title="All 2 branches missed.">              startPosition = (startPosition == null) ? newValue</span>
<span class="nc" id="L700">                  : Math.min(startPosition, newValue);</span>
            }
<span class="nc" id="L702">          }</span>
<span class="nc bnc" id="L703" title="All 2 branches missed.">          while (endPositionIt.hasNext()) {</span>
<span class="nc" id="L704">            String localKey = endPositionIt.next();</span>
<span class="nc bnc" id="L705" title="All 2 branches missed.">            if (currentObject.referredEndPosition.containsKey(localKey)) {</span>
<span class="nc" id="L706">              newValue = currentObject.referredEndPosition.get(localKey);</span>
<span class="nc bnc" id="L707" title="All 2 branches missed.">              endPosition = (endPosition == null) ? newValue</span>
<span class="nc" id="L708">                  : Math.max(endPosition, newValue);</span>
            }
<span class="nc" id="L710">          }</span>
<span class="nc bnc" id="L711" title="All 2 branches missed.">          while (startOffsetIt.hasNext()) {</span>
<span class="nc" id="L712">            String localKey = startOffsetIt.next();</span>
<span class="nc bnc" id="L713" title="All 2 branches missed.">            if (currentObject.referredStartOffset.containsKey(localKey)) {</span>
<span class="nc" id="L714">              newValue = currentObject.referredStartOffset.get(localKey);</span>
<span class="nc bnc" id="L715" title="All 2 branches missed.">              startOffset = (startOffset == null) ? newValue</span>
<span class="nc" id="L716">                  : Math.min(startOffset, newValue);</span>
            }
<span class="nc" id="L718">          }</span>
<span class="nc bnc" id="L719" title="All 2 branches missed.">          while (endOffsetIt.hasNext()) {</span>
<span class="nc" id="L720">            String localKey = endOffsetIt.next();</span>
<span class="nc bnc" id="L721" title="All 2 branches missed.">            if (currentObject.referredEndOffset.containsKey(localKey)) {</span>
<span class="nc" id="L722">              newValue = currentObject.referredEndOffset.get(localKey);</span>
<span class="nc bnc" id="L723" title="All 2 branches missed.">              endOffset = (endOffset == null) ? newValue</span>
<span class="nc" id="L724">                  : Math.max(endOffset, newValue);</span>
            }
<span class="nc" id="L726">          }</span>
<span class="nc bnc" id="L727" title="All 8 branches missed.">          if (startPosition != null &amp;&amp; endPosition != null</span>
              &amp;&amp; startOffset != null &amp;&amp; endOffset != null) {
<span class="nc" id="L729">            MtasToken token = tokenCollection.get(tokenId);</span>
<span class="nc" id="L730">            token.addPositionRange(startPosition, endPosition);</span>
<span class="nc" id="L731">            token.setOffset(startOffset, endOffset);</span>
          }
        }
<span class="nc" id="L734">      }</span>

    }
<span class="fc bfc" id="L737" title="All 2 branches covered.">    if (!currentList.get(MAPPING_TYPE_GROUP).isEmpty()) {</span>
<span class="fc" id="L738">      MtasParserObject parentGroup = currentList.get(MAPPING_TYPE_GROUP)</span>
<span class="fc" id="L739">          .get(currentList.get(MAPPING_TYPE_GROUP).size() - 1);</span>
<span class="fc" id="L740">      parentGroup.referredStartPosition</span>
<span class="fc" id="L741">          .putAll(currentObject.referredStartPosition);</span>
<span class="fc" id="L742">      parentGroup.referredEndPosition.putAll(currentObject.referredEndPosition);</span>
<span class="fc" id="L743">      parentGroup.referredStartOffset.putAll(currentObject.referredStartOffset);</span>
<span class="fc" id="L744">      parentGroup.referredEndOffset.putAll(currentObject.referredEndOffset);</span>
    }
<span class="fc" id="L746">    currentObject.referredStartPosition.clear();</span>
<span class="fc" id="L747">    currentObject.referredEndPosition.clear();</span>
<span class="fc" id="L748">    currentObject.referredStartOffset.clear();</span>
<span class="fc" id="L749">    currentObject.referredEndOffset.clear();</span>
<span class="fc" id="L750">  }</span>

  /**
   * Compute type from mapping source.
   *
   * @param source the source
   * @return the string
   * @throws MtasParserException the mtas parser exception
   */
  private String computeTypeFromMappingSource(String source)
      throws MtasParserException {
<span class="pc bpc" id="L761" title="1 of 2 branches missed.">    if (source.equals(MtasParserMapping.SOURCE_OWN)) {</span>
<span class="nc" id="L762">      return null;</span>
<span class="pc bpc" id="L763" title="1 of 2 branches missed.">    } else if (source.equals(MtasParserMapping.SOURCE_ANCESTOR_GROUP)) {</span>
<span class="nc" id="L764">      return MAPPING_TYPE_GROUP;</span>
<span class="fc" id="L765">    } else if (source</span>
<span class="pc bpc" id="L766" title="1 of 2 branches missed.">        .equals(MtasParserMapping.SOURCE_ANCESTOR_GROUP_ANNOTATION)) {</span>
<span class="nc" id="L767">      return MAPPING_TYPE_GROUP_ANNOTATION;</span>
<span class="fc bfc" id="L768" title="All 2 branches covered.">    } else if (source.equals(MtasParserMapping.SOURCE_ANCESTOR_WORD)) {</span>
<span class="fc" id="L769">      return MAPPING_TYPE_WORD;</span>
<span class="fc" id="L770">    } else if (source</span>
<span class="fc bfc" id="L771" title="All 2 branches covered.">        .equals(MtasParserMapping.SOURCE_ANCESTOR_WORD_ANNOTATION)) {</span>
<span class="fc" id="L772">      return MAPPING_TYPE_WORD_ANNOTATION;</span>
<span class="pc bpc" id="L773" title="1 of 2 branches missed.">    } else if (source.equals(MtasParserMapping.SOURCE_ANCESTOR_RELATION)) {</span>
<span class="fc" id="L774">      return MAPPING_TYPE_RELATION;</span>
<span class="nc" id="L775">    } else if (source</span>
<span class="nc bnc" id="L776" title="All 2 branches missed.">        .equals(MtasParserMapping.SOURCE_ANCESTOR_RELATION_ANNOTATION)) {</span>
<span class="nc" id="L777">      return MAPPING_TYPE_RELATION_ANNOTATION;</span>
    } else {
<span class="nc" id="L779">      throw new MtasParserException(&quot;unknown source &quot; + source);</span>
    }
  }

  /**
   * Compute object from mapping value.
   *
   * @param object the object
   * @param mappingValue the mapping value
   * @param currentList the current list
   * @return the mtas parser object[]
   * @throws MtasParserException the mtas parser exception
   */
  private MtasParserObject[] computeObjectFromMappingValue(
      MtasParserObject object, Map&lt;String, String&gt; mappingValue,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList)
      throws MtasParserException {
<span class="fc" id="L796">    MtasParserObject[] checkObjects = null;</span>
    MtasParserObject checkObject;
<span class="fc" id="L798">    Integer ancestorNumber = null;</span>
<span class="fc" id="L799">    String ancestorType = null;</span>
    // try to get relevant object
<span class="fc" id="L801">    if (mappingValue.get(MAPPING_VALUE_SOURCE)</span>
<span class="fc bfc" id="L802" title="All 2 branches covered.">        .equals(MtasParserMapping.SOURCE_OWN)) {</span>
<span class="fc" id="L803">      checkObjects = new MtasParserObject[] { object };</span>
    } else {
<span class="fc bfc" id="L805" title="All 2 branches covered.">      ancestorNumber = mappingValue.get(MAPPING_VALUE_ANCESTOR) != null</span>
<span class="fc" id="L806">          ? Integer.parseInt(mappingValue.get(MAPPING_VALUE_ANCESTOR)) : null;</span>
<span class="fc" id="L807">      ancestorType = computeTypeFromMappingSource(</span>
<span class="fc" id="L808">          mappingValue.get(MAPPING_VALUE_SOURCE));</span>
      // get ancestor object
<span class="pc bpc" id="L810" title="1 of 2 branches missed.">      if (ancestorType != null) {</span>
<span class="fc" id="L811">        int s = currentList.get(ancestorType).size();</span>
        // check existence ancestor for conditions
<span class="fc bfc" id="L813" title="All 2 branches covered.">        if (ancestorNumber != null) {</span>
<span class="pc bpc" id="L814" title="1 of 4 branches missed.">          if ((s &gt; 0) &amp;&amp; (ancestorNumber &lt; s) &amp;&amp; (checkObject = currentList</span>
<span class="pc bpc" id="L815" title="1 of 2 branches missed.">              .get(ancestorType).get((s - ancestorNumber - 1))) != null) {</span>
<span class="fc" id="L816">            checkObjects = new MtasParserObject[] { checkObject };</span>
          }
        } else {
<span class="fc" id="L819">          checkObjects = new MtasParserObject[s];</span>
<span class="fc bfc" id="L820" title="All 2 branches covered.">          for (int i = s - 1; i &gt;= 0; i--) {</span>
<span class="fc" id="L821">            checkObjects[s - i - 1] = currentList.get(ancestorType).get(i);</span>
          }
        }
      }
    }
<span class="fc" id="L826">    return checkObjects;</span>
  }

  /**
   * Compute value from mapping values.
   *
   * @param object the object
   * @param mappingValues the mapping values
   * @param currentList the current list
   * @param containsVariables the contains variables
   * @return the string[]
   * @throws MtasParserException the mtas parser exception
   * @throws MtasConfigException the mtas config exception
   */
  private String[] computeValueFromMappingValues(MtasParserObject object,
      List&lt;Map&lt;String, String&gt;&gt; mappingValues,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList,
      boolean containsVariables)
      throws MtasParserException, MtasConfigException {
<span class="fc" id="L845">    String[] value = { &quot;&quot; };</span>
<span class="fc bfc" id="L846" title="All 2 branches covered.">    for (Map&lt;String, String&gt; mappingValue : mappingValues) {</span>
      // directly
<span class="fc" id="L848">      if (mappingValue.get(MAPPING_VALUE_SOURCE)</span>
<span class="fc bfc" id="L849" title="All 2 branches covered.">          .equals(MtasParserMapping.SOURCE_STRING)) {</span>
<span class="fc" id="L850">        if (mappingValue.get(&quot;type&quot;)</span>
<span class="pc bpc" id="L851" title="1 of 2 branches missed.">            .equals(MtasParserMapping.PARSER_TYPE_STRING)) {</span>
<span class="fc" id="L852">          String subvalue = computeFilteredPrefixedValue(</span>
<span class="fc" id="L853">              mappingValue.get(MAPPING_VALUE_TYPE),</span>
<span class="fc" id="L854">              mappingValue.get(MAPPING_VALUE_TEXT), null, null);</span>
<span class="pc bpc" id="L855" title="1 of 2 branches missed.">          if (subvalue != null) {</span>
<span class="fc bfc" id="L856" title="All 2 branches covered.">            for (int i = 0; i &lt; value.length; i++) {</span>
<span class="fc" id="L857">              value[i] = addAndEncodeValue(value[i], subvalue,</span>
                  containsVariables);
            }
          }
<span class="fc" id="L861">        }</span>
        // from objects
      } else {
<span class="fc" id="L864">        MtasParserObject[] checkObjects = computeObjectFromMappingValue(object,</span>
            mappingValue, currentList);
        // create value
<span class="pc bpc" id="L867" title="2 of 4 branches missed.">        if (checkObjects != null &amp;&amp; checkObjects.length &gt; 0) {</span>
<span class="fc" id="L868">          MtasParserType checkType = checkObjects[0].getType();</span>
          // add name to value
<span class="fc" id="L870">          if (mappingValue.get(MAPPING_VALUE_TYPE)</span>
<span class="fc bfc" id="L871" title="All 2 branches covered.">              .equals(MtasParserMapping.PARSER_TYPE_NAME)) {</span>
<span class="fc" id="L872">            String subvalue = computeFilteredPrefixedValue(</span>
<span class="fc" id="L873">                mappingValue.get(MAPPING_VALUE_TYPE), checkType.getName(),</span>
<span class="fc" id="L874">                mappingValue.get(MAPPING_VALUE_FILTER),</span>
<span class="fc bfc" id="L875" title="All 2 branches covered.">                mappingValue.get(MAPPING_VALUE_PREFIX) == null</span>
<span class="pc bpc" id="L876" title="1 of 2 branches missed.">                    || mappingValue.get(MAPPING_VALUE_PREFIX).isEmpty() ? null</span>
<span class="fc" id="L877">                        : mappingValue.get(MAPPING_VALUE_PREFIX));</span>
<span class="pc bpc" id="L878" title="1 of 2 branches missed.">            if (subvalue != null) {</span>
<span class="fc bfc" id="L879" title="All 2 branches covered.">              for (int i = 0; i &lt; value.length; i++) {</span>
<span class="fc" id="L880">                value[i] = addAndEncodeValue(value[i], subvalue,</span>
                    containsVariables);
              }
            }
            // add attribute to value
<span class="fc" id="L885">          } else if (mappingValue.get(MAPPING_VALUE_TYPE)</span>
<span class="fc bfc" id="L886" title="All 2 branches covered.">              .equals(MtasParserMapping.PARSER_TYPE_ATTRIBUTE)) {</span>
<span class="fc" id="L887">            String tmpValue = null;</span>
<span class="pc bpc" id="L888" title="1 of 2 branches missed.">            if (mappingValue.get(MAPPING_VALUE_NAME).equals(&quot;#&quot;)) {</span>
<span class="nc" id="L889">              tmpValue = checkObjects[0].getId();</span>
            } else {
<span class="fc" id="L891">              tmpValue = checkObjects[0]</span>
<span class="fc" id="L892">                  .getAttribute(mappingValue.get(MAPPING_VALUE_NAME));</span>
            }
<span class="fc" id="L894">            String subvalue = computeFilteredPrefixedValue(</span>
<span class="fc" id="L895">                mappingValue.get(MAPPING_VALUE_TYPE), tmpValue,</span>
<span class="fc" id="L896">                mappingValue.get(MAPPING_VALUE_FILTER),</span>
<span class="fc bfc" id="L897" title="All 2 branches covered.">                mappingValue.get(MAPPING_VALUE_PREFIX) == null</span>
<span class="pc bpc" id="L898" title="1 of 2 branches missed.">                    || mappingValue.get(MAPPING_VALUE_PREFIX).isEmpty() ? null</span>
<span class="fc" id="L899">                        : mappingValue.get(MAPPING_VALUE_PREFIX));</span>
<span class="fc bfc" id="L900" title="All 2 branches covered.">            if (subvalue != null) {</span>
<span class="fc bfc" id="L901" title="All 2 branches covered.">              for (int i = 0; i &lt; value.length; i++) {</span>
<span class="fc" id="L902">                value[i] = addAndEncodeValue(value[i], subvalue,</span>
                    containsVariables);
              }
            }
            // value from text
<span class="fc" id="L907">          } else if (mappingValue.get(&quot;type&quot;)</span>
<span class="pc bpc" id="L908" title="1 of 2 branches missed.">              .equals(MtasParserMapping.PARSER_TYPE_TEXT)) {</span>
<span class="fc" id="L909">            String subvalue = computeFilteredPrefixedValue(</span>
<span class="fc" id="L910">                mappingValue.get(MAPPING_VALUE_TYPE), checkObjects[0].getText(),</span>
<span class="fc" id="L911">                mappingValue.get(MAPPING_VALUE_FILTER),</span>
<span class="pc bpc" id="L912" title="1 of 2 branches missed.">                mappingValue.get(MAPPING_VALUE_PREFIX) == null</span>
<span class="pc bnc" id="L913" title="All 2 branches missed.">                    || mappingValue.get(MAPPING_VALUE_PREFIX).isEmpty() ? null</span>
<span class="nc" id="L914">                        : mappingValue.get(MAPPING_VALUE_PREFIX));</span>
<span class="pc bpc" id="L915" title="1 of 2 branches missed.">            if (subvalue != null) {</span>
<span class="fc bfc" id="L916" title="All 2 branches covered.">              for (int i = 0; i &lt; value.length; i++) {</span>
<span class="fc" id="L917">                value[i] = addAndEncodeValue(value[i], subvalue,</span>
                    containsVariables);
              }
            }
<span class="pc" id="L921">          } else if (mappingValue.get(&quot;type&quot;)</span>
<span class="nc bnc" id="L922" title="All 2 branches missed.">              .equals(MtasParserMapping.PARSER_TYPE_TEXT_SPLIT)) {</span>
<span class="nc" id="L923">            String[] textValues = checkObjects[0].getText()</span>
<span class="nc" id="L924">                .split(Pattern.quote(mappingValue.get(MAPPING_VALUE_SPLIT)));</span>
<span class="nc" id="L925">            textValues = computeFilteredSplitValues(textValues,</span>
<span class="nc" id="L926">                mappingValue.get(MAPPING_VALUE_FILTER));</span>
<span class="nc bnc" id="L927" title="All 4 branches missed.">            if (textValues != null &amp;&amp; textValues.length &gt; 0) {</span>
<span class="nc" id="L928">              String[] nextValue = new String[value.length * textValues.length];</span>
<span class="nc" id="L929">              boolean nullValue = false;</span>
<span class="nc" id="L930">              int number = 0;</span>
<span class="nc bnc" id="L931" title="All 2 branches missed.">              for (int k = 0; k &lt; textValues.length; k++) {</span>
<span class="nc" id="L932">                String subvalue = computeFilteredPrefixedValue(</span>
<span class="nc" id="L933">                    mappingValue.get(MAPPING_VALUE_TYPE), textValues[k],</span>
<span class="nc" id="L934">                    mappingValue.get(MAPPING_VALUE_FILTER),</span>
<span class="nc bnc" id="L935" title="All 2 branches missed.">                    mappingValue.get(MAPPING_VALUE_PREFIX) == null</span>
<span class="nc bnc" id="L936" title="All 2 branches missed.">                        || mappingValue.get(MAPPING_VALUE_PREFIX).isEmpty()</span>
<span class="nc" id="L937">                            ? null : mappingValue.get(MAPPING_VALUE_PREFIX));</span>
<span class="nc bnc" id="L938" title="All 2 branches missed.">                if (subvalue != null) {</span>
<span class="nc bnc" id="L939" title="All 2 branches missed.">                  for (int i = 0; i &lt; value.length; i++) {</span>
<span class="nc" id="L940">                    nextValue[number] = addAndEncodeValue(value[i], subvalue,</span>
                        containsVariables);
<span class="nc" id="L942">                    number++;</span>
                  }
<span class="nc bnc" id="L944" title="All 2 branches missed.">                } else if (!nullValue) {</span>
<span class="nc bnc" id="L945" title="All 2 branches missed.">                  for (int i = 0; i &lt; value.length; i++) {</span>
<span class="nc" id="L946">                    nextValue[number] = value[i];</span>
<span class="nc" id="L947">                    number++;</span>
                  }
<span class="nc" id="L949">                  nullValue = true;</span>
                }
              }
<span class="nc" id="L952">              value = new String[number];</span>
<span class="nc" id="L953">              System.arraycopy(nextValue, 0, value, 0, number);</span>
            }
<span class="nc" id="L955">          } else if (mappingValue.get(&quot;type&quot;)</span>
<span class="nc bnc" id="L956" title="All 2 branches missed.">              .equals(MtasParserMapping.PARSER_TYPE_VARIABLE)) {</span>
<span class="nc bnc" id="L957" title="All 2 branches missed.">            if (containsVariables) {</span>
<span class="nc" id="L958">              String variableName = mappingValue.get(MAPPING_VALUE_NAME);</span>
<span class="nc" id="L959">              String variableValue = mappingValue.get(MAPPING_VALUE_VALUE);</span>
<span class="nc" id="L960">              String prefix = mappingValue.get(MAPPING_VALUE_PREFIX);</span>
<span class="nc bnc" id="L961" title="All 4 branches missed.">              if (variableName != null &amp;&amp; variableValue != null</span>
<span class="nc" id="L962">                  &amp;&amp; mappingValue.get(MAPPING_VALUE_SOURCE)</span>
<span class="nc bnc" id="L963" title="All 2 branches missed.">                      .equals(MtasParserMapping.SOURCE_OWN)) {</span>
<span class="nc" id="L964">                String subvalue = object.getAttribute(variableValue);</span>
<span class="nc bnc" id="L965" title="All 4 branches missed.">                if (subvalue != null &amp;&amp; subvalue.startsWith(&quot;#&quot;)) {</span>
<span class="nc" id="L966">                  subvalue = subvalue.substring(1);</span>
                }
<span class="nc bnc" id="L968" title="All 2 branches missed.">                if (subvalue != null) {</span>
<span class="nc bnc" id="L969" title="All 2 branches missed.">                  for (int i = 0; i &lt; value.length; i++) {</span>
<span class="nc bnc" id="L970" title="All 4 branches missed.">                    if (prefix != null &amp;&amp; !prefix.isEmpty()) {</span>
<span class="nc" id="L971">                      value[i] = addAndEncodeValue(value[i], prefix,</span>
                          containsVariables);
                    }
<span class="nc" id="L974">                    value[i] = addAndEncodeVariable(value[i], variableName,</span>
                        subvalue, containsVariables);
                  }
                }
              }
<span class="nc" id="L979">            } else {</span>
<span class="nc" id="L980">              throw new MtasParserException(&quot;unexpected variable&quot;);</span>
            }
          } else {
<span class="nc" id="L983">            throw new MtasParserException(</span>
<span class="nc" id="L984">                &quot;unknown type &quot; + mappingValue.get(&quot;type&quot;));</span>
          }
        }
      }
<span class="fc" id="L988">    }</span>
<span class="pc bpc" id="L989" title="1 of 4 branches missed.">    if (value.length == 1 &amp;&amp; value[0].isEmpty()) {</span>
<span class="fc" id="L990">      return new String[] {};</span>
    } else {
<span class="fc" id="L992">      return value;</span>
    }
  }

  /**
   * Adds the and encode variable.
   *
   * @param originalValue the original value
   * @param newVariable the new variable
   * @param newVariableName the new variable name
   * @param encode the encode
   * @return the string
   */
  private String addAndEncodeVariable(String originalValue, String newVariable,
      String newVariableName, boolean encode) {
<span class="nc" id="L1007">    return addAndEncode(originalValue, newVariable, newVariableName, encode);</span>
  }

  /**
   * Adds the and encode value.
   *
   * @param originalValue the original value
   * @param newValue the new value
   * @param encode the encode
   * @return the string
   */
  private String addAndEncodeValue(String originalValue, String newValue,
      boolean encode) {
<span class="fc" id="L1020">    return addAndEncode(originalValue, null, newValue, encode);</span>
  }

  /**
   * Adds the and encode.
   *
   * @param originalValue the original value
   * @param newType the new type
   * @param newValue the new value
   * @param encode the encode
   * @return the string
   */
  private String addAndEncode(String originalValue, String newType,
      String newValue, boolean encode) {
<span class="pc bpc" id="L1034" title="1 of 2 branches missed.">    if (newValue == null) {</span>
<span class="nc" id="L1035">      return originalValue;</span>
    } else {
      String finalNewValue;
<span class="pc bpc" id="L1038" title="1 of 2 branches missed.">      if (encode) {</span>
<span class="nc bnc" id="L1039" title="All 2 branches missed.">        if (newType == null) {</span>
<span class="nc" id="L1040">          finalNewValue = new String(</span>
<span class="nc" id="L1041">              enc.encode(newValue.getBytes(StandardCharsets.UTF_8)),</span>
              StandardCharsets.UTF_8);
        } else {
<span class="nc" id="L1044">          finalNewValue = new String(</span>
<span class="nc" id="L1045">              enc.encode(newType.getBytes(StandardCharsets.UTF_8)),</span>
              StandardCharsets.UTF_8)
              + &quot;:&quot;
              + new String(
<span class="nc" id="L1049">                  enc.encode(newValue.getBytes(StandardCharsets.UTF_8)),</span>
                  StandardCharsets.UTF_8);
        }
      } else {
<span class="fc" id="L1053">        finalNewValue = newValue;</span>
      }
<span class="pc bpc" id="L1055" title="1 of 4 branches missed.">      if (originalValue == null || originalValue.isEmpty()) {</span>
<span class="fc" id="L1056">        return finalNewValue;</span>
      } else {
<span class="pc bpc" id="L1058" title="1 of 2 branches missed.">        return originalValue + (encode ? &quot; &quot; : &quot;&quot;) + finalNewValue;</span>
      }
    }
  }

  /**
   * Decode and update with variables.
   *
   * @param encodedPrefix the encoded prefix
   * @param encodedPostfix the encoded postfix
   * @param variables the variables
   * @return the string
   */
  protected String decodeAndUpdateWithVariables(String encodedPrefix,
      String encodedPostfix, Map&lt;String, Map&lt;String, String&gt;&gt; variables) {
    String[] prefixSplit;
    String[] postfixSplit;
<span class="nc bnc" id="L1075" title="All 4 branches missed.">    if (encodedPrefix != null &amp;&amp; !encodedPrefix.isEmpty()) {</span>
<span class="nc" id="L1076">      prefixSplit = encodedPrefix.split(&quot; &quot;);</span>
    } else {
<span class="nc" id="L1078">      prefixSplit = new String[0];</span>
    }
<span class="nc bnc" id="L1080" title="All 4 branches missed.">    if (encodedPostfix != null &amp;&amp; !encodedPostfix.isEmpty()) {</span>
<span class="nc" id="L1081">      postfixSplit = encodedPostfix.split(&quot; &quot;);</span>
    } else {
<span class="nc" id="L1083">      postfixSplit = new String[0];</span>
    }
    try {
<span class="nc" id="L1086">      String prefix = decodeAndUpdateWithVariables(prefixSplit, variables);</span>
<span class="nc" id="L1087">      String postfix = decodeAndUpdateWithVariables(postfixSplit, variables);</span>
<span class="nc" id="L1088">      return prefix + MtasToken.DELIMITER + postfix;</span>
<span class="nc" id="L1089">    } catch (MtasParserException e) {</span>
<span class="nc" id="L1090">      log.debug(e);</span>
<span class="nc" id="L1091">      return null;</span>
    }
  }

  /**
   * Decode and update with variables.
   *
   * @param splitList the split list
   * @param variables the variables
   * @return the string
   * @throws MtasParserException the mtas parser exception
   */
  private String decodeAndUpdateWithVariables(String[] splitList,
      Map&lt;String, Map&lt;String, String&gt;&gt; variables) throws MtasParserException {
<span class="nc" id="L1105">    StringBuilder builder = new StringBuilder();</span>
<span class="nc bnc" id="L1106" title="All 2 branches missed.">    for (String split : splitList) {</span>
<span class="nc bnc" id="L1107" title="All 2 branches missed.">      if (split.contains(&quot;:&quot;)) {</span>
<span class="nc" id="L1108">        String[] subSplit = split.split(&quot;:&quot;);</span>
<span class="nc bnc" id="L1109" title="All 2 branches missed.">        if (subSplit.length == 2) {</span>
<span class="nc" id="L1110">          String decodedVariableName = new String(dec.decode(subSplit[0]),</span>
              StandardCharsets.UTF_8);
<span class="nc" id="L1112">          String decodedVariableValue = new String(dec.decode(subSplit[1]),</span>
              StandardCharsets.UTF_8);
<span class="nc bnc" id="L1114" title="All 2 branches missed.">          if (variables.containsKey(decodedVariableName)) {</span>
<span class="nc" id="L1115">            if (variables.get(decodedVariableName)</span>
<span class="nc bnc" id="L1116" title="All 2 branches missed.">                .containsKey(decodedVariableValue)) {</span>
<span class="nc" id="L1117">              String valueFromVariable = variables.get(decodedVariableName)</span>
<span class="nc" id="L1118">                  .get(decodedVariableValue);</span>
<span class="nc" id="L1119">              builder.append(valueFromVariable);</span>
<span class="nc" id="L1120">            } else {</span>
<span class="nc" id="L1121">              throw new MtasParserException(&quot;id &quot; + decodedVariableValue</span>
                  + &quot; not found in &quot; + decodedVariableName);
            }
          } else {
<span class="nc" id="L1125">            throw new MtasParserException(</span>
                &quot;variable &quot; + decodedVariableName + &quot; unknown&quot;);
          }
        }
<span class="nc" id="L1129">      } else {</span>
        try {
<span class="nc" id="L1131">          builder.append(new String(dec.decode(split), StandardCharsets.UTF_8));</span>
<span class="nc" id="L1132">        } catch (IllegalArgumentException e) {</span>
<span class="nc" id="L1133">          log.info(e);</span>
<span class="nc" id="L1134">        }</span>
      }
    }
<span class="nc" id="L1137">    return builder.toString();</span>
  }

  /**
   * Compute payload from mapping payload.
   *
   * @param object the object
   * @param mappingPayloads the mapping payloads
   * @param currentList the current list
   * @return the bytes ref
   * @throws MtasParserException the mtas parser exception
   */
  private BytesRef computePayloadFromMappingPayload(MtasParserObject object,
      List&lt;Map&lt;String, String&gt;&gt; mappingPayloads,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList)
      throws MtasParserException {
<span class="fc" id="L1153">    BytesRef payload = null;</span>
<span class="fc bfc" id="L1154" title="All 2 branches covered.">    for (Map&lt;String, String&gt; mappingPayload : mappingPayloads) {</span>
<span class="fc" id="L1155">      if (mappingPayload.get(MAPPING_VALUE_SOURCE)</span>
<span class="pc bpc" id="L1156" title="1 of 2 branches missed.">          .equals(MtasParserMapping.SOURCE_STRING)) {</span>
<span class="nc" id="L1157">        if (mappingPayload.get(MAPPING_VALUE_TYPE)</span>
<span class="nc bnc" id="L1158" title="All 2 branches missed.">            .equals(MtasParserMapping.PARSER_TYPE_STRING)</span>
<span class="nc bnc" id="L1159" title="All 2 branches missed.">            &amp;&amp; mappingPayload.get(MAPPING_VALUE_TEXT) != null) {</span>
<span class="nc" id="L1160">          BytesRef subpayload = computeMaximumFilteredPayload(</span>
<span class="nc" id="L1161">              mappingPayload.get(MAPPING_VALUE_TEXT), payload, null);</span>
<span class="nc bnc" id="L1162" title="All 2 branches missed.">          payload = (subpayload != null) ? subpayload : payload;</span>
<span class="nc" id="L1163">        }</span>
        // from objects
      } else {
<span class="fc" id="L1166">        MtasParserObject[] checkObjects = computeObjectFromMappingValue(object,</span>
            mappingPayload, currentList);
        // do checks and updates
<span class="pc bpc" id="L1169" title="1 of 2 branches missed.">        if (checkObjects != null) {</span>
          // payload from attribute
<span class="fc" id="L1171">          if (mappingPayload.get(&quot;type&quot;)</span>
<span class="pc bpc" id="L1172" title="1 of 2 branches missed.">              .equals(MtasParserMapping.PARSER_TYPE_ATTRIBUTE)) {</span>
<span class="fc" id="L1173">            BytesRef subpayload = computeMaximumFilteredPayload(</span>
<span class="fc" id="L1174">                checkObjects[0].getAttribute(mappingPayload.get(&quot;name&quot;)),</span>
<span class="fc" id="L1175">                payload, mappingPayload.get(MAPPING_VALUE_FILTER));</span>
<span class="fc bfc" id="L1176" title="All 2 branches covered.">            payload = (subpayload != null) ? subpayload : payload;</span>
            // payload from text
<span class="pc" id="L1178">          } else if (mappingPayload.get(&quot;type&quot;)</span>
<span class="nc bnc" id="L1179" title="All 2 branches missed.">              .equals(MtasParserMapping.PARSER_TYPE_TEXT)) {</span>
<span class="nc" id="L1180">            BytesRef subpayload = computeMaximumFilteredPayload(</span>
<span class="nc" id="L1181">                object.getText(), payload,</span>
<span class="nc" id="L1182">                mappingPayload.get(MAPPING_VALUE_FILTER));</span>
<span class="nc bnc" id="L1183" title="All 2 branches missed.">            payload = (subpayload != null) ? subpayload : payload;</span>
          }
        }
      }
<span class="fc" id="L1187">    }</span>
<span class="fc" id="L1188">    return payload;</span>
  }

  /**
   * Prevalidate object.
   *
   * @param object the object
   * @param currentList the current list
   * @return the boolean
   */
  Boolean prevalidateObject(MtasParserObject object,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList) {
<span class="fc" id="L1200">    MtasParserType objectType = object.getType();</span>
<span class="fc" id="L1201">    List&lt;MtasParserMapping&lt;?&gt;&gt; mappings = objectType.getItems();</span>
<span class="fc bfc" id="L1202" title="All 2 branches covered.">    if (mappings.isEmpty()) {</span>
<span class="fc" id="L1203">      return true;</span>
    }
<span class="fc bfc" id="L1205" title="All 2 branches covered.">    for (MtasParserMapping&lt;?&gt; mapping : mappings) {</span>
      try {
<span class="fc" id="L1207">        precheckMappingConditions(object, mapping.getConditions(), currentList);</span>
<span class="fc" id="L1208">        return true;</span>
<span class="fc" id="L1209">      } catch (MtasParserException e) {</span>
<span class="fc" id="L1210">        log.debug(e);</span>
      }
<span class="fc" id="L1212">    }</span>
<span class="fc" id="L1213">    return false;</span>
  }

  /**
   * Precheck mapping conditions.
   *
   * @param object the object
   * @param mappingConditions the mapping conditions
   * @param currentList the current list
   * @throws MtasParserException the mtas parser exception
   */
  void precheckMappingConditions(MtasParserObject object,
      List&lt;Map&lt;String, String&gt;&gt; mappingConditions,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList)
      throws MtasParserException {
<span class="fc bfc" id="L1228" title="All 2 branches covered.">    for (Map&lt;String, String&gt; mappingCondition : mappingConditions) {</span>
      // condition existence ancestor
<span class="fc" id="L1230">      if (mappingCondition.get(&quot;type&quot;)</span>
<span class="fc bfc" id="L1231" title="All 2 branches covered.">          .equals(MtasParserMapping.PARSER_TYPE_EXISTENCE)) {</span>
<span class="fc" id="L1232">        int number = 0;</span>
        try {
<span class="fc" id="L1234">          number = Integer.parseInt(mappingCondition.get(&quot;number&quot;));</span>
<span class="nc" id="L1235">        } catch (Exception e) {</span>
<span class="nc" id="L1236">          log.debug(e);</span>
<span class="fc" id="L1237">        }</span>
<span class="fc" id="L1238">        String type = computeTypeFromMappingSource(</span>
<span class="fc" id="L1239">            mappingCondition.get(MAPPING_VALUE_SOURCE));</span>
<span class="fc bfc" id="L1240" title="All 2 branches covered.">        if (number != currentList.get(type).size()) {</span>
<span class="fc" id="L1241">          throw new MtasParserException(</span>
              &quot;condition mapping is &quot; + number + &quot; ancestors of &quot; + type
<span class="fc" id="L1243">                  + &quot; (but &quot; + currentList.get(type).size() + &quot; found)&quot;);</span>
        }
        // condition unknown ancestors
<span class="fc" id="L1246">      } else if (mappingCondition.get(&quot;type&quot;)</span>
<span class="fc bfc" id="L1247" title="All 2 branches covered.">          .equals(MtasParserMapping.PARSER_TYPE_UNKNOWN_ANCESTOR)) {</span>
<span class="fc" id="L1248">        int number = 0;</span>
        try {
<span class="fc" id="L1250">          number = Integer.parseInt(mappingCondition.get(&quot;number&quot;));</span>
<span class="nc" id="L1251">        } catch (Exception e) {</span>
<span class="nc" id="L1252">          log.debug(e);</span>
<span class="fc" id="L1253">        }</span>
<span class="fc bfc" id="L1254" title="All 2 branches covered.">        if (number != object.getUnknownAncestorNumber()) {</span>
<span class="fc" id="L1255">          throw new MtasParserException(</span>
              &quot;condition mapping is &quot; + number + &quot; unknown ancestors (but &quot;
<span class="fc" id="L1257">                  + object.getUnknownAncestorNumber() + &quot; found)&quot;);</span>
        }
<span class="fc" id="L1259">      } else {</span>
<span class="fc" id="L1260">        MtasParserObject[] checkObjects = computeObjectFromMappingValue(object,</span>
            mappingCondition, currentList);
<span class="fc" id="L1262">        Boolean notCondition = false;</span>
<span class="fc bfc" id="L1263" title="All 2 branches covered.">        if (mappingCondition.get(&quot;not&quot;) != null) {</span>
<span class="fc" id="L1264">          notCondition = true;</span>
        }
        // do checks
<span class="fc bfc" id="L1267" title="All 2 branches covered.">        if (checkObjects != null) {</span>
<span class="fc bfc" id="L1268" title="All 2 branches covered.">          checkObjectLoop: for (MtasParserObject checkObject : checkObjects) {</span>
<span class="fc" id="L1269">            MtasParserType checkType = checkObject.getType();</span>
            // condition on name
<span class="fc" id="L1271">            if (mappingCondition.get(&quot;type&quot;)</span>
<span class="fc bfc" id="L1272" title="All 2 branches covered.">                .equals(MtasParserMapping.PARSER_TYPE_NAME)) {</span>
<span class="pc bpc" id="L1273" title="1 of 2 branches missed.">              if (notCondition &amp;&amp; mappingCondition.get(MAPPING_VALUE_CONDITION)</span>
<span class="nc bnc" id="L1274" title="All 2 branches missed.">                  .equals(checkType.getName())) {</span>
<span class="nc" id="L1275">                throw new MtasParserException(&quot;condition NOT &quot;</span>
<span class="nc" id="L1276">                    + mappingCondition.get(MAPPING_VALUE_CONDITION)</span>
<span class="nc" id="L1277">                    + &quot; on name not matched (is &quot; + checkType.getName() + &quot;)&quot;);</span>
<span class="pc bpc" id="L1278" title="1 of 2 branches missed.">              } else if (!notCondition &amp;&amp; mappingCondition</span>
<span class="pc bpc" id="L1279" title="1 of 2 branches missed.">                  .get(MAPPING_VALUE_CONDITION).equals(checkType.getName())) {</span>
<span class="fc" id="L1280">                break checkObjectLoop;</span>
<span class="nc bnc" id="L1281" title="All 2 branches missed.">              } else if (!notCondition &amp;&amp; !mappingCondition</span>
<span class="nc bnc" id="L1282" title="All 2 branches missed.">                  .get(MAPPING_VALUE_CONDITION).equals(checkType.getName())) {</span>
<span class="nc" id="L1283">                throw new MtasParserException(&quot;condition &quot;</span>
<span class="nc" id="L1284">                    + mappingCondition.get(MAPPING_VALUE_CONDITION)</span>
<span class="nc" id="L1285">                    + &quot; on name not matched (is &quot; + checkType.getName() + &quot;)&quot;);</span>
              }
              // condition on attribute
<span class="fc" id="L1288">            } else if (mappingCondition.get(&quot;type&quot;)</span>
<span class="pc bpc" id="L1289" title="1 of 2 branches missed.">                .equals(MtasParserMapping.PARSER_TYPE_ATTRIBUTE)) {</span>
<span class="fc" id="L1290">              String attributeCondition = mappingCondition</span>
<span class="fc" id="L1291">                  .get(MAPPING_VALUE_CONDITION);</span>
<span class="fc" id="L1292">              String attributeValue = checkObject</span>
<span class="fc" id="L1293">                  .getAttribute(mappingCondition.get(&quot;name&quot;));</span>
<span class="pc bpc" id="L1294" title="1 of 4 branches missed.">              if ((attributeCondition == null) &amp;&amp; (attributeValue == null)) {</span>
<span class="nc bnc" id="L1295" title="All 2 branches missed.">                if (!notCondition) {</span>
<span class="nc" id="L1296">                  throw new MtasParserException(&quot;attribute &quot;</span>
<span class="nc" id="L1297">                      + mappingCondition.get(&quot;name&quot;) + &quot; not available&quot;);</span>
                }
<span class="pc bpc" id="L1299" title="1 of 4 branches missed.">              } else if ((attributeCondition != null)</span>
                  &amp;&amp; (attributeValue == null)) {
<span class="nc bnc" id="L1301" title="All 2 branches missed.">                if (!notCondition) {</span>
<span class="nc" id="L1302">                  throw new MtasParserException(</span>
                      &quot;condition &quot; + attributeCondition + &quot; on attribute &quot;
<span class="nc" id="L1304">                          + mappingCondition.get(&quot;name&quot;)</span>
                          + &quot; not matched (is null)&quot;);
                }
<span class="fc bfc" id="L1307" title="All 2 branches covered.">              } else if (attributeCondition != null) {</span>
<span class="pc bpc" id="L1308" title="1 of 2 branches missed.">                if (!notCondition</span>
<span class="nc bnc" id="L1309" title="All 2 branches missed.">                    &amp;&amp; !attributeCondition.equals(attributeValue)) {</span>
<span class="nc" id="L1310">                  throw new MtasParserException(</span>
                      &quot;condition &quot; + attributeCondition + &quot; on attribute &quot;
<span class="nc" id="L1312">                          + mappingCondition.get(&quot;name&quot;) + &quot; not matched (is &quot;</span>
                          + attributeValue + &quot;)&quot;);
<span class="pc bpc" id="L1314" title="1 of 2 branches missed.">                } else if (!notCondition</span>
<span class="nc bnc" id="L1315" title="All 2 branches missed.">                    &amp;&amp; attributeCondition.equals(attributeValue)) {</span>
<span class="nc" id="L1316">                  break checkObjectLoop;</span>
<span class="pc bpc" id="L1317" title="1 of 2 branches missed.">                } else if (notCondition</span>
<span class="fc bfc" id="L1318" title="All 2 branches covered.">                    &amp;&amp; attributeCondition.equals(attributeValue)) {</span>
<span class="fc" id="L1319">                  throw new MtasParserException(</span>
                      &quot;condition NOT &quot; + attributeCondition + &quot; on attribute &quot;
<span class="fc" id="L1321">                          + mappingCondition.get(&quot;name&quot;) + &quot; not matched (is &quot;</span>
                          + attributeValue + &quot;)&quot;);
                }
              }
              // condition on text
<span class="pc" id="L1326">            } else if (mappingCondition.get(&quot;type&quot;)</span>
<span class="nc bnc" id="L1327" title="All 2 branches missed.">                .equals(MtasParserMapping.PARSER_TYPE_TEXT)</span>
<span class="nc bnc" id="L1328" title="All 2 branches missed.">                &amp;&amp; object.getType().precheckText()) {</span>
<span class="nc" id="L1329">              String textCondition = mappingCondition</span>
<span class="nc" id="L1330">                  .get(MAPPING_VALUE_CONDITION);</span>
<span class="nc" id="L1331">              String textValue = object.getText();</span>
<span class="nc bnc" id="L1332" title="All 4 branches missed.">              if ((textCondition == null)</span>
<span class="nc bnc" id="L1333" title="All 2 branches missed.">                  &amp;&amp; ((textValue == null) || textValue.equals(&quot;&quot;))) {</span>
<span class="nc bnc" id="L1334" title="All 2 branches missed.">                if (!notCondition) {</span>
<span class="nc" id="L1335">                  throw new MtasParserException(&quot;no text available&quot;);</span>
                }
<span class="nc bnc" id="L1337" title="All 4 branches missed.">              } else if ((textCondition != null) &amp;&amp; (textValue == null)) {</span>
<span class="nc bnc" id="L1338" title="All 2 branches missed.">                if (!notCondition) {</span>
<span class="nc" id="L1339">                  throw new MtasParserException(&quot;condition &quot; + textCondition</span>
                      + &quot; on text not matched (is null)&quot;);
                }
<span class="nc bnc" id="L1342" title="All 2 branches missed.">              } else if (textCondition != null) {</span>
<span class="nc bnc" id="L1343" title="All 4 branches missed.">                if (!notCondition &amp;&amp; !textCondition.equals(textValue)) {</span>
<span class="nc" id="L1344">                  throw new MtasParserException(&quot;condition &quot; + textCondition</span>
                      + &quot; on text not matched (is &quot; + textValue + &quot;)&quot;);
<span class="nc bnc" id="L1346" title="All 4 branches missed.">                } else if (notCondition &amp;&amp; textCondition.equals(textValue)) {</span>
<span class="nc" id="L1347">                  throw new MtasParserException(&quot;condition NOT &quot; + textCondition</span>
                      + &quot; on text not matched (is &quot; + textValue + &quot;)&quot;);
                }
              }
            }
          }
<span class="pc bpc" id="L1353" title="1 of 2 branches missed.">        } else if (!notCondition) {</span>
<span class="fc" id="L1354">          throw new MtasParserException(</span>
              &quot;no object found to match condition&quot; + mappingCondition);
        }
      }
<span class="fc" id="L1358">    }</span>
<span class="fc" id="L1359">  }</span>

  /**
   * Postcheck mapping conditions.
   *
   * @param object the object
   * @param mappingConditions the mapping conditions
   * @param currentList the current list
   * @throws MtasParserException the mtas parser exception
   */
  private void postcheckMappingConditions(MtasParserObject object,
      List&lt;Map&lt;String, String&gt;&gt; mappingConditions,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList)
      throws MtasParserException {
<span class="fc" id="L1373">    precheckMappingConditions(object, mappingConditions, currentList);</span>
<span class="fc bfc" id="L1374" title="All 2 branches covered.">    for (Map&lt;String, String&gt; mappingCondition : mappingConditions) {</span>
      // condition on text
<span class="fc" id="L1376">      if (mappingCondition.get(&quot;type&quot;)</span>
<span class="pc bpc" id="L1377" title="1 of 2 branches missed.">          .equals(MtasParserMapping.PARSER_TYPE_TEXT)) {</span>
<span class="nc" id="L1378">        MtasParserObject[] checkObjects = computeObjectFromMappingValue(object,</span>
            mappingCondition, currentList);
<span class="nc bnc" id="L1380" title="All 2 branches missed.">        if (checkObjects != null) {</span>
<span class="nc" id="L1381">          String textCondition = mappingCondition.get(MAPPING_VALUE_CONDITION);</span>
<span class="nc" id="L1382">          String textValue = object.getText();</span>
<span class="nc" id="L1383">          Boolean notCondition = false;</span>
<span class="nc bnc" id="L1384" title="All 2 branches missed.">          if (mappingCondition.get(&quot;not&quot;) != null) {</span>
<span class="nc" id="L1385">            notCondition = true;</span>
          }
<span class="nc bnc" id="L1387" title="All 4 branches missed.">          if ((textCondition == null)</span>
<span class="nc bnc" id="L1388" title="All 2 branches missed.">              &amp;&amp; ((textValue == null) || textValue.isEmpty())) {</span>
<span class="nc bnc" id="L1389" title="All 2 branches missed.">            if (!notCondition) {</span>
<span class="nc" id="L1390">              throw new MtasParserException(&quot;no text available&quot;);</span>
            }
<span class="nc bnc" id="L1392" title="All 4 branches missed.">          } else if ((textCondition != null) &amp;&amp; (textValue == null)) {</span>
<span class="nc bnc" id="L1393" title="All 2 branches missed.">            if (!notCondition) {</span>
<span class="nc" id="L1394">              throw new MtasParserException(&quot;condition &quot; + textCondition</span>
                  + &quot; on text not matched (is null)&quot;);
            }
<span class="nc bnc" id="L1397" title="All 2 branches missed.">          } else if (textCondition != null) {</span>
<span class="nc bnc" id="L1398" title="All 4 branches missed.">            if (!notCondition &amp;&amp; !textCondition.equals(textValue)) {</span>
<span class="nc" id="L1399">              throw new MtasParserException(&quot;condition &quot; + textCondition</span>
                  + &quot; on text not matched (is &quot; + textValue + &quot;)&quot;);
<span class="nc bnc" id="L1401" title="All 4 branches missed.">            } else if (notCondition &amp;&amp; textCondition.equals(textValue)) {</span>
<span class="nc" id="L1402">              throw new MtasParserException(&quot;condition NOT &quot; + textCondition</span>
                  + &quot; on text not matched (is &quot; + textValue + &quot;)&quot;);
            }
          }
        }
      }
<span class="fc" id="L1408">    }</span>
<span class="fc" id="L1409">  }</span>

  /**
   * Compute filtered split values.
   *
   * @param values the values
   * @param filter the filter
   * @return the string[]
   * @throws MtasConfigException the mtas config exception
   */
  private String[] computeFilteredSplitValues(String[] values, String filter)
      throws MtasConfigException {
<span class="nc bnc" id="L1421" title="All 2 branches missed.">    if (filter != null) {</span>
<span class="nc" id="L1422">      String[] filters = filter.split(&quot;,&quot;);</span>
<span class="nc" id="L1423">      boolean[] valuesFilter = new boolean[values.length];</span>
<span class="nc" id="L1424">      boolean doSplitFilter = false;</span>
<span class="nc bnc" id="L1425" title="All 2 branches missed.">      for (String item : filters) {</span>
<span class="nc bnc" id="L1426" title="All 2 branches missed.">        if (item.trim().matches(</span>
<span class="nc" id="L1427">            &quot;^&quot; + Pattern.quote(MAPPING_FILTER_SPLIT) + &quot;\\([0-9\\-]+\\)$&quot;)) {</span>
<span class="nc" id="L1428">          doSplitFilter = true;</span>
<span class="nc" id="L1429">          Pattern splitContent = Pattern</span>
<span class="nc" id="L1430">              .compile(&quot;^&quot; + Pattern.quote(MAPPING_FILTER_SPLIT)</span>
                  + &quot;\\(([0-9]+)(-([0-9]+))?\\)$&quot;);
<span class="nc" id="L1432">          Matcher splitContentMatcher = splitContent.matcher(item.trim());</span>
<span class="nc bnc" id="L1433" title="All 2 branches missed.">          while (splitContentMatcher.find()) {</span>
<span class="nc bnc" id="L1434" title="All 2 branches missed.">            if (splitContentMatcher.group(3) == null) {</span>
<span class="nc" id="L1435">              int i = Integer.parseInt(splitContentMatcher.group(1));</span>
<span class="nc bnc" id="L1436" title="All 4 branches missed.">              if (i &gt;= 0 &amp;&amp; i &lt; values.length) {</span>
<span class="nc" id="L1437">                valuesFilter[i] = true;</span>
              }
<span class="nc" id="L1439">            } else {</span>
<span class="nc" id="L1440">              int i1 = Integer.parseInt(splitContentMatcher.group(1));</span>
<span class="nc" id="L1441">              int i2 = Integer.parseInt(splitContentMatcher.group(3));</span>
<span class="nc bnc" id="L1442" title="All 2 branches missed.">              for (int i = Math.max(0, i1); i &lt; Math.min(values.length,</span>
<span class="nc" id="L1443">                  i2); i++) {</span>
<span class="nc" id="L1444">                valuesFilter[i] = true;</span>
              }
<span class="nc" id="L1446">            }</span>
          }
        }
      }
<span class="nc bnc" id="L1450" title="All 2 branches missed.">      if (doSplitFilter) {</span>
<span class="nc" id="L1451">        int number = 0;</span>
<span class="nc bnc" id="L1452" title="All 2 branches missed.">        for (int i = 0; i &lt; valuesFilter.length; i++) {</span>
<span class="nc bnc" id="L1453" title="All 2 branches missed.">          if (valuesFilter[i]) {</span>
<span class="nc" id="L1454">            number++;</span>
          }
        }
<span class="nc bnc" id="L1457" title="All 2 branches missed.">        if (number &gt; 0) {</span>
<span class="nc" id="L1458">          String[] newValues = new String[number];</span>
<span class="nc" id="L1459">          number = 0;</span>
<span class="nc bnc" id="L1460" title="All 2 branches missed.">          for (int i = 0; i &lt; valuesFilter.length; i++) {</span>
<span class="nc bnc" id="L1461" title="All 2 branches missed.">            if (valuesFilter[i]) {</span>
<span class="nc" id="L1462">              newValues[number] = values[i];</span>
<span class="nc" id="L1463">              number++;</span>
            }
          }
<span class="nc" id="L1466">          return newValues;</span>
        } else {
<span class="nc" id="L1468">          return new String[] {};</span>
        }
      }
    }
<span class="nc" id="L1472">    return values;</span>
  }

  /**
   * Compute filtered prefixed value.
   *
   * @param type the type
   * @param value the value
   * @param filter the filter
   * @param prefix the prefix
   * @return the string
   * @throws MtasConfigException the mtas config exception
   */
  private String computeFilteredPrefixedValue(String type, String value,
      String filter, String prefix) throws MtasConfigException {
<span class="fc" id="L1487">    String localValue = value;</span>
    // do magic with filter
<span class="fc bfc" id="L1489" title="All 2 branches covered.">    if (filter != null) {</span>
<span class="fc" id="L1490">      String[] filters = filter.split(&quot;,&quot;);</span>
<span class="fc bfc" id="L1491" title="All 2 branches covered.">      for (String item : filters) {</span>
<span class="pc bpc" id="L1492" title="1 of 2 branches missed.">        if (item.trim().equals(MAPPING_FILTER_UPPERCASE)) {</span>
<span class="nc bnc" id="L1493" title="All 2 branches missed.">          localValue = localValue == null ? null : localValue.toUpperCase();</span>
<span class="fc bfc" id="L1494" title="All 2 branches covered.">        } else if (item.trim().equals(MAPPING_FILTER_LOWERCASE)) {</span>
<span class="pc bpc" id="L1495" title="1 of 2 branches missed.">          localValue = localValue == null ? null : localValue.toLowerCase();</span>
<span class="pc bpc" id="L1496" title="1 of 2 branches missed.">        } else if (item.trim().equals(MAPPING_FILTER_ASCII)) {</span>
<span class="pc bpc" id="L1497" title="1 of 2 branches missed.">          if (localValue != null) {</span>
<span class="fc" id="L1498">            char[] old = localValue.toCharArray();</span>
<span class="fc" id="L1499">            char[] ascii = new char[4 * old.length];</span>
<span class="fc" id="L1500">            ASCIIFoldingFilter.foldToASCII(old, 0, ascii, 0,</span>
<span class="fc" id="L1501">                localValue.length());</span>
<span class="fc" id="L1502">            localValue = new String(ascii);</span>
<span class="fc" id="L1503">          }</span>
<span class="nc" id="L1504">        } else if (item.trim()</span>
<span class="nc bnc" id="L1505" title="All 2 branches missed.">            .matches(Pattern.quote(MAPPING_FILTER_SPLIT) + &quot;\\([0-9\\-]+\\)&quot;)) {</span>
<span class="nc bnc" id="L1506" title="All 2 branches missed.">          if (!type.equals(MtasParserMapping.PARSER_TYPE_TEXT_SPLIT)) {</span>
<span class="nc" id="L1507">            throw new MtasConfigException(</span>
                &quot;split filter not allowed for &quot; + type);
          }
        } else {
<span class="nc" id="L1511">          throw new MtasConfigException(</span>
              &quot;unknown filter &quot; + item + &quot; for value &quot; + localValue);
        }
      }
    }
<span class="fc bfc" id="L1516" title="All 4 branches covered.">    if (localValue != null &amp;&amp; prefix != null) {</span>
<span class="fc" id="L1517">      localValue = prefix + localValue;</span>
    }
<span class="fc" id="L1519">    return localValue;</span>
  }

  /**
   * Compute maximum filtered payload.
   *
   * @param value the value
   * @param payload the payload
   * @param filter the filter
   * @return the bytes ref
   */
  private BytesRef computeMaximumFilteredPayload(String value, BytesRef payload,
      String filter) {
    // do magic with filter
<span class="fc bfc" id="L1533" title="All 2 branches covered.">    if (value != null) {</span>
<span class="pc bpc" id="L1534" title="1 of 2 branches missed.">      if (payload != null) {</span>
<span class="nc" id="L1535">        Float payloadFloat = PayloadHelper.decodeFloat(payload.bytes,</span>
            payload.offset);
<span class="nc" id="L1537">        Float valueFloat = Float.parseFloat(value);</span>
<span class="nc" id="L1538">        return new BytesRef(</span>
<span class="nc" id="L1539">            PayloadHelper.encodeFloat(Math.max(payloadFloat, valueFloat)));</span>
      } else {
<span class="fc" id="L1541">        return new BytesRef(PayloadHelper.encodeFloat(Float.parseFloat(value)));</span>
      }
    } else {
<span class="fc" id="L1544">      return payload;</span>
    }
  }

  /**
   * The Class MtasParserType.
   *
   * @param &lt;T&gt; the generic type
   */
  protected static class MtasParserType&lt;T&gt; {

    /** The type. */
    private String type;

    /** The name. */
    private String name;

    /** The precheck text. */
    protected boolean precheckText;

    /** The ref attribute name. */
    private String refAttributeName;

    /** The items. */
<span class="fc" id="L1568">    protected ArrayList&lt;T&gt; items = new ArrayList&lt;&gt;();</span>

    /**
     * Instantiates a new mtas parser type.
     *
     * @param type the type
     * @param name the name
     * @param precheckText the precheck text
     */
<span class="fc" id="L1577">    MtasParserType(String type, String name, boolean precheckText) {</span>
<span class="fc" id="L1578">      this.type = type;</span>
<span class="fc" id="L1579">      this.name = name;</span>
<span class="fc" id="L1580">      this.precheckText = precheckText;</span>
<span class="fc" id="L1581">    }</span>

    /**
     * Instantiates a new mtas parser type.
     *
     * @param type the type
     * @param name the name
     * @param precheckText the precheck text
     * @param refAttributeName the ref attribute name
     */
    MtasParserType(String type, String name, boolean precheckText,
        String refAttributeName) {
<span class="fc" id="L1593">      this(type, name, precheckText);</span>
<span class="fc" id="L1594">      this.refAttributeName = refAttributeName;</span>
<span class="fc" id="L1595">    }</span>

    /**
     * Gets the ref attribute name.
     *
     * @return the ref attribute name
     */
    public String getRefAttributeName() {
<span class="fc" id="L1603">      return refAttributeName;</span>
    }

    /**
     * Gets the name.
     *
     * @return the name
     */
    public String getName() {
<span class="fc" id="L1612">      return name;</span>
    }

    /**
     * Gets the type.
     *
     * @return the type
     */
    public String getType() {
<span class="fc" id="L1621">      return type;</span>
    }

    /**
     * Precheck text.
     *
     * @return true, if successful
     */
    public boolean precheckText() {
<span class="nc" id="L1630">      return precheckText;</span>
    }

    /**
     * Adds the item.
     *
     * @param item the item
     */
    public void addItem(T item) {
<span class="fc" id="L1639">      items.add(item);</span>
<span class="fc" id="L1640">    }</span>

    /**
     * Gets the items.
     *
     * @return the items
     */
    public List&lt;T&gt; getItems() {
<span class="fc" id="L1648">      return items;</span>
    }

  }

  /**
   * The Class MtasParserVariableValue.
   */
  protected static class MtasParserVariableValue {

    /** The type. */
    public String type;

    /** The name. */
    public String name;

    /**
     * Instantiates a new mtas parser variable value.
     *
     * @param type the type
     * @param name the name
     */
<span class="nc" id="L1670">    public MtasParserVariableValue(String type, String name) {</span>
<span class="nc" id="L1671">      this.type = type;</span>
<span class="nc" id="L1672">      this.name = name;</span>
<span class="nc" id="L1673">    }</span>

  }

  /**
   * The Class MtasParserMappingToken.
   */
  protected static class MtasParserMappingToken {

    /** The type. */
    public String type;

    /** The offset. */
    public Boolean offset;

    /** The realoffset. */
    public Boolean realoffset;

    /** The parent. */
    public Boolean parent;

    /** The pre values. */
    public List&lt;Map&lt;String, String&gt;&gt; preValues;

    /** The post values. */
    public List&lt;Map&lt;String, String&gt;&gt; postValues;

    /** The payload. */
    public List&lt;Map&lt;String, String&gt;&gt; payload;

    /**
     * Instantiates a new mtas parser mapping token.
     *
     * @param tokenType the token type
     */
<span class="fc" id="L1708">    public MtasParserMappingToken(String tokenType) {</span>
<span class="fc" id="L1709">      type = tokenType;</span>
<span class="fc" id="L1710">      offset = true;</span>
<span class="fc" id="L1711">      realoffset = true;</span>
<span class="fc" id="L1712">      parent = true;</span>
<span class="fc" id="L1713">      preValues = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L1714">      postValues = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L1715">      payload = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L1716">    }</span>

    /**
     * Sets the offset.
     *
     * @param tokenOffset the new offset
     */
    public void setOffset(Boolean tokenOffset) {
<span class="fc" id="L1724">      offset = tokenOffset;</span>
<span class="fc" id="L1725">    }</span>

    /**
     * Sets the real offset.
     *
     * @param tokenRealOffset the new real offset
     */
    public void setRealOffset(Boolean tokenRealOffset) {
<span class="fc" id="L1733">      realoffset = tokenRealOffset;</span>
<span class="fc" id="L1734">    }</span>

    /**
     * Sets the parent.
     *
     * @param tokenParent the new parent
     */
    public void setParent(Boolean tokenParent) {
<span class="fc" id="L1742">      parent = tokenParent;</span>
<span class="fc" id="L1743">    }</span>

  }

  /**
   * The Class MtasParserVariable.
   */
  protected static class MtasParserVariable {

    /** The name. */
    public String name;

    /** The variable. */
    public String variable;

    /** The values. */
    protected ArrayList&lt;MtasParserVariableValue&gt; values;

    /**
     * Instantiates a new mtas parser variable.
     *
     * @param name the name
     * @param value the value
     */
<span class="nc" id="L1767">    public MtasParserVariable(String name, String value) {</span>
<span class="nc" id="L1768">      this.name = name;</span>
<span class="nc" id="L1769">      this.variable = value;</span>
<span class="nc" id="L1770">      values = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L1771">    }</span>

    /**
     * Process config.
     *
     * @param config the config
     * @throws MtasConfigException the mtas config exception
     */
    public void processConfig(MtasConfiguration config)
        throws MtasConfigException {
<span class="nc bnc" id="L1781" title="All 2 branches missed.">      for (int k = 0; k &lt; config.children.size(); k++) {</span>
<span class="nc bnc" id="L1782" title="All 2 branches missed.">        if (config.children.get(k).name.equals(VARIABLE_SUBTYPE_VALUE)) {</span>

<span class="nc bnc" id="L1784" title="All 2 branches missed.">          for (int m = 0; m &lt; config.children.get(k).children.size(); m++) {</span>
<span class="nc" id="L1785">            if (config.children.get(k).children.get(m).name</span>
<span class="nc bnc" id="L1786" title="All 2 branches missed.">                .equals(VARIABLE_SUBTYPE_VALUE_ITEM)) {</span>
<span class="nc" id="L1787">              String valueType = config.children.get(k).children</span>
<span class="nc" id="L1788">                  .get(m).attributes.get(&quot;type&quot;);</span>
<span class="nc" id="L1789">              String nameType = config.children.get(k).children</span>
<span class="nc" id="L1790">                  .get(m).attributes.get(&quot;name&quot;);</span>
<span class="nc bnc" id="L1791" title="All 6 branches missed.">              if ((valueType != null) &amp;&amp; valueType.equals(&quot;attribute&quot;)</span>
                  &amp;&amp; nameType != null) {
<span class="nc" id="L1793">                MtasParserVariableValue variableValue = new MtasParserVariableValue(</span>
                    valueType, nameType);
<span class="nc" id="L1795">                values.add(variableValue);</span>
              }
            }
          }
        } else {
<span class="nc" id="L1800">          throw new MtasConfigException(</span>
<span class="nc" id="L1801">              &quot;unknown variable subtype &quot; + config.children.get(k).name</span>
<span class="nc" id="L1802">                  + &quot; in variable &quot; + config.attributes.get(&quot;name&quot;));</span>
        }
      }
<span class="nc" id="L1805">    }</span>

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
<span class="nc" id="L1814">      StringBuilder builder = new StringBuilder();</span>
<span class="nc" id="L1815">      builder.append(&quot;variable &quot; + variable + &quot; from &quot; + name);</span>
<span class="nc bnc" id="L1816" title="All 2 branches missed.">      for (int i = 0; i &lt; values.size(); i++) {</span>
<span class="nc" id="L1817">        builder.append(&quot;\n\tvalue &quot; + i);</span>
<span class="nc" id="L1818">        builder.append(&quot; - &quot; + values.get(i).type);</span>
      }
<span class="nc" id="L1820">      return builder.toString();</span>
    }
  }

  /**
   * The Class MtasParserMapping.
   *
   * @param &lt;T&gt; the generic type
   */
  protected abstract class MtasParserMapping&lt;T extends MtasParserMapping&lt;T&gt;&gt; {

    /**
     * Self.
     *
     * @return the t
     */
    protected abstract T self();

    /** The Constant SOURCE_OWN. */
    protected static final String SOURCE_OWN = &quot;own&quot;;

    /** The Constant SOURCE_REFS. */
    protected static final String SOURCE_REFS = &quot;refs&quot;;

    /** The Constant SOURCE_ANCESTOR_GROUP. */
    protected static final String SOURCE_ANCESTOR_GROUP = &quot;ancestorGroup&quot;;

    /** The Constant SOURCE_ANCESTOR_GROUP_ANNOTATION. */
    protected static final String SOURCE_ANCESTOR_GROUP_ANNOTATION = &quot;ancestorGroupAnnotation&quot;;

    /** The Constant SOURCE_ANCESTOR_WORD. */
    protected static final String SOURCE_ANCESTOR_WORD = &quot;ancestorWord&quot;;

    /** The Constant SOURCE_ANCESTOR_WORD_ANNOTATION. */
    protected static final String SOURCE_ANCESTOR_WORD_ANNOTATION = &quot;ancestorWordAnnotation&quot;;

    /** The Constant SOURCE_ANCESTOR_RELATION. */
    protected static final String SOURCE_ANCESTOR_RELATION = &quot;ancestorRelation&quot;;

    /** The Constant SOURCE_ANCESTOR_RELATION_ANNOTATION. */
    protected static final String SOURCE_ANCESTOR_RELATION_ANNOTATION = &quot;ancestorRelationAnnotation&quot;;

    /** The Constant SOURCE_STRING. */
    protected static final String SOURCE_STRING = &quot;string&quot;;

    /** The Constant PARSER_TYPE_VARIABLE. */
    protected static final String PARSER_TYPE_VARIABLE = &quot;variable&quot;;

    /** The Constant PARSER_TYPE_STRING. */
    protected static final String PARSER_TYPE_STRING = &quot;string&quot;;

    /** The Constant PARSER_TYPE_NAME. */
    protected static final String PARSER_TYPE_NAME = &quot;name&quot;;

    /** The Constant PARSER_TYPE_ATTRIBUTE. */
    protected static final String PARSER_TYPE_ATTRIBUTE = &quot;attribute&quot;;

    /** The Constant PARSER_TYPE_TEXT. */
    protected static final String PARSER_TYPE_TEXT = &quot;text&quot;;

    /** The Constant PARSER_TYPE_TEXT_SPLIT. */
    protected static final String PARSER_TYPE_TEXT_SPLIT = &quot;textSplit&quot;;

    /** The Constant PARSER_TYPE_EXISTENCE. */
    protected static final String PARSER_TYPE_EXISTENCE = &quot;existence&quot;;

    /** The Constant PARSER_TYPE_UNKNOWN_ANCESTOR. */
    protected static final String PARSER_TYPE_UNKNOWN_ANCESTOR = &quot;unknownAncestor&quot;;

    /** The type. */
    protected String type;

    /** The offset. */
    protected String offset;

    /** The real offset. */
    protected String realOffset;

    /** The position. */
    protected String position;

    /** The start. */
    protected String start;

    /** The end. */
    protected String end;

    /** The tokens. */
    protected List&lt;MtasParserMappingToken&gt; tokens;

    /** The conditions. */
    protected List&lt;Map&lt;String, String&gt;&gt; conditions;

    /**
     * Instantiates a new mtas parser mapping.
     */
<span class="fc" id="L1916">    public MtasParserMapping() {</span>
<span class="fc" id="L1917">      type = null;</span>
<span class="fc" id="L1918">      offset = null;</span>
<span class="fc" id="L1919">      realOffset = null;</span>
<span class="fc" id="L1920">      position = null;</span>
<span class="fc" id="L1921">      tokens = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L1922">      conditions = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L1923">      start = null;</span>
<span class="fc" id="L1924">      end = null;</span>
<span class="fc" id="L1925">    }</span>

    /**
     * Process config.
     *
     * @param config the config
     * @throws MtasConfigException the mtas config exception
     */
    public void processConfig(MtasConfiguration config)
        throws MtasConfigException {
<span class="fc" id="L1935">      setStartEnd(config.attributes.get(&quot;start&quot;), config.attributes.get(&quot;end&quot;));</span>
<span class="fc bfc" id="L1936" title="All 2 branches covered.">      for (int k = 0; k &lt; config.children.size(); k++) {</span>
<span class="fc bfc" id="L1937" title="All 2 branches covered.">        if (config.children.get(k).name.equals(MAPPING_SUBTYPE_TOKEN)) {</span>
<span class="fc" id="L1938">          String tokenType = config.children.get(k).attributes.get(&quot;type&quot;);</span>
<span class="pc bpc" id="L1939" title="2 of 4 branches missed.">          if ((tokenType != null) &amp;&amp; tokenType.equals(&quot;string&quot;)) {</span>
<span class="fc" id="L1940">            MtasParserMappingToken mappingToken = new MtasParserMappingToken(</span>
                tokenType);
<span class="fc" id="L1942">            tokens.add(mappingToken);</span>
            // check attributes
<span class="fc bfc" id="L1944" title="All 2 branches covered.">            for (String tokenAttributeName : config.children.get(k).attributes</span>
<span class="fc" id="L1945">                .keySet()) {</span>
<span class="fc" id="L1946">              String attributeValue = config.children.get(k).attributes</span>
<span class="fc" id="L1947">                  .get(tokenAttributeName);</span>
<span class="fc bfc" id="L1948" title="All 2 branches covered.">              if (tokenAttributeName.equals(TOKEN_OFFSET)) {</span>
<span class="pc bpc" id="L1949" title="1 of 2 branches missed.">                if (!attributeValue.equals(&quot;true&quot;)</span>
<span class="pc bpc" id="L1950" title="1 of 2 branches missed.">                    &amp;&amp; !attributeValue.equals(&quot;1&quot;)) {</span>
<span class="fc" id="L1951">                  mappingToken.setOffset(false);</span>
                } else {
<span class="nc" id="L1953">                  mappingToken.setOffset(true);</span>
                }
<span class="fc bfc" id="L1955" title="All 2 branches covered.">              } else if (tokenAttributeName.equals(TOKEN_REALOFFSET)) {</span>
<span class="pc bpc" id="L1956" title="1 of 2 branches missed.">                if (!attributeValue.equals(&quot;true&quot;)</span>
<span class="pc bpc" id="L1957" title="1 of 2 branches missed.">                    &amp;&amp; !attributeValue.equals(&quot;1&quot;)) {</span>
<span class="fc" id="L1958">                  mappingToken.setRealOffset(false);</span>
                } else {
<span class="nc" id="L1960">                  mappingToken.setRealOffset(true);</span>
                }
<span class="fc bfc" id="L1962" title="All 2 branches covered.">              } else if (tokenAttributeName.equals(TOKEN_PARENT)) {</span>
<span class="pc bpc" id="L1963" title="1 of 2 branches missed.">                if (!attributeValue.equals(&quot;true&quot;)</span>
<span class="pc bpc" id="L1964" title="1 of 2 branches missed.">                    &amp;&amp; !attributeValue.equals(&quot;1&quot;)) {</span>
<span class="fc" id="L1965">                  mappingToken.setParent(false);</span>
                } else {
<span class="nc" id="L1967">                  mappingToken.setParent(true);</span>
                }
              }
<span class="fc" id="L1970">            }</span>
<span class="fc bfc" id="L1971" title="All 2 branches covered.">            for (int m = 0; m &lt; config.children.get(k).children.size(); m++) {</span>
<span class="fc" id="L1972">              if (config.children.get(k).children.get(m).name</span>
<span class="fc bfc" id="L1973" title="All 2 branches covered.">                  .equals(MAPPING_SUBTYPE_TOKEN_PRE)</span>
<span class="fc" id="L1974">                  || config.children.get(k).children.get(m).name</span>
<span class="fc bfc" id="L1975" title="All 2 branches covered.">                      .equals(MAPPING_SUBTYPE_TOKEN_POST)) {</span>
<span class="fc" id="L1976">                MtasConfiguration items = config.children.get(k).children</span>
<span class="fc" id="L1977">                    .get(m);</span>
<span class="fc bfc" id="L1978" title="All 2 branches covered.">                for (int l = 0; l &lt; items.children.size(); l++) {</span>
<span class="pc bpc" id="L1979" title="1 of 2 branches missed.">                  if (items.children.get(l).name.equals(&quot;item&quot;)) {</span>
<span class="fc" id="L1980">                    String itemType = items.children.get(l).attributes</span>
<span class="fc" id="L1981">                        .get(MAPPING_VALUE_TYPE);</span>
<span class="fc" id="L1982">                    String nameAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L1983">                        .get(MAPPING_VALUE_NAME);</span>
<span class="fc" id="L1984">                    String prefixAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L1985">                        .get(MAPPING_VALUE_PREFIX);</span>
<span class="fc" id="L1986">                    String filterAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L1987">                        .get(MAPPING_VALUE_FILTER);</span>
<span class="fc" id="L1988">                    String distanceAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L1989">                        .get(MAPPING_VALUE_DISTANCE);</span>
<span class="fc" id="L1990">                    String valueAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L1991">                        .get(MAPPING_VALUE_VALUE);</span>
<span class="fc bfc" id="L1992" title="All 2 branches covered.">                    if (itemType.equals(ITEM_TYPE_STRING)) {</span>
<span class="fc" id="L1993">                      addString(mappingToken, items.name, valueAttribute);</span>
<span class="fc bfc" id="L1994" title="All 2 branches covered.">                    } else if (itemType.equals(ITEM_TYPE_NAME)) {</span>
<span class="fc" id="L1995">                      addName(mappingToken, items.name, prefixAttribute,</span>
                          filterAttribute);
<span class="fc bfc" id="L1997" title="All 2 branches covered.">                    } else if (itemType.equals(ITEM_TYPE_ATTRIBUTE)) {</span>
<span class="fc" id="L1998">                      addAttribute(mappingToken, items.name, nameAttribute,</span>
                          prefixAttribute, filterAttribute);
<span class="fc bfc" id="L2000" title="All 2 branches covered.">                    } else if (itemType.equals(ITEM_TYPE_TEXT)) {</span>
<span class="fc" id="L2001">                      addText(mappingToken, items.name, prefixAttribute,</span>
                          filterAttribute);
<span class="pc bpc" id="L2003" title="1 of 2 branches missed.">                    } else if (itemType.equals(ITEM_TYPE_TEXT_SPLIT)) {</span>
<span class="nc" id="L2004">                      addTextSplit(mappingToken, items.name, valueAttribute,</span>
                          prefixAttribute, filterAttribute);
<span class="pc bpc" id="L2006" title="1 of 2 branches missed.">                    } else if (itemType.equals(ITEM_TYPE_NAME_ANCESTOR)) {</span>
<span class="fc" id="L2007">                      addAncestorName(computeAncestorSourceType(type),</span>
                          mappingToken, items.name,
<span class="fc" id="L2009">                          computeDistance(distanceAttribute), prefixAttribute,</span>
                          filterAttribute);
<span class="nc bnc" id="L2011" title="All 2 branches missed.">                    } else if (itemType.equals(ITEM_TYPE_NAME_ANCESTOR_GROUP)) {</span>
<span class="nc" id="L2012">                      addAncestorName(SOURCE_ANCESTOR_GROUP, mappingToken,</span>
<span class="nc" id="L2013">                          items.name, computeDistance(distanceAttribute),</span>
                          prefixAttribute, filterAttribute);
<span class="nc" id="L2015">                    } else if (itemType</span>
<span class="nc bnc" id="L2016" title="All 2 branches missed.">                        .equals(ITEM_TYPE_NAME_ANCESTOR_GROUP_ANNOTATION)) {</span>
<span class="nc" id="L2017">                      addAncestorName(SOURCE_ANCESTOR_GROUP_ANNOTATION,</span>
                          mappingToken, items.name,
<span class="nc" id="L2019">                          computeDistance(distanceAttribute), prefixAttribute,</span>
                          filterAttribute);
<span class="nc bnc" id="L2021" title="All 2 branches missed.">                    } else if (itemType.equals(ITEM_TYPE_NAME_ANCESTOR_WORD)) {</span>
<span class="nc" id="L2022">                      addAncestorName(SOURCE_ANCESTOR_WORD, mappingToken,</span>
<span class="nc" id="L2023">                          items.name, computeDistance(distanceAttribute),</span>
                          prefixAttribute, filterAttribute);
<span class="nc" id="L2025">                    } else if (itemType</span>
<span class="nc bnc" id="L2026" title="All 2 branches missed.">                        .equals(ITEM_TYPE_NAME_ANCESTOR_WORD_ANNOTATION)) {</span>
<span class="nc" id="L2027">                      addAncestorName(SOURCE_ANCESTOR_WORD_ANNOTATION,</span>
                          mappingToken, items.name,
<span class="nc" id="L2029">                          computeDistance(distanceAttribute), prefixAttribute,</span>
                          filterAttribute);
<span class="nc" id="L2031">                    } else if (itemType</span>
<span class="nc bnc" id="L2032" title="All 2 branches missed.">                        .equals(ITEM_TYPE_NAME_ANCESTOR_RELATION)) {</span>
<span class="nc" id="L2033">                      addAncestorName(SOURCE_ANCESTOR_RELATION, mappingToken,</span>
<span class="nc" id="L2034">                          items.name, computeDistance(distanceAttribute),</span>
                          prefixAttribute, filterAttribute);
<span class="nc" id="L2036">                    } else if (itemType</span>
<span class="nc bnc" id="L2037" title="All 2 branches missed.">                        .equals(ITEM_TYPE_NAME_ANCESTOR_RELATION_ANNOTATION)) {</span>
<span class="nc" id="L2038">                      addAncestorName(SOURCE_ANCESTOR_RELATION_ANNOTATION,</span>
                          mappingToken, items.name,
<span class="nc" id="L2040">                          computeDistance(distanceAttribute), prefixAttribute,</span>
                          filterAttribute);
<span class="nc" id="L2042">                    } else if (itemType</span>
<span class="nc bnc" id="L2043" title="All 2 branches missed.">                        .equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_GROUP)) {</span>
<span class="nc" id="L2044">                      addAncestorAttribute(SOURCE_ANCESTOR_GROUP, mappingToken,</span>
<span class="nc" id="L2045">                          items.name, computeDistance(distanceAttribute),</span>
                          nameAttribute, prefixAttribute, filterAttribute);
<span class="nc bnc" id="L2047" title="All 2 branches missed.">                    } else if (itemType.equals(</span>
                        ITEM_TYPE_ATTRIBUTE_ANCESTOR_GROUP_ANNOTATION)) {
<span class="nc" id="L2049">                      addAncestorAttribute(SOURCE_ANCESTOR_GROUP_ANNOTATION,</span>
                          mappingToken, items.name,
<span class="nc" id="L2051">                          computeDistance(distanceAttribute), nameAttribute,</span>
                          prefixAttribute, filterAttribute);
<span class="nc" id="L2053">                    } else if (itemType</span>
<span class="nc bnc" id="L2054" title="All 2 branches missed.">                        .equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_WORD)) {</span>
<span class="nc" id="L2055">                      addAncestorAttribute(SOURCE_ANCESTOR_WORD, mappingToken,</span>
<span class="nc" id="L2056">                          items.name, computeDistance(distanceAttribute),</span>
                          nameAttribute, prefixAttribute, filterAttribute);
<span class="nc" id="L2058">                    } else if (itemType</span>
<span class="nc bnc" id="L2059" title="All 2 branches missed.">                        .equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_WORD_ANNOTATION)) {</span>
<span class="nc" id="L2060">                      addAncestorAttribute(SOURCE_ANCESTOR_WORD_ANNOTATION,</span>
                          mappingToken, items.name,
<span class="nc" id="L2062">                          computeDistance(distanceAttribute), nameAttribute,</span>
                          prefixAttribute, filterAttribute);
<span class="nc" id="L2064">                    } else if (itemType</span>
<span class="nc bnc" id="L2065" title="All 2 branches missed.">                        .equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_RELATION)) {</span>
<span class="nc" id="L2066">                      addAncestorAttribute(SOURCE_ANCESTOR_RELATION,</span>
                          mappingToken, items.name,
<span class="nc" id="L2068">                          computeDistance(distanceAttribute), nameAttribute,</span>
                          prefixAttribute, filterAttribute);
<span class="nc bnc" id="L2070" title="All 2 branches missed.">                    } else if (itemType.equals(</span>
                        ITEM_TYPE_ATTRIBUTE_ANCESTOR_RELATION_ANNOTATION)) {
<span class="nc" id="L2072">                      addAncestorAttribute(SOURCE_ANCESTOR_RELATION_ANNOTATION,</span>
                          mappingToken, items.name,
<span class="nc" id="L2074">                          computeDistance(distanceAttribute), nameAttribute,</span>
                          prefixAttribute, filterAttribute);
<span class="nc bnc" id="L2076" title="All 2 branches missed.">                    } else if (itemType.equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR)) {</span>
<span class="nc" id="L2077">                      addAncestorAttribute(computeAncestorSourceType(this.type),</span>
                          mappingToken, items.name,
<span class="nc" id="L2079">                          computeDistance(distanceAttribute), nameAttribute,</span>
                          prefixAttribute, filterAttribute);
<span class="nc" id="L2081">                    } else if (itemType</span>
<span class="nc bnc" id="L2082" title="All 2 branches missed.">                        .equals(ITEM_TYPE_VARIABLE_FROM_ATTRIBUTE)) {</span>
<span class="nc" id="L2083">                      addVariableFromAttribute(mappingToken, items.name,</span>
                          nameAttribute, prefixAttribute, valueAttribute);
                    } else {
<span class="nc" id="L2086">                      throw new MtasConfigException(String.format(</span>
                          &quot;unknown itemType %s for %s in mapping %s&quot;, itemType,
<span class="nc" id="L2088">                          items.name, config.attributes.get(&quot;name&quot;)));</span>
                    }
                  }
                }
<span class="fc" id="L2092">              } else if (config.children.get(k).children.get(m).name</span>
<span class="pc bpc" id="L2093" title="1 of 2 branches missed.">                  .equals(MAPPING_SUBTYPE_PAYLOAD)) {</span>
<span class="fc" id="L2094">                MtasConfiguration items = config.children.get(k).children</span>
<span class="fc" id="L2095">                    .get(m);</span>
<span class="fc bfc" id="L2096" title="All 2 branches covered.">                for (int l = 0; l &lt; items.children.size(); l++) {</span>
<span class="pc bpc" id="L2097" title="1 of 2 branches missed.">                  if (items.children.get(l).name.equals(&quot;item&quot;)) {</span>
<span class="fc" id="L2098">                    String itemType = items.children.get(l).attributes</span>
<span class="fc" id="L2099">                        .get(&quot;type&quot;);</span>
<span class="fc" id="L2100">                    String valueAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L2101">                        .get(MAPPING_VALUE_VALUE);</span>
<span class="fc" id="L2102">                    String nameAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L2103">                        .get(MAPPING_VALUE_NAME);</span>
<span class="fc" id="L2104">                    String filterAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L2105">                        .get(MAPPING_VALUE_FILTER);</span>
<span class="fc" id="L2106">                    String distanceAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L2107">                        .get(MAPPING_VALUE_DISTANCE);</span>
<span class="pc bpc" id="L2108" title="1 of 2 branches missed.">                    if (itemType.equals(ITEM_TYPE_STRING)) {</span>
<span class="nc" id="L2109">                      payloadString(mappingToken, valueAttribute);</span>
<span class="pc bpc" id="L2110" title="1 of 2 branches missed.">                    } else if (itemType.equals(ITEM_TYPE_TEXT)) {</span>
<span class="nc" id="L2111">                      payloadText(mappingToken, filterAttribute);</span>
<span class="fc bfc" id="L2112" title="All 2 branches covered.">                    } else if (itemType.equals(ITEM_TYPE_ATTRIBUTE)) {</span>
<span class="fc" id="L2113">                      payloadAttribute(mappingToken, nameAttribute,</span>
                          filterAttribute);
<span class="pc bpc" id="L2115" title="1 of 2 branches missed.">                    } else if (itemType.equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR)) {</span>
<span class="fc" id="L2116">                      payloadAncestorAttribute(mappingToken,</span>
<span class="fc" id="L2117">                          computeAncestorSourceType(type),</span>
<span class="fc" id="L2118">                          computeDistance(distanceAttribute), nameAttribute,</span>
                          filterAttribute);
<span class="nc" id="L2120">                    } else if (itemType</span>
<span class="nc bnc" id="L2121" title="All 2 branches missed.">                        .equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_GROUP)) {</span>
<span class="nc" id="L2122">                      payloadAncestorAttribute(mappingToken,</span>
                          SOURCE_ANCESTOR_GROUP,
<span class="nc" id="L2124">                          computeDistance(distanceAttribute), nameAttribute,</span>
                          filterAttribute);
<span class="nc bnc" id="L2126" title="All 2 branches missed.">                    } else if (itemType.equals(</span>
                        ITEM_TYPE_ATTRIBUTE_ANCESTOR_GROUP_ANNOTATION)) {
<span class="nc" id="L2128">                      payloadAncestorAttribute(mappingToken,</span>
                          SOURCE_ANCESTOR_GROUP_ANNOTATION,
<span class="nc" id="L2130">                          computeDistance(distanceAttribute), nameAttribute,</span>
                          filterAttribute);
<span class="nc" id="L2132">                    } else if (itemType</span>
<span class="nc bnc" id="L2133" title="All 2 branches missed.">                        .equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_WORD)) {</span>
<span class="nc" id="L2134">                      payloadAncestorAttribute(mappingToken,</span>
                          SOURCE_ANCESTOR_WORD,
<span class="nc" id="L2136">                          computeDistance(distanceAttribute), nameAttribute,</span>
                          filterAttribute);
<span class="nc" id="L2138">                    } else if (itemType</span>
<span class="nc bnc" id="L2139" title="All 2 branches missed.">                        .equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_WORD_ANNOTATION)) {</span>
<span class="nc" id="L2140">                      payloadAncestorAttribute(mappingToken,</span>
                          SOURCE_ANCESTOR_WORD_ANNOTATION,
<span class="nc" id="L2142">                          computeDistance(distanceAttribute), nameAttribute,</span>
                          filterAttribute);
<span class="nc" id="L2144">                    } else if (itemType</span>
<span class="nc bnc" id="L2145" title="All 2 branches missed.">                        .equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_RELATION)) {</span>
<span class="nc" id="L2146">                      payloadAncestorAttribute(mappingToken,</span>
                          SOURCE_ANCESTOR_RELATION,
<span class="nc" id="L2148">                          computeDistance(distanceAttribute), nameAttribute,</span>
                          filterAttribute);
<span class="nc bnc" id="L2150" title="All 2 branches missed.">                    } else if (itemType.equals(</span>
                        ITEM_TYPE_ATTRIBUTE_ANCESTOR_RELATION_ANNOTATION)) {
<span class="nc" id="L2152">                      payloadAncestorAttribute(mappingToken,</span>
                          SOURCE_ANCESTOR_RELATION_ANNOTATION,
<span class="nc" id="L2154">                          computeDistance(distanceAttribute), nameAttribute,</span>
                          filterAttribute);
                    } else {
<span class="nc" id="L2157">                      throw new MtasConfigException(String.format(</span>
                          &quot;unknown itemType %s for %s in mapping %s&quot;, itemType,
<span class="nc" id="L2159">                          items.name, config.attributes.get(&quot;name&quot;)));</span>
                    }
                  }
                }
              }
            }
          }
<span class="fc" id="L2166">        } else if (config.children.get(k).name</span>
<span class="pc bpc" id="L2167" title="1 of 2 branches missed.">            .equals(MAPPING_SUBTYPE_CONDITION)) {</span>
<span class="fc" id="L2168">          MtasConfiguration items = config.children.get(k);</span>
<span class="fc bfc" id="L2169" title="All 2 branches covered.">          for (int l = 0; l &lt; items.children.size(); l++) {</span>
<span class="pc bpc" id="L2170" title="1 of 2 branches missed.">            if (items.children.get(l).name.equals(&quot;item&quot;)) {</span>
<span class="fc" id="L2171">              String itemType = items.children.get(l).attributes.get(&quot;type&quot;);</span>
<span class="fc" id="L2172">              String nameAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L2173">                  .get(MAPPING_VALUE_NAME);</span>
<span class="fc" id="L2174">              String conditionAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L2175">                  .get(MAPPING_VALUE_CONDITION);</span>
<span class="fc" id="L2176">              String filterAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L2177">                  .get(MAPPING_VALUE_FILTER);</span>
<span class="fc" id="L2178">              String numberAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L2179">                  .get(MAPPING_VALUE_NUMBER);</span>
<span class="fc" id="L2180">              String distanceAttribute = items.children.get(l).attributes</span>
<span class="fc" id="L2181">                  .get(MAPPING_VALUE_DISTANCE);</span>
<span class="fc" id="L2182">              String notAttribute = items.children.get(l).attributes.get(&quot;not&quot;);</span>
<span class="pc bpc" id="L2183" title="1 of 4 branches missed.">              if ((notAttribute != null) &amp;&amp; !notAttribute.equals(&quot;true&quot;)</span>
<span class="nc bnc" id="L2184" title="All 2 branches missed.">                  &amp;&amp; !notAttribute.equals(&quot;1&quot;)) {</span>
<span class="nc" id="L2185">                notAttribute = null;</span>
              }
<span class="fc bfc" id="L2187" title="All 2 branches covered.">              if (itemType.equals(ITEM_TYPE_ATTRIBUTE)) {</span>
<span class="fc" id="L2188">                conditionAttribute(nameAttribute, conditionAttribute,</span>
                    filterAttribute, notAttribute);
<span class="pc bpc" id="L2190" title="1 of 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_NAME)) {</span>
<span class="nc" id="L2191">                conditionName(conditionAttribute, notAttribute);</span>
<span class="pc bpc" id="L2192" title="1 of 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_TEXT)) {</span>
<span class="nc" id="L2193">                conditionText(conditionAttribute, filterAttribute,</span>
                    notAttribute);
<span class="fc bfc" id="L2195" title="All 2 branches covered.">              } else if (itemType.equals(ITEM_TYPE_UNKNOWN_ANCESTOR)) {</span>
<span class="fc" id="L2196">                conditionUnknownAncestor(computeNumber(numberAttribute));</span>
<span class="fc bfc" id="L2197" title="All 2 branches covered.">              } else if (itemType.equals(ITEM_TYPE_ANCESTOR)) {</span>
<span class="fc" id="L2198">                conditionAncestor(computeAncestorSourceType(type),</span>
<span class="fc" id="L2199">                    computeNumber(numberAttribute));</span>
<span class="pc bpc" id="L2200" title="1 of 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_ANCESTOR_GROUP)) {</span>
<span class="nc" id="L2201">                conditionAncestor(SOURCE_ANCESTOR_GROUP,</span>
<span class="nc" id="L2202">                    computeNumber(numberAttribute));</span>
<span class="pc bpc" id="L2203" title="1 of 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_ANCESTOR_GROUP_ANNOTATION)) {</span>
<span class="nc" id="L2204">                conditionAncestor(SOURCE_ANCESTOR_GROUP_ANNOTATION,</span>
<span class="nc" id="L2205">                    computeNumber(numberAttribute));</span>
<span class="fc bfc" id="L2206" title="All 2 branches covered.">              } else if (itemType.equals(ITEM_TYPE_ANCESTOR_WORD)) {</span>
<span class="fc" id="L2207">                conditionAncestor(SOURCE_ANCESTOR_WORD,</span>
<span class="fc" id="L2208">                    computeNumber(numberAttribute));</span>
<span class="pc bpc" id="L2209" title="1 of 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_ANCESTOR_WORD_ANNOTATION)) {</span>
<span class="nc" id="L2210">                conditionAncestor(SOURCE_ANCESTOR_WORD_ANNOTATION,</span>
<span class="nc" id="L2211">                    computeNumber(numberAttribute));</span>
<span class="pc bpc" id="L2212" title="1 of 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_ANCESTOR_RELATION)) {</span>
<span class="nc" id="L2213">                conditionAncestor(SOURCE_ANCESTOR_RELATION,</span>
<span class="nc" id="L2214">                    computeNumber(numberAttribute));</span>
<span class="fc" id="L2215">              } else if (itemType</span>
<span class="pc bpc" id="L2216" title="1 of 2 branches missed.">                  .equals(ITEM_TYPE_ANCESTOR_RELATION_ANNOTATION)) {</span>
<span class="nc" id="L2217">                conditionAncestor(SOURCE_ANCESTOR_RELATION_ANNOTATION,</span>
<span class="nc" id="L2218">                    computeNumber(numberAttribute));</span>
<span class="pc bpc" id="L2219" title="1 of 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR)) {</span>
<span class="nc" id="L2220">                conditionAncestorAttribute(computeAncestorSourceType(type),</span>
<span class="nc" id="L2221">                    computeDistance(distanceAttribute), nameAttribute,</span>
                    conditionAttribute, filterAttribute, notAttribute);
<span class="pc bpc" id="L2223" title="1 of 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_GROUP)) {</span>
<span class="nc" id="L2224">                conditionAncestorAttribute(SOURCE_ANCESTOR_GROUP,</span>
<span class="nc" id="L2225">                    computeDistance(distanceAttribute), nameAttribute,</span>
                    conditionAttribute, filterAttribute, notAttribute);
<span class="fc" id="L2227">              } else if (itemType</span>
<span class="pc bpc" id="L2228" title="1 of 2 branches missed.">                  .equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_GROUP_ANNOTATION)) {</span>
<span class="nc" id="L2229">                conditionAncestorAttribute(SOURCE_ANCESTOR_GROUP_ANNOTATION,</span>
<span class="nc" id="L2230">                    computeDistance(distanceAttribute), nameAttribute,</span>
                    conditionAttribute, filterAttribute, notAttribute);
<span class="pc bpc" id="L2232" title="1 of 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_WORD)) {</span>
<span class="nc" id="L2233">                conditionAncestorAttribute(SOURCE_ANCESTOR_WORD,</span>
<span class="nc" id="L2234">                    computeDistance(distanceAttribute), nameAttribute,</span>
                    conditionAttribute, filterAttribute, notAttribute);
<span class="fc" id="L2236">              } else if (itemType</span>
<span class="pc bpc" id="L2237" title="1 of 2 branches missed.">                  .equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_WORD_ANNOTATION)) {</span>
<span class="nc" id="L2238">                conditionAncestorAttribute(SOURCE_ANCESTOR_WORD_ANNOTATION,</span>
<span class="nc" id="L2239">                    computeDistance(distanceAttribute), nameAttribute,</span>
                    conditionAttribute, filterAttribute, notAttribute);
<span class="fc" id="L2241">              } else if (itemType</span>
<span class="pc bpc" id="L2242" title="1 of 2 branches missed.">                  .equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_RELATION)) {</span>
<span class="nc" id="L2243">                conditionAncestorAttribute(SOURCE_ANCESTOR_RELATION,</span>
<span class="nc" id="L2244">                    computeDistance(distanceAttribute), nameAttribute,</span>
                    conditionAttribute, filterAttribute, notAttribute);
<span class="fc" id="L2246">              } else if (itemType</span>
<span class="pc bpc" id="L2247" title="1 of 2 branches missed.">                  .equals(ITEM_TYPE_ATTRIBUTE_ANCESTOR_RELATION_ANNOTATION)) {</span>
<span class="nc" id="L2248">                conditionAncestorAttribute(SOURCE_ANCESTOR_RELATION_ANNOTATION,</span>
<span class="nc" id="L2249">                    computeDistance(distanceAttribute), nameAttribute,</span>
                    conditionAttribute, filterAttribute, notAttribute);
<span class="pc bpc" id="L2251" title="1 of 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_NAME_ANCESTOR)) {</span>
<span class="fc" id="L2252">                conditionAncestorName(computeAncestorSourceType(type),</span>
<span class="fc" id="L2253">                    computeDistance(distanceAttribute), conditionAttribute,</span>
                    filterAttribute, notAttribute);
<span class="nc bnc" id="L2255" title="All 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_NAME_ANCESTOR_GROUP)) {</span>
<span class="nc" id="L2256">                conditionAncestorName(SOURCE_ANCESTOR_GROUP,</span>
<span class="nc" id="L2257">                    computeDistance(distanceAttribute), conditionAttribute,</span>
                    filterAttribute, notAttribute);
<span class="nc" id="L2259">              } else if (itemType</span>
<span class="nc bnc" id="L2260" title="All 2 branches missed.">                  .equals(ITEM_TYPE_NAME_ANCESTOR_GROUP_ANNOTATION)) {</span>
<span class="nc" id="L2261">                conditionAncestorName(SOURCE_ANCESTOR_GROUP_ANNOTATION,</span>
<span class="nc" id="L2262">                    computeDistance(distanceAttribute), conditionAttribute,</span>
                    filterAttribute, notAttribute);
<span class="nc bnc" id="L2264" title="All 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_NAME_ANCESTOR_WORD)) {</span>
<span class="nc" id="L2265">                conditionAncestorName(SOURCE_ANCESTOR_WORD,</span>
<span class="nc" id="L2266">                    computeDistance(distanceAttribute), conditionAttribute,</span>
                    filterAttribute, notAttribute);
<span class="nc" id="L2268">              } else if (itemType</span>
<span class="nc bnc" id="L2269" title="All 2 branches missed.">                  .equals(ITEM_TYPE_NAME_ANCESTOR_WORD_ANNOTATION)) {</span>
<span class="nc" id="L2270">                conditionAncestorName(SOURCE_ANCESTOR_WORD_ANNOTATION,</span>
<span class="nc" id="L2271">                    computeDistance(distanceAttribute), conditionAttribute,</span>
                    filterAttribute, notAttribute);
<span class="nc bnc" id="L2273" title="All 2 branches missed.">              } else if (itemType.equals(ITEM_TYPE_NAME_ANCESTOR_RELATION)) {</span>
<span class="nc" id="L2274">                conditionAncestorName(SOURCE_ANCESTOR_RELATION,</span>
<span class="nc" id="L2275">                    computeDistance(distanceAttribute), conditionAttribute,</span>
                    filterAttribute, notAttribute);
<span class="nc" id="L2277">              } else if (itemType</span>
<span class="nc bnc" id="L2278" title="All 2 branches missed.">                  .equals(ITEM_TYPE_NAME_ANCESTOR_RELATION_ANNOTATION)) {</span>
<span class="nc" id="L2279">                conditionAncestorName(SOURCE_ANCESTOR_RELATION_ANNOTATION,</span>
<span class="nc" id="L2280">                    computeDistance(distanceAttribute), conditionAttribute,</span>
                    filterAttribute, notAttribute);
              } else {
<span class="nc" id="L2283">                throw new MtasConfigException(</span>
<span class="nc" id="L2284">                    String.format(&quot;unknown itemType %s for %s in mapping %s&quot;,</span>
<span class="nc" id="L2285">                        itemType, config.children.get(k).name,</span>
<span class="nc" id="L2286">                        config.attributes.get(&quot;name&quot;)));</span>
              }
            }
          }
<span class="fc" id="L2290">        } else {</span>
<span class="nc" id="L2291">          throw new MtasConfigException(</span>
<span class="nc" id="L2292">              String.format(&quot;unknown mapping subType %s in mapping %s&quot;,</span>
<span class="nc" id="L2293">                  config.children.get(k).name, config.attributes.get(&quot;name&quot;)));</span>
        }
      }
<span class="fc" id="L2296">    }</span>

    /**
     * Sets the start end.
     *
     * @param start the start
     * @param end the end
     */
    protected void setStartEnd(String start, String end) {
<span class="pc bpc" id="L2305" title="7 of 8 branches missed.">      if (start != null &amp;&amp; !start.isEmpty() &amp;&amp; end != null &amp;&amp; !end.isEmpty()) {</span>
<span class="nc" id="L2306">        this.start = start;</span>
<span class="nc" id="L2307">        this.end = end;</span>
      }
<span class="fc" id="L2309">    }</span>

    /**
     * Condition unknown ancestor.
     *
     * @param number the number
     */
    private void conditionUnknownAncestor(String number) {
<span class="fc" id="L2317">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2318">      mapConstructionItem.put(&quot;type&quot;, PARSER_TYPE_UNKNOWN_ANCESTOR);</span>
<span class="fc" id="L2319">      mapConstructionItem.put(&quot;number&quot;, number);</span>
<span class="fc" id="L2320">      conditions.add(mapConstructionItem);</span>
<span class="fc" id="L2321">    }</span>

    /**
     * Adds the string.
     *
     * @param mappingToken the mapping token
     * @param type the type
     * @param text the text
     */
    private void addString(MtasParserMappingToken mappingToken, String type,
        String text) {
<span class="fc" id="L2332">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2333">      mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_STRING);</span>
<span class="fc" id="L2334">      mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_STRING);</span>
<span class="fc" id="L2335">      mapConstructionItem.put(MAPPING_VALUE_TEXT, text);</span>
<span class="pc bpc" id="L2336" title="1 of 2 branches missed.">      if (type.equals(MAPPING_SUBTYPE_TOKEN_PRE)) {</span>
<span class="fc" id="L2337">        mappingToken.preValues.add(mapConstructionItem);</span>
<span class="nc bnc" id="L2338" title="All 2 branches missed.">      } else if (type.equals(MAPPING_SUBTYPE_TOKEN_POST)) {</span>
<span class="nc" id="L2339">        mappingToken.postValues.add(mapConstructionItem);</span>
      }
<span class="fc" id="L2341">    }</span>

    /**
     * Payload string.
     *
     * @param mappingToken the mapping token
     * @param text the text
     */
    private void payloadString(MtasParserMappingToken mappingToken,
        String text) {
<span class="nc" id="L2351">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="nc" id="L2352">      mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_STRING);</span>
<span class="nc" id="L2353">      mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_STRING);</span>
<span class="nc" id="L2354">      mapConstructionItem.put(MAPPING_VALUE_TEXT, text);</span>
<span class="nc" id="L2355">      mappingToken.payload.add(mapConstructionItem);</span>
<span class="nc" id="L2356">    }</span>

    /**
     * Adds the name.
     *
     * @param mappingToken the mapping token
     * @param type the type
     * @param prefix the prefix
     * @param filter the filter
     */
    private void addName(MtasParserMappingToken mappingToken, String type,
        String prefix, String filter) {
<span class="fc" id="L2368">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2369">      mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_OWN);</span>
<span class="fc" id="L2370">      mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_NAME);</span>
<span class="fc" id="L2371">      mapConstructionItem.put(MAPPING_VALUE_PREFIX, prefix);</span>
<span class="fc" id="L2372">      mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="pc bpc" id="L2373" title="1 of 2 branches missed.">      if (type.equals(MAPPING_SUBTYPE_TOKEN_PRE)) {</span>
<span class="fc" id="L2374">        mappingToken.preValues.add(mapConstructionItem);</span>
<span class="nc bnc" id="L2375" title="All 2 branches missed.">      } else if (type.equals(MAPPING_SUBTYPE_TOKEN_POST)) {</span>
<span class="nc" id="L2376">        mappingToken.postValues.add(mapConstructionItem);</span>
      }
<span class="fc" id="L2378">    }</span>

    /**
     * Condition name.
     *
     * @param condition the condition
     * @param not the not
     */
    private void conditionName(String condition, String not) {
<span class="nc" id="L2387">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="nc" id="L2388">      mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_OWN);</span>
<span class="nc" id="L2389">      mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_NAME);</span>
<span class="nc" id="L2390">      mapConstructionItem.put(MAPPING_VALUE_CONDITION, condition);</span>
<span class="nc" id="L2391">      mapConstructionItem.put(MAPPING_VALUE_NOT, not);</span>
<span class="nc" id="L2392">      conditions.add(mapConstructionItem);</span>
<span class="nc" id="L2393">    }</span>

    /**
     * Adds the text.
     *
     * @param mappingToken the mapping token
     * @param type the type
     * @param prefix the prefix
     * @param filter the filter
     */
    private void addText(MtasParserMappingToken mappingToken, String type,
        String prefix, String filter) {
<span class="fc" id="L2405">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2406">      mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_OWN);</span>
<span class="fc" id="L2407">      mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_TEXT);</span>
<span class="fc" id="L2408">      mapConstructionItem.put(MAPPING_VALUE_PREFIX, prefix);</span>
<span class="fc" id="L2409">      mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="pc bpc" id="L2410" title="1 of 2 branches missed.">      if (type.equals(MAPPING_SUBTYPE_TOKEN_PRE)) {</span>
<span class="nc" id="L2411">        mappingToken.preValues.add(mapConstructionItem);</span>
<span class="pc bpc" id="L2412" title="1 of 2 branches missed.">      } else if (type.equals(MAPPING_SUBTYPE_TOKEN_POST)) {</span>
<span class="fc" id="L2413">        mappingToken.postValues.add(mapConstructionItem);</span>
      }
<span class="fc" id="L2415">    }</span>

    /**
     * Adds the text split.
     *
     * @param mappingToken the mapping token
     * @param type the type
     * @param split the split
     * @param prefix the prefix
     * @param filter the filter
     */
    private void addTextSplit(MtasParserMappingToken mappingToken, String type,
        String split, String prefix, String filter) {
<span class="nc" id="L2428">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="nc" id="L2429">      mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_OWN);</span>
<span class="nc" id="L2430">      mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_TEXT_SPLIT);</span>
<span class="nc" id="L2431">      mapConstructionItem.put(MAPPING_VALUE_SPLIT, split);</span>
<span class="nc" id="L2432">      mapConstructionItem.put(MAPPING_VALUE_PREFIX, prefix);</span>
<span class="nc" id="L2433">      mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="nc bnc" id="L2434" title="All 2 branches missed.">      if (type.equals(MAPPING_SUBTYPE_TOKEN_PRE)) {</span>
<span class="nc" id="L2435">        mappingToken.preValues.add(mapConstructionItem);</span>
<span class="nc bnc" id="L2436" title="All 2 branches missed.">      } else if (type.equals(MAPPING_SUBTYPE_TOKEN_POST)) {</span>
<span class="nc" id="L2437">        mappingToken.postValues.add(mapConstructionItem);</span>
      }
<span class="nc" id="L2439">    }</span>

    /**
     * Condition text.
     *
     * @param condition the condition
     * @param filter the filter
     * @param not the not
     */
    private void conditionText(String condition, String filter, String not) {
<span class="nc" id="L2449">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="nc" id="L2450">      mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_OWN);</span>
<span class="nc" id="L2451">      mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_TEXT);</span>
<span class="nc" id="L2452">      mapConstructionItem.put(MAPPING_VALUE_CONDITION, condition);</span>
<span class="nc" id="L2453">      mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="nc" id="L2454">      mapConstructionItem.put(MAPPING_VALUE_NOT, not);</span>
<span class="nc" id="L2455">      conditions.add(mapConstructionItem);</span>
<span class="nc" id="L2456">    }</span>

    /**
     * Payload text.
     *
     * @param mappingToken the mapping token
     * @param filter the filter
     */
    private void payloadText(MtasParserMappingToken mappingToken,
        String filter) {
<span class="nc" id="L2466">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="nc" id="L2467">      mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_OWN);</span>
<span class="nc" id="L2468">      mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_TEXT);</span>
<span class="nc" id="L2469">      mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="nc" id="L2470">      mappingToken.payload.add(mapConstructionItem);</span>
<span class="nc" id="L2471">    }</span>

    /**
     * Adds the attribute.
     *
     * @param mappingToken the mapping token
     * @param type the type
     * @param name the name
     * @param prefix the prefix
     * @param filter the filter
     */
    private void addAttribute(MtasParserMappingToken mappingToken, String type,
        String name, String prefix, String filter) {
<span class="fc" id="L2484">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2485">      mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_OWN);</span>
<span class="fc" id="L2486">      mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_ATTRIBUTE);</span>
<span class="fc" id="L2487">      mapConstructionItem.put(MAPPING_VALUE_NAME, name);</span>
<span class="fc" id="L2488">      mapConstructionItem.put(MAPPING_VALUE_PREFIX, prefix);</span>
<span class="fc" id="L2489">      mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="pc bpc" id="L2490" title="1 of 2 branches missed.">      if (name != null) {</span>
<span class="fc bfc" id="L2491" title="All 2 branches covered.">        if (type.equals(MAPPING_SUBTYPE_TOKEN_PRE)) {</span>
<span class="fc" id="L2492">          mappingToken.preValues.add(mapConstructionItem);</span>
<span class="pc bpc" id="L2493" title="1 of 2 branches missed.">        } else if (type.equals(MAPPING_SUBTYPE_TOKEN_POST)) {</span>
<span class="fc" id="L2494">          mappingToken.postValues.add(mapConstructionItem);</span>
        }
      }
<span class="fc" id="L2497">    }</span>

    /**
     * Adds the variable from attribute.
     *
     * @param mappingToken the mapping token
     * @param type the type
     * @param name the name
     * @param prefix the prefix
     * @param value the value
     */
    private void addVariableFromAttribute(MtasParserMappingToken mappingToken,
        String type, String name, String prefix, String value) {
<span class="nc" id="L2510">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="nc" id="L2511">      mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_OWN);</span>
<span class="nc" id="L2512">      mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_VARIABLE);</span>
<span class="nc" id="L2513">      mapConstructionItem.put(MAPPING_VALUE_NAME, name);</span>
<span class="nc" id="L2514">      mapConstructionItem.put(MAPPING_VALUE_PREFIX, prefix);</span>
<span class="nc" id="L2515">      mapConstructionItem.put(MAPPING_VALUE_VALUE, value);</span>
<span class="nc bnc" id="L2516" title="All 4 branches missed.">      if (name != null &amp;&amp; value != null) {</span>
<span class="nc bnc" id="L2517" title="All 2 branches missed.">        if (type.equals(MAPPING_SUBTYPE_TOKEN_PRE)) {</span>
<span class="nc" id="L2518">          mappingToken.preValues.add(mapConstructionItem);</span>
<span class="nc bnc" id="L2519" title="All 2 branches missed.">        } else if (type.equals(MAPPING_SUBTYPE_TOKEN_POST)) {</span>
<span class="nc" id="L2520">          mappingToken.postValues.add(mapConstructionItem);</span>
        }
      }
<span class="nc" id="L2523">    }</span>

    /**
     * Condition attribute.
     *
     * @param name the name
     * @param condition the condition
     * @param filter the filter
     * @param not the not
     */
    private void conditionAttribute(String name, String condition,
        String filter, String not) {
<span class="fc" id="L2535">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2536">      mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_OWN);</span>
<span class="fc" id="L2537">      mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_ATTRIBUTE);</span>
<span class="fc" id="L2538">      mapConstructionItem.put(MAPPING_VALUE_NAME, name);</span>
<span class="fc" id="L2539">      mapConstructionItem.put(MAPPING_VALUE_CONDITION, condition);</span>
<span class="fc" id="L2540">      mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="fc" id="L2541">      mapConstructionItem.put(MAPPING_VALUE_NOT, not);</span>
<span class="pc bpc" id="L2542" title="1 of 2 branches missed.">      if (name != null) {</span>
<span class="fc" id="L2543">        conditions.add(mapConstructionItem);</span>
      }
<span class="fc" id="L2545">    }</span>

    /**
     * Payload attribute.
     *
     * @param mappingToken the mapping token
     * @param name the name
     * @param filter the filter
     */
    private void payloadAttribute(MtasParserMappingToken mappingToken,
        String name, String filter) {
<span class="fc" id="L2556">      HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2557">      mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_OWN);</span>
<span class="fc" id="L2558">      mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_ATTRIBUTE);</span>
<span class="fc" id="L2559">      mapConstructionItem.put(MAPPING_VALUE_NAME, name);</span>
<span class="fc" id="L2560">      mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="fc" id="L2561">      mappingToken.payload.add(mapConstructionItem);</span>
<span class="fc" id="L2562">    }</span>

    /**
     * Condition ancestor.
     *
     * @param ancestorType the ancestor type
     * @param number the number
     */
    public void conditionAncestor(String ancestorType, String number) {
<span class="pc bpc" id="L2571" title="1 of 2 branches missed.">      if (ancestorType.equals(SOURCE_ANCESTOR_GROUP)</span>
<span class="pc bpc" id="L2572" title="1 of 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_GROUP_ANNOTATION)</span>
<span class="fc bfc" id="L2573" title="All 2 branches covered.">          || ancestorType.equals(SOURCE_ANCESTOR_WORD)</span>
<span class="fc bfc" id="L2574" title="All 2 branches covered.">          || ancestorType.equals(SOURCE_ANCESTOR_WORD_ANNOTATION)</span>
<span class="pc bpc" id="L2575" title="1 of 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_RELATION)</span>
<span class="nc bnc" id="L2576" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_RELATION_ANNOTATION)) {</span>
<span class="fc" id="L2577">        HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2578">        mapConstructionItem.put(MAPPING_VALUE_SOURCE, ancestorType);</span>
<span class="fc" id="L2579">        mapConstructionItem.put(MAPPING_VALUE_NUMBER, number);</span>
<span class="fc" id="L2580">        mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_EXISTENCE);</span>
<span class="fc" id="L2581">        conditions.add(mapConstructionItem);</span>
      }
<span class="fc" id="L2583">    }</span>

    /**
     * Adds the ancestor name.
     *
     * @param ancestorType the ancestor type
     * @param mappingToken the mapping token
     * @param type the type
     * @param distance the distance
     * @param prefix the prefix
     * @param filter the filter
     */
    private void addAncestorName(String ancestorType,
        MtasParserMappingToken mappingToken, String type, String distance,
        String prefix, String filter) {
<span class="pc bpc" id="L2598" title="1 of 2 branches missed.">      if (ancestorType.equals(SOURCE_ANCESTOR_GROUP)</span>
<span class="pc bpc" id="L2599" title="1 of 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_GROUP_ANNOTATION)</span>
<span class="pc bpc" id="L2600" title="1 of 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_WORD)</span>
<span class="fc bfc" id="L2601" title="All 2 branches covered.">          || ancestorType.equals(SOURCE_ANCESTOR_WORD_ANNOTATION)</span>
<span class="pc bpc" id="L2602" title="1 of 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_RELATION)</span>
<span class="nc bnc" id="L2603" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_RELATION_ANNOTATION)) {</span>
<span class="fc" id="L2604">        HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2605">        mapConstructionItem.put(MAPPING_VALUE_SOURCE, ancestorType);</span>
<span class="fc" id="L2606">        mapConstructionItem.put(MAPPING_VALUE_ANCESTOR, distance);</span>
<span class="fc" id="L2607">        mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_NAME);</span>
<span class="fc" id="L2608">        mapConstructionItem.put(MAPPING_VALUE_PREFIX, prefix);</span>
<span class="fc" id="L2609">        mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="pc bpc" id="L2610" title="1 of 2 branches missed.">        if (type.equals(MAPPING_SUBTYPE_TOKEN_PRE)) {</span>
<span class="fc" id="L2611">          mappingToken.preValues.add(mapConstructionItem);</span>
<span class="nc bnc" id="L2612" title="All 2 branches missed.">        } else if (type.equals(MAPPING_SUBTYPE_TOKEN_POST)) {</span>
<span class="nc" id="L2613">          mappingToken.postValues.add(mapConstructionItem);</span>
        }
      }
<span class="fc" id="L2616">    }</span>

    /**
     * Condition ancestor name.
     *
     * @param ancestorType the ancestor type
     * @param distance the distance
     * @param condition the condition
     * @param filter the filter
     * @param not the not
     */
    public void conditionAncestorName(String ancestorType, String distance,
        String condition, String filter, String not) {
<span class="pc bpc" id="L2629" title="1 of 2 branches missed.">      if (ancestorType.equals(SOURCE_ANCESTOR_GROUP)</span>
<span class="pc bpc" id="L2630" title="1 of 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_GROUP_ANNOTATION)</span>
<span class="pc bpc" id="L2631" title="1 of 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_WORD)</span>
<span class="fc bfc" id="L2632" title="All 2 branches covered.">          || ancestorType.equals(SOURCE_ANCESTOR_WORD_ANNOTATION)</span>
<span class="pc bpc" id="L2633" title="1 of 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_RELATION)</span>
<span class="nc bnc" id="L2634" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_RELATION_ANNOTATION)) {</span>
<span class="fc" id="L2635">        HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2636">        mapConstructionItem.put(MAPPING_VALUE_SOURCE, ancestorType);</span>
<span class="fc" id="L2637">        mapConstructionItem.put(MAPPING_VALUE_ANCESTOR, distance);</span>
<span class="fc" id="L2638">        mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_NAME);</span>
<span class="fc" id="L2639">        mapConstructionItem.put(MAPPING_VALUE_CONDITION, condition);</span>
<span class="fc" id="L2640">        mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="fc" id="L2641">        mapConstructionItem.put(MAPPING_VALUE_NOT, not);</span>
<span class="fc" id="L2642">        conditions.add(mapConstructionItem);</span>
      }
<span class="fc" id="L2644">    }</span>

    /**
     * Adds the ancestor attribute.
     *
     * @param ancestorType the ancestor type
     * @param mappingToken the mapping token
     * @param type the type
     * @param distance the distance
     * @param name the name
     * @param prefix the prefix
     * @param filter the filter
     */
    public void addAncestorAttribute(String ancestorType,
        MtasParserMappingToken mappingToken, String type, String distance,
        String name, String prefix, String filter) {
<span class="nc bnc" id="L2660" title="All 2 branches missed.">      if (ancestorType.equals(SOURCE_ANCESTOR_GROUP)</span>
<span class="nc bnc" id="L2661" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_GROUP_ANNOTATION)</span>
<span class="nc bnc" id="L2662" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_WORD)</span>
<span class="nc bnc" id="L2663" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_WORD_ANNOTATION)</span>
<span class="nc bnc" id="L2664" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_RELATION)</span>
<span class="nc bnc" id="L2665" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_RELATION_ANNOTATION)) {</span>
<span class="nc" id="L2666">        HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="nc" id="L2667">        mapConstructionItem.put(MAPPING_VALUE_SOURCE, ancestorType);</span>
<span class="nc" id="L2668">        mapConstructionItem.put(MAPPING_VALUE_ANCESTOR, distance);</span>
<span class="nc" id="L2669">        mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_ATTRIBUTE);</span>
<span class="nc" id="L2670">        mapConstructionItem.put(MAPPING_VALUE_NAME, name);</span>
<span class="nc" id="L2671">        mapConstructionItem.put(MAPPING_VALUE_PREFIX, prefix);</span>
<span class="nc" id="L2672">        mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="nc bnc" id="L2673" title="All 2 branches missed.">        if (name != null) {</span>
<span class="nc bnc" id="L2674" title="All 2 branches missed.">          if (type.equals(MAPPING_SUBTYPE_TOKEN_PRE)) {</span>
<span class="nc" id="L2675">            mappingToken.preValues.add(mapConstructionItem);</span>
<span class="nc bnc" id="L2676" title="All 2 branches missed.">          } else if (type.equals(MAPPING_SUBTYPE_TOKEN_POST)) {</span>
<span class="nc" id="L2677">            mappingToken.postValues.add(mapConstructionItem);</span>
          }
        }
      }
<span class="nc" id="L2681">    }</span>

    /**
     * Condition ancestor attribute.
     *
     * @param ancestorType the ancestor type
     * @param distance the distance
     * @param name the name
     * @param condition the condition
     * @param filter the filter
     * @param not the not
     */
    public void conditionAncestorAttribute(String ancestorType, String distance,
        String name, String condition, String filter, String not) {
<span class="nc bnc" id="L2695" title="All 2 branches missed.">      if (ancestorType.equals(SOURCE_ANCESTOR_GROUP)</span>
<span class="nc bnc" id="L2696" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_GROUP_ANNOTATION)</span>
<span class="nc bnc" id="L2697" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_WORD)</span>
<span class="nc bnc" id="L2698" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_WORD_ANNOTATION)</span>
<span class="nc bnc" id="L2699" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_RELATION)</span>
<span class="nc bnc" id="L2700" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_RELATION_ANNOTATION)) {</span>
<span class="nc" id="L2701">        HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="nc" id="L2702">        mapConstructionItem.put(MAPPING_VALUE_SOURCE, ancestorType);</span>
<span class="nc" id="L2703">        mapConstructionItem.put(MAPPING_VALUE_ANCESTOR, distance);</span>
<span class="nc" id="L2704">        mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_ATTRIBUTE);</span>
<span class="nc" id="L2705">        mapConstructionItem.put(MAPPING_VALUE_NAME, name);</span>
<span class="nc" id="L2706">        mapConstructionItem.put(MAPPING_VALUE_CONDITION, condition);</span>
<span class="nc" id="L2707">        mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="nc" id="L2708">        mapConstructionItem.put(MAPPING_VALUE_NOT, not);</span>
<span class="nc bnc" id="L2709" title="All 2 branches missed.">        if (name != null) {</span>
<span class="nc" id="L2710">          conditions.add(mapConstructionItem);</span>
        }
      }
<span class="nc" id="L2713">    }</span>

    /**
     * Payload ancestor attribute.
     *
     * @param mappingToken the mapping token
     * @param ancestorType the ancestor type
     * @param distance the distance
     * @param name the name
     * @param filter the filter
     */
    private void payloadAncestorAttribute(MtasParserMappingToken mappingToken,
        String ancestorType, String distance, String name, String filter) {
<span class="pc bpc" id="L2726" title="1 of 2 branches missed.">      if (ancestorType.equals(SOURCE_ANCESTOR_GROUP)</span>
<span class="pc bpc" id="L2727" title="1 of 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_GROUP_ANNOTATION)</span>
<span class="pc bpc" id="L2728" title="1 of 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_WORD)</span>
<span class="pc bpc" id="L2729" title="1 of 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_WORD_ANNOTATION)</span>
<span class="nc bnc" id="L2730" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_RELATION)</span>
<span class="nc bnc" id="L2731" title="All 2 branches missed.">          || ancestorType.equals(SOURCE_ANCESTOR_RELATION_ANNOTATION)) {</span>
<span class="fc" id="L2732">        HashMap&lt;String, String&gt; mapConstructionItem = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2733">        mapConstructionItem.put(MAPPING_VALUE_SOURCE, ancestorType);</span>
<span class="fc" id="L2734">        mapConstructionItem.put(MAPPING_VALUE_ANCESTOR, distance);</span>
<span class="fc" id="L2735">        mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_ATTRIBUTE);</span>
<span class="fc" id="L2736">        mapConstructionItem.put(MAPPING_VALUE_NAME, name);</span>
<span class="fc" id="L2737">        mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);</span>
<span class="pc bpc" id="L2738" title="1 of 2 branches missed.">        if (name != null) {</span>
<span class="fc" id="L2739">          mappingToken.payload.add(mapConstructionItem);</span>
        }
      }
<span class="fc" id="L2742">    }</span>

    /**
     * Compute ancestor source type.
     *
     * @param type the type
     * @return the string
     * @throws MtasConfigException the mtas config exception
     */
    private String computeAncestorSourceType(String type)
        throws MtasConfigException {
<span class="pc bpc" id="L2753" title="1 of 2 branches missed.">      if (type.equals(MAPPING_TYPE_GROUP)) {</span>
<span class="nc" id="L2754">        return SOURCE_ANCESTOR_GROUP;</span>
<span class="pc bpc" id="L2755" title="1 of 2 branches missed.">      } else if (type.equals(MAPPING_TYPE_GROUP_ANNOTATION)) {</span>
<span class="nc" id="L2756">        return SOURCE_ANCESTOR_GROUP_ANNOTATION;</span>
<span class="pc bpc" id="L2757" title="1 of 2 branches missed.">      } else if (type.equals(MAPPING_TYPE_WORD)) {</span>
<span class="nc" id="L2758">        return SOURCE_ANCESTOR_WORD;</span>
<span class="fc bfc" id="L2759" title="All 2 branches covered.">      } else if (type.equals(MAPPING_TYPE_WORD_ANNOTATION)) {</span>
<span class="fc" id="L2760">        return SOURCE_ANCESTOR_WORD_ANNOTATION;</span>
<span class="pc bpc" id="L2761" title="1 of 2 branches missed.">      } else if (type.equals(MAPPING_TYPE_RELATION)) {</span>
<span class="fc" id="L2762">        return SOURCE_ANCESTOR_RELATION;</span>
<span class="nc bnc" id="L2763" title="All 2 branches missed.">      } else if (type.equals(MAPPING_TYPE_RELATION_ANNOTATION)) {</span>
<span class="nc" id="L2764">        return SOURCE_ANCESTOR_RELATION_ANNOTATION;</span>
      } else {
<span class="nc" id="L2766">        throw new MtasConfigException(&quot;unknown type &quot; + type);</span>
      }
    }

    /**
     * Compute distance.
     *
     * @param distance the distance
     * @return the string
     */
    private String computeDistance(String distance) {
<span class="fc" id="L2777">      Integer i = 0;</span>
<span class="fc bfc" id="L2778" title="All 2 branches covered.">      if (distance != null) {</span>
<span class="fc" id="L2779">        Integer d = Integer.parseInt(distance);</span>
<span class="pc bpc" id="L2780" title="2 of 4 branches missed.">        if ((d != null) &amp;&amp; (d &gt;= i)) {</span>
<span class="fc" id="L2781">          return distance;</span>
        } else {
<span class="nc" id="L2783">          return i.toString();</span>
        }
      }
<span class="fc" id="L2786">      return null;</span>
    }

    /**
     * Compute number.
     *
     * @param number the number
     * @return the string
     */
    private String computeNumber(String number) {
<span class="fc" id="L2796">      return computeDistance(number);</span>
    }

    /**
     * Gets the tokens.
     *
     * @return the tokens
     */
    public List&lt;MtasParserMappingToken&gt; getTokens() {
<span class="fc" id="L2805">      return tokens;</span>
    }

    /**
     * Gets the conditions.
     *
     * @return the conditions
     */
    public List&lt;Map&lt;String, String&gt;&gt; getConditions() {
<span class="fc" id="L2814">      return conditions;</span>
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
<span class="nc" id="L2824">      StringBuilder builder = new StringBuilder();</span>
<span class="nc" id="L2825">      builder.append(&quot;mapping - type:&quot; + type + &quot;, offset:&quot; + offset</span>
          + &quot;, realOffset:&quot; + realOffset + &quot;, position:&quot; + position);
<span class="nc bnc" id="L2827" title="All 2 branches missed.">      for (int i = 0; i &lt; conditions.size(); i++) {</span>
<span class="nc" id="L2828">        builder.append(&quot;\n\tcondition &quot; + i + &quot;: &quot;);</span>
<span class="nc bnc" id="L2829" title="All 2 branches missed.">        for (Entry&lt;String, String&gt; entry : conditions.get(i).entrySet()) {</span>
<span class="nc" id="L2830">          builder.append(entry.getKey() + &quot;:&quot; + entry.getValue() + &quot;,&quot;);</span>
<span class="nc" id="L2831">        }</span>
      }
<span class="nc bnc" id="L2833" title="All 2 branches missed.">      for (int i = 0; i &lt; tokens.size(); i++) {</span>
<span class="nc" id="L2834">        builder.append(&quot;\n\ttoken &quot; + i);</span>
<span class="nc" id="L2835">        builder.append(&quot; - &quot; + tokens.get(i).type);</span>
<span class="nc" id="L2836">        builder.append(&quot; [offset:&quot; + tokens.get(i).offset);</span>
<span class="nc" id="L2837">        builder.append(&quot;,realoffset:&quot; + tokens.get(i).realoffset);</span>
<span class="nc" id="L2838">        builder.append(&quot;,parent:&quot; + tokens.get(i).parent + &quot;]&quot;);</span>
<span class="nc bnc" id="L2839" title="All 2 branches missed.">        for (int j = 0; j &lt; tokens.get(i).preValues.size(); j++) {</span>
<span class="nc" id="L2840">          builder.append(&quot;\n\t- pre &quot; + j + &quot;: &quot;);</span>
<span class="nc bnc" id="L2841" title="All 2 branches missed.">          for (Entry&lt;String, String&gt; entry : tokens.get(i).preValues.get(j)</span>
<span class="nc" id="L2842">              .entrySet()) {</span>
<span class="nc" id="L2843">            builder.append(entry.getKey() + &quot;:&quot; + entry.getValue() + &quot;,&quot;);</span>
<span class="nc" id="L2844">          }</span>
        }
<span class="nc bnc" id="L2846" title="All 2 branches missed.">        for (int j = 0; j &lt; tokens.get(i).postValues.size(); j++) {</span>
<span class="nc" id="L2847">          builder.append(&quot;\n\t- post &quot; + j + &quot;: &quot;);</span>
<span class="nc bnc" id="L2848" title="All 2 branches missed.">          for (Entry&lt;String, String&gt; entry : tokens.get(i).postValues.get(j)</span>
<span class="nc" id="L2849">              .entrySet()) {</span>
<span class="nc" id="L2850">            builder.append(entry.getKey() + &quot;:&quot; + entry.getValue() + &quot;,&quot;);</span>
<span class="nc" id="L2851">          }</span>
        }
<span class="nc bnc" id="L2853" title="All 2 branches missed.">        for (int j = 0; j &lt; tokens.get(i).payload.size(); j++) {</span>
<span class="nc" id="L2854">          builder.append(&quot;\n\t- payload &quot; + j + &quot;: &quot;);</span>
<span class="nc bnc" id="L2855" title="All 2 branches missed.">          for (Entry&lt;String, String&gt; entry : tokens.get(i).payload.get(j)</span>
<span class="nc" id="L2856">              .entrySet()) {</span>
<span class="nc" id="L2857">            builder.append(entry.getKey() + &quot;:&quot; + entry.getValue() + &quot;,&quot;);</span>
<span class="nc" id="L2858">          }</span>
        }
      }
<span class="nc" id="L2861">      return builder.toString();</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>