<commit_before>package org.basex.query.up.primitives;

import static org.basex.query.util.Err.*;
import static org.basex.util.Token.*;
import java.io.IOException;
import org.basex.build.DirParser;
import org.basex.build.MemBuilder;
import org.basex.core.Context;
import org.basex.data.Data;
import org.basex.data.MemData;
import org.basex.io.IO;
import org.basex.query.QueryException;
import org.basex.query.item.ANode;
import org.basex.query.item.Item;
import org.basex.query.item.NodeType;
import org.basex.query.util.DataBuilder;
import org.basex.util.InputInfo;
import org.basex.util.Util;
import org.basex.util.list.IntList;
import org.basex.util.list.ObjList;

/**
 * Add primitive.
 *
 * @author BaseX Team 2005-11, BSD License
 * @author <NAME>
 */
public final class Add extends InsertBase {
  /** Documents to add. */
  private final ObjList<Item> docs;
  /** New document name (used only for adding a single document). */
  private final byte[] name;
  /** Path to which new document(s) will be added. */
  private final byte[] path;
  /** Database context. */
  private final Context ctx;

  /**
   * Constructor.
   * @param trg target database
   * @param i input info
   * @param d document nodes to add
   * @param n document name
   * @param p document(s) path
   * @param c database context
   */
  public Add(final Data trg, final InputInfo i, final ObjList<Item> d,
      final byte[] n, final byte[] p, final Context c) {

    super(PrimitiveType.INSERTAFTER, lastDoc(trg), trg, i, null);
    docs = d;
    name = n == null || n.length == 0 ? null : n;
    path = p == null || p.length == 0 ? null : p;
    ctx = c;
  }

  @Override
  public boolean checkTextAdjacency(final int c) {
    return false;
  }

  @Override
  public void merge(final UpdatePrimitive p) {
    if(p instanceof Add) {
      for(final Item d : docs) docs.add(d);
    } else {
      Util.notexpected(p);
    }
  }

  @Override
  public void apply() {
    super.apply();
    data.insert(pre + data.size(pre, data.kind(pre)), -1, md);
    if(ctx.data != null) ctx.update();
  }

  @Override<commit_msg>[FIX] XQuery, bug fixed (introduced in recent commit)<commit_after>package org.basex.query.up.primitives;

import static org.basex.query.util.Err.*;
import static org.basex.util.Token.*;
import java.io.IOException;
import org.basex.build.DirParser;
import org.basex.build.MemBuilder;
import org.basex.core.Context;
import org.basex.data.Data;
import org.basex.data.MemData;
import org.basex.io.IO;
import org.basex.query.QueryException;
import org.basex.query.item.ANode;
import org.basex.query.item.Item;
import org.basex.query.item.NodeType;
import org.basex.query.util.DataBuilder;
import org.basex.util.InputInfo;
import org.basex.util.Util;
import org.basex.util.list.IntList;
import org.basex.util.list.ObjList;

/**
 * Add primitive.
 *
 * @author BaseX Team 2005-11, BSD License
 * @author <NAME>
 */
public final class Add extends InsertBase {
  /** Documents to add. */
  private final ObjList<Item> docs;
  /** New document name (used only for adding a single document). */
  private final byte[] name;
  /** Path to which new document(s) will be added. */
  private final byte[] path;
  /** Database context. */
  private final Context ctx;

  /**
   * Constructor.
   * @param trg target database
   * @param i input info
   * @param d document nodes to add
   * @param n document name
   * @param p document(s) path
   * @param c database context
   */
  public Add(final Data trg, final InputInfo i, final ObjList<Item> d,
      final byte[] n, final byte[] p, final Context c) {

    super(PrimitiveType.INSERTAFTER, lastDoc(trg), trg, i, null);
    docs = d;
    name = n == null || n.length == 0 ? null : n;
    path = p == null || p.length == 0 ? null : p;
    ctx = c;
  }

  @Override
  public boolean checkTextAdjacency(final int c) {
    return false;
  }

  @Override
  public void merge(final UpdatePrimitive p) {
    for(final Item d : ((Add) p).docs) docs.add(d);
  }

  @Override
  public void apply() {
    super.apply();
    data.insert(pre + data.size(pre, data.kind(pre)), -1, md);
    if(ctx.data != null) ctx.update();
  }

  @Override
{'fraction_non_alphanumeric': 0.1340379533989911, 'fraction_numerical': 0.004323804948354552, 'mean_word_length': 3.2839506172839505, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2136804', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1393, 'n_words': 406}