text:
__author__="Jason Lambert"
# (some additional corrections by Miguel Gonzalez, Yue Chun Chiu, and Andrew Jewett)
__version__="0.21"

import sys
import os
from operator import itemgetter

g_program_name    = __file__.split('/')[-1]

#  First make a copy of the \"oplsaa.prm\" file
#  (which can be downloaded from the TINKER web site).
#  The lines in this file beginning with the word \"atoms\" should
#  define the atoms which you plan to put in your simulation. All other
#  lines beginning with the word \"atoms\" should be deleted.
#  (Leave the other sections of this file alone.)
#""")

if sys.version > '3':
    import io
else:
    import cStringIO

try:
   if sys.version < '2.7':
      raise Exception('Error: Using python '+sys.version+'\n'+
                      '       Alas, your version of python is too old.\n'
                      '       You must upgrade to a newer version of python (2.7 or later).')
except Exception as err:
   sys.stderr.write('\n\n'+str(err)+'\n')
   sys.exit(-1)

#input data from file containing oplsaa force field parameters.
try:
   f=open(sys.argv[1],"r")
except:
   sys.stderr.write("Error: \n"
   "    You need to specify a file name as an input argument:\n"
   "    python oplsaa_moltemplate.py <forcefield file name>\n"
   "    (or the file name is specified incorrectly)\n")
   sys.exit()

sys.stderr.write(g_program_name+", version "+__version__+"\n"
                 "Reading parameter file...\n")

#output lt file
g=open("oplsaa.lt","w")

lines = f.readlines()

# Ignore/Comment out lines before the "##  Atom Type Definitions  ##" section.

for i in range(0, len(lines)):
   if (lines[i].find("##  Atom Type Definitions  ##") != -1):
      break
   else:
      lines[i] = '# ' + lines[i]

# As of late 2014, there appear to be 906 atom types, but we don't assume this.
# First try to infer out how many atom types there were in the original
# oplsaa.prm file, or at least find an upper bound on the atom-type numbers.
# (Keep track of the maximum value of the first column in the "atom" section.)
max_atomType = 0
num_atomTypes = 0
for line in lines:
   # skip over text after a # comment character
   ic = line.find('#')
   if ic != -1:
      line = (line[:ic]).strip()
   else:
      line = line.strip()
   # now look for lines beginning with the word "atom"
   tokens = line.split()
   if ((len(tokens)>2) and (tokens[0] == "atom")):
       num_atomTypes += 1
       if (int(tokens[1]) > max_atomType):
          max_atomType = int(tokens[1])

if num_atomTypes > 25:
   sys.stderr.write("\n"
      "(Note: If your computer freezes while running "+g_program_name+",\n"
      "       it could be because you forgot to edit the .prm file.\n"
      "       The original \"oplsaa.prm\" file distributed with TINKER has over 900 atom\n"
      "       types.  If you run "+g_program_name+" on this file, it may freeze or\n"
      "       crash.  Instead, run "+g_program_name+" on a SUBSET of the OPLS atoms\n"
      "       relevant to your problem.  To do that, delete the lines from the .prm\n"
      "       file beginning with \"atom\" which you do not need.)\n\n")

#temporary storage file
atom_lookup={} #this dictionary contains all the atom ffid's as a key and the number of atoms with that key
#atom=[[10000,10000] for i in range(906)]  <- don't assume there are 906 atoms
atom=[[-10000,-10000] for i in range(0,max_atomType+1)]
#charge_by_type={} # lookup charge by atom type
#vdw_by_type={}    # lookup epsilon & sigma paramters by atom type
charge_by_type=[0.0 for i in range(0,max_atomType+1)]    # lookup charge by atom
vdw_by_type=[(0.0,0.0) for i in range(0,max_atomType+1)] # lookup epsilon & sigma

#atom is declared this way so for sorting purposes.
#atom contains the following data upon allocation
#atom[][0]=atom_id( Important for partial charges and non_bonded interactions)
#atom[][1]=atom_ffid( Important for stretches, bending, torsions and impropers)
#atom[][2]=atom_mass
#atom[][3]=partial charge
#atom[][4]=non_bonding sigma
#atom[][5]=non_bonding epsilon
#atom[][6]=atom comment
bond=[]
#bond contains the following data
#bond[0]=atom 1 ffid
#bond[1]=atom 2 ffid
#bond[2]=bond spring constant(OPLS-aa compatible)
#bond[3]=equilibrium bond distance(Angstrom)
angle=[]
#angle contains the following data
#angle[0]=atom 1 ffid
#angle[1]=atom 2 ffid
#angle[2]=atom 3 ffid
#angle[3]=spring constant
#angle[4]=equilibrium angle (degrees)
dihedral=[]
#dihedral contains the following data
#dihedral[0]=atom 1 ffid
#dihedral[1]=atom 2 ffid
#dihedral[2]=atom 3 ffid
#dihedral[3]=atom 4 ffid
#dihedral[4]=v1
#dihedral[5]=v2
#dihedral[6]=v3
#dihedral[7]=v4
improper=[]
#improper[0]=atom 1 ffid
#improper[1]=atom 2 ffid(central atom)
#improper[2]=atom 3 ffid
#improper[3]=atom 4 ffid
#improper[4]=spring coefficient
#improper[5]=equilibrium angle

#This section gets all the parameters from the force field file
for line in lines:

   # skip over text after a # comment character
   ic = line.find('#')
   if ic != -1:
      line = (line[:ic]).strip()
   else:
      line = line.strip()

   if line.find("atom") == 0:
      line=line.split()
      atom[int(line[1])-1]=[int(line[1]),int(line[2]),float(line[-2]),
                            0.0,0.0,0.0," ".join(line[3:-2])]
   elif line.find("vdw") == 0:
      line=line.split()
      #vdw_temp.append([float(line[1]),float(line[2]),float(line[3])])
      if (int(line[1]) <= max_atomType):
         vdw_by_type[int(line[1])] = (float(line[2]),float(line[3]))
   elif line.find("bond") == 0:
      line=line.split()
      bond.append([int(line[1]),int(line[2]),float(line[3]),float(line[4])])
   elif line.find("angle") == 0:
      line=line.split()
      angle.append([int(line[1]),int(line[2]),int(line[3]),
      float(line[4]),float(line[5])])
   elif line.find("torsion") == 0:
      line=line.split()
      dihedral.append([int(line[1]),int(line[2]),int(line[3]),int(line[4]),
      float(line[5]),float(line[8]), float(line[11]), 0.0])
   elif line.find("charge") == 0:
      line=line.split()
      #charge_temp.append([int(line[1]),float(line[2])])
      if (int(line[1]) <= max_atomType):
         charge_by_type[int(line[1])] = float(line[2])
   elif line.find("imptors") == 0:
      line=line.split()
      improper.append([int(line[1]), int(line[2]),
      int(line[3]), int(line[4]), float(line[5]), float(line[6])])

#if len(atom) > 600:
#   sys.stderr.write("WARNING: The number of atom types in your file exceeds 600\n"
#                    "         (You were supposed to edit out the atoms you don't need.\n"
#                    "          Not doing this may crash your computer.)\n"
#                    "\n"
#                    "         Proceed? (Y/N): ")
#   reply = sys.stdin.readline()
#   if find(reply.strip().lower(), 'y') != 0:
#      exit(0)

#adding the charge and Lennard Jones parameters to
#to each atom type.
#----------------------------------------------#

system_is_charged = False

for i in range(0,len(atom)):
   atom_type_num = atom[i][0]
   #q = charge_by_type.get(atomTypeNum)
   #if q:
   #   atom[i][3] = q
   if atom_type_num != -10000:
      q = charge_by_type[atom_type_num]
      atom[i][3] = q
      if q != 0.0:
        # the system has some charged atoms
        system_is_charged = True

for i in range(0,len(atom)):
   atom_type_num = atom[i][0]
   #vdw_params = vdw_by_type.get(atomTypeNum)
   #if vdw_params:
   #   atom[i][4] = vdw_params[0]
   #   atom[i][5] = vdw_params[1]
   if atom_type_num != -10000:
      vdw_params = vdw_by_type[atom_type_num]
      atom[i][4] = vdw_params[0]
      atom[i][5] = vdw_params[1]

del(charge_by_type)
del(vdw_by_type)

if system_is_charged:
  pair_style = "lj/cut/coul/long"
  pair_style_params = "10.0 10.0"
  kspace_style = "    kspace_style pppm 0.0001\n"
else:
  pair_style = "lj/cut"
  pair_style_params = "10.0"
  kspace_style = ""

pair_style_command = "    pair_style hybrid "+pair_style+" "+pair_style_params+"\n"

#----------------------------------------------------------#
#begin writing content to lt file
g.write("# NOTE: This file was created automatically using:\n"
        "#       "+g_program_name+" \""+sys.argv[1]+"\"\n\n\n")

g.write("OPLSAA {\n\n" )

#write out the atom masses
#----------------------------------------------------------#
g.write("  write_once(\"Data Masses\"){\n")#checked with gaff
for i,x in enumerate(atom):
   if x[0] != -10000:
     g.write("    @atom:{} {} #{} partial charge={}\n".format(
     x[0],x[2],x[6],x[3]))
g.write("  } #(end of atom masses)\n\n")
#----------------------------------------------------------#

#write out the pair coefficients
#----------------------------------------------------------#
g.write("  write_once(\"In Settings\"){\n")#checked with gaff
for i,x in enumerate(atom):
  if x[0] != -10000:
    fmt = "    pair_coeff @atom:{0} @atom:{0} "+pair_style+" {1} {2}\n"
    g.write(fmt.format(x[0],x[5],x[4]))
g.write("  } #(end of pair coeffs)\n\n")

g.write("  write_once(\"In Charges\"){\n")#checked with gaff
for i,x in enumerate(atom):
  if x[0] != -10000:
   g.write("    set type @atom:{0} charge {1}\n".format(x[0],x[3]))
g.write("  } #(end of atom charges)\n\n")

#-----------------------------------------------------------#

# This part of the code creates a lookup dictionary
# that allows you to find every type of atom by its
# force field id. force field id is the id number
# relevant to bonds, angles, dihedrals, and impropers.
# This greatly increases the speed of angle, bond, dihedral
# and improper assignment.
#------------------------------------------------------------#
atom=sorted(atom,key=itemgetter(1))
atom_ffid=0
for x in atom:
        if x[1]==atom_ffid:
                atom_lookup[x[1]].append(x[0])
        elif x[1]>atom_ffid:
           atom_lookup[x[1]]=[x[0]]
           atom_ffid=x[1]
atom_lookup[0]=["*"]

#-------------------------------------------------------------#
#writing out the bond coefficients and bond parameters#
#-------------------------------------------------------------#

# First check if the atoms in system can potentially form bonds
might_have_bonds = False
for x in bond:
  for y in atom_lookup.get(x[0],[]):
    for z in atom_lookup.get(x[1],[]):
       might_have_bonds = True

if might_have_bonds:
  h=open("temp.txt","w+")
  g.write("  write_once(\"In Settings\") {\n")
  index1=0
  for x in bond:
    for y in atom_lookup.get(x[0],[]):
      for z in atom_lookup.get(x[1],[]):
        #g.write("    bond_coeff @bond:{}-{} harmonic {} {}\n".format(y,z,x[2]/2,x[3]))
        # Miguel Gonzales corrected this line to:
        g.write("    bond_coeff @bond:{}-{} harmonic {} {}\n".format(y,z,x[2],x[3]))
        h.write("    @bond:{0}-{1} @atom:{0} @atom:{1}\n".format(y,z))
  g.write("  } #(end of bond_coeffs)\n\n")
  h.seek(0,0)
  g.write("  write_once(\"Data Bonds By Type\") {\n")
  for line in h.readlines():
    g.write(line)
  g.write("  } #(end of bonds by type)\n\n")
  del(bond)
  h.close()

#-----------------------------------------------------------#
#writing out angle coefficients and angles by type.---------#
#-----------------------------------------------------------#

# First check if the atoms in system can potentially form angle interactions
might_have_angles = False
for x in angle:
  for y in atom_lookup.get(x[0],[]):
    for z in atom_lookup.get(x[1],[]):
      for u in atom_lookup.get(x[2],[]):
        might_have_angles = True

if might_have_angles:
  h=open("temp.txt","w+")
  g.write("  write_once(\"Data Angles By Type\"){\n")
  for x in angle:
    for y in atom_lookup.get(x[0],[]):
      for z in atom_lookup.get(x[1],[]):
        for u in atom_lookup.get(x[2],[]):
           #print(y,z,u,x)
           #h.write("    angle_coeff @angle:{}-{}-{} harmonic {} {}\n".format(y,z,u,x[3]/2.0,x[4]))
           # Miguel Gonzales corrected this line:
           h.write("    angle_coeff @angle:{}-{}-{} harmonic {} {}\n".format(y,z,u,x[3],x[4]))
           g.write("    @angle:{0}-{1}-{2} @atom:{0} @atom:{1} @atom:{2}\n".format(y,z,u))

  g.write("  } #(end of angles by type)\n\n")
  h.seek(0,0)
  g.write("  write_once(\"In Settings\" ){\n")
  for line in h.readlines():
    g.write(line)
  g.write("  } #(end of angle_coeffs)\n\n")
  del(angle)
  h.close()

#----------------------------------------------------------#
#writing dihedrals by type and dihedral coefficients-------#
#----------------------------------------------------------#

# First check if the atoms in system can potentially form dihedral interactions
might_have_dihedrals = False
for x in dihedral:
  for y in atom_lookup.get(x[0],[]):
    for z in atom_lookup.get(x[1],[]):
      for u in atom_lookup.get(x[2],[]):
        for v in atom_lookup.get(x[3],[]):
          might_have_dihedrals = True

if might_have_dihedrals:
  h=open("temp.txt","w+")
  g.write("  write_once(\"Data Dihedrals By Type\") {\n")
  #print(atom_lookup)
  for x in dihedral:
    for y in atom_lookup.get(x[0],[]):
      for z in atom_lookup.get(x[1],[]):
        for u in atom_lookup.get(x[2],[]):
          for v in atom_lookup.get(x[3],[]):
            if x[0]!=0 and x[3]!=0:
              g.write("    @dihedral:{0}-{1}-{2}-{3} @atom:{0} @atom:{1} @atom:{2} @atom:{3}\n".format(y,z,u,v))
              h.write("    dihedral_coeff @dihedral:{}-{}-{}-{} opls {} {} {} {}\n".format(y,z,u,v,x[4],x[5],x[6],x[7]))
            elif x[0]==0 and x[3]!=0:
              g.write("    @dihedral:0-{1}-{2}-{3} @atom:{0} @atom:{1} @atom:{2} @atom:{3}\n".format(
              y,z,u,v))
              h.write("    dihedral_coeff @dihedral:0-{}-{}-{} opls {} {} {} {}\n".format(z,u,v,x[4],x[5],x[6],x[7]))
            elif x[0]==0 and x[3]==0:
              g.write("    @dihedral:0-{1}-{2}-0 @atom:{0} @atom:{1} @atom:{2} @atom:{3}\n".format(y,z,u,v))
              #h.write("    dihedral_coeff @dihedral:0-{}-{}-0 harmonic {} {} {} {}\n".format(z,u,x[4],x[5],x[6],x[7]))
              h.write("    dihedral_coeff @dihedral:0-{}-{}-0 opls {} {} {} {}\n".format(z,u,x[4],x[5],x[6],x[7]))

  del(dihedral)
  g.write("  } #(end of Dihedrals by type)\n\n")
  h.seek(0,0)
  g.write("  write_once(\"In Settings\") {\n")
  for line in h.readlines():
     g.write(line)
  g.write("  } #(end of dihedral_coeffs)\n\n")
  h.close()

#-----------------------------------------------------------------------#
#----writing out improper coefficients and impropers by type------------#
#-----------------------------------------------------------------------#

# First check if the atoms in system can potentially form improper interactions
might_have_impropers = False
for x in improper:
  for y in atom_lookup.get(x[0],[]):
    for z in atom_lookup.get(x[1],[]):
      for u in atom_lookup.get(x[2],[]):
        for v in atom_lookup.get(x[3],[]):
          might_have_impropers = True

if might_have_impropers:
  h=open("temp.txt","w+")
  g.write("  write_once(\"Data Impropers By Type (opls_imp.py)\") {\n")
  for x in improper:
    for y in atom_lookup.get(x[0],[]):
      for z in atom_lookup.get(x[1],[]):
        for u in atom_lookup.get(x[2],[]):
          for v in atom_lookup.get(x[3],[]):
            # Notation: let I,J,K,L denote the atom types ("biotypes")
            #  listed in the order they appear in the "oplsaa.prm" file.
            # (I think J and L are represented by "u" and "v" in the code here.)
            # It looks like the "oplsaa.prm" file distributed with tinker
            # treats the third atom ("K") as the central atom.
            # After checking the code, it appears that the improper angle is
            # calculated as the angle between the I,J,K and the J,K,L planes
            if x[0]==0 and x[1]==0 and x[3]==0:
              g.write("    @improper:0-0-{2}-0 @atom:{0} @atom:{1} @atom:{2} @atom:{3}\n".format(y,z,u,v))
              h.write("    improper_coeff @improper:0-0-{2}-0 harmonic {4} {5} \n".format(y,z,u,v,x[4]/2,180))
            else:
              g.write("    @improper:0-0-{2}-{3} @atom:{0} @atom:{1} @atom:{2} @atom:{3}\n".format(y,z,u,v))
              h.write("    improper_coeff @improper:0-0-{2}-{3} harmonic {4} {5} \n".format(y,z,u,v,x[4]/2,180))

  g.write("  } #(end of impropers by type)\n\n")
  h.seek(0,0)
  g.write("  write_once(\"In Settings\") {\n")
  for line in h.readlines():
    g.write(line)
  g.write("  } #(end of improp_coeffs)\n\n")
  h.close()

#-----------------------------------------------------------------------#

#This section writes out the input parameters required for an opls-aa simulation
# lammps.

g.write("  write_once(\"In Init\") {\n")
g.write("    units real\n")
g.write("    atom_style full\n")
g.write("    bond_style hybrid harmonic\n")
g.write("    angle_style hybrid harmonic\n")
g.write("    dihedral_style hybrid opls\n")
g.write("    improper_style hybrid harmonic\n")
g.write(pair_style_command)
g.write("    pair_modify mix geometric\n")
g.write("    special_bonds lj/coul 0.0 0.0 0.5\n")
g.write(kspace_style)
g.write("  } #end of init parameters\n\n")
g.write("} # OPLSAA\n")
f.close()
g.close()
os.remove("temp.txt")

sys.stderr.write("...finished.\n")


text:
.. Licensed to the Apache Software Foundation (ASF) under one
.. or more contributor license agreements.  See the NOTICE file
.. distributed with this work for additional information
.. regarding copyright ownership.  The ASF licenses this file
.. to you under the Apache License, Version 2.0 (the
.. "License"); you may not use this file except in compliance
.. with the License.  You may obtain a copy of the License at

..   http://www.apache.org/licenses/LICENSE-2.0

.. Unless required by applicable law or agreed to in writing,
.. software distributed under the License is distributed on an
.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
.. KIND, either express or implied.  See the License for the
.. specific language governing permissions and limitations
.. under the License.

.. _cpp-development:

***************
C++ Development
***************

System setup
============

Arrow uses CMake as a build configuration system. We recommend building
out-of-source. If you are not familiar with this terminology:

* **In-source build**: ``cmake`` is invoked directly from the ``cpp``
  directory. This can be inflexible when you wish to maintain multiple build
  environments (e.g. one for debug builds and another for release builds)
* **Out-of-source build**: ``cmake`` is invoked from another directory,
  creating an isolated build environment that does not interact with any other
  build environment. For example, you could create ``cpp/build-debug`` and
  invoke ``cmake $CMAKE_ARGS ..`` from this directory

Building requires:

* A C++11-enabled compiler. On Linux, gcc 4.8 and higher should be
  sufficient. For Windows, at least Visual Studio 2015 is required.
* CMake 3.2 or higher
* On Linux and macOS, either ``make`` or ``ninja`` build utilities

On Ubuntu/Debian you can install the requirements with:

.. code-block:: shell

   sudo apt-get install \
        build-essential \
        cmake

On Alpine Linux:

.. code-block:: shell

   apk add autoconf \
           bash \
           cmake \
           g++ \
           gcc \
           make

On macOS, you can use `Homebrew <https://brew.sh/>`_.

.. code-block:: shell

   git clone https://github.com/apache/arrow.git
   cd arrow
   brew update && brew bundle --file=cpp/Brewfile

On MSYS2:

.. code-block:: shell

   pacman --sync --refresh --noconfirm \
     ccache \
     git \
     mingw-w64-${MSYSTEM_CARCH}-boost \
     mingw-w64-${MSYSTEM_CARCH}-brotli \
     mingw-w64-${MSYSTEM_CARCH}-cmake \
     mingw-w64-${MSYSTEM_CARCH}-double-conversion \
     mingw-w64-${MSYSTEM_CARCH}-gcc \
     mingw-w64-${MSYSTEM_CARCH}-gflags \
     mingw-w64-${MSYSTEM_CARCH}-glog \
     mingw-w64-${MSYSTEM_CARCH}-gtest \
     mingw-w64-${MSYSTEM_CARCH}-lz4 \
     mingw-w64-${MSYSTEM_CARCH}-protobuf \
     mingw-w64-${MSYSTEM_CARCH}-python3-numpy \
     mingw-w64-${MSYSTEM_CARCH}-rapidjson \
     mingw-w64-${MSYSTEM_CARCH}-snappy \
     mingw-w64-${MSYSTEM_CARCH}-thrift \
     mingw-w64-${MSYSTEM_CARCH}-uriparser \
     mingw-w64-${MSYSTEM_CARCH}-zlib \
     mingw-w64-${MSYSTEM_CARCH}-zstd

Building
========

The build system uses ``CMAKE_BUILD_TYPE=release`` by default, so if this
argument is omitted then a release build will be produced.

.. note::

   You need to more options to build on Windows. See
   :ref:`developers-cpp-windows` for details.

Minimal release build:

.. code-block:: shell

   git clone https://github.com/apache/arrow.git
   cd arrow/cpp
   mkdir release
   cd release
   cmake ..
   make

Minimal debug build with unit tests:

.. code-block:: shell

   git clone https://github.com/apache/arrow.git
   cd arrow/cpp
   mkdir debug
   cd debug
   cmake -DCMAKE_BUILD_TYPE=Debug -DARROW_BUILD_TESTS=ON ..
   make unittest

The unit tests are not built by default. After building, one can also invoke
the unit tests using the ``ctest`` tool provided by CMake (not that ``test``
depends on ``python`` being available).

On some Linux distributions, running the test suite might require setting an
explicit locale. If you see any locale-related errors, try setting the
environment variable (which requires the `locales` package or equivalent):

.. code-block:: shell

   export LC_ALL="en_US.UTF-8"

Faster builds with Ninja
~~~~~~~~~~~~~~~~~~~~~~~~

Many contributors use the `Ninja build system <https://ninja-build.org/>`_ to
get faster builds. It especially speeds up incremental builds. To use
``ninja``, pass ``-GNinja`` when calling ``cmake`` and then use the ``ninja``
command instead of ``make``.

Optional Components
~~~~~~~~~~~~~~~~~~~

By default, the C++ build system creates a fairly minimal build. We have
several optional system components which you can opt into building by passing
boolean flags to ``cmake``.

* ``-DARROW_CUDA=ON``: CUDA integration for GPU development. Depends on NVIDIA
  CUDA toolkit. The CUDA toolchain used to build the library can be customized
  by using the ``$CUDA_HOME`` environment variable.
* ``-DARROW_FLIGHT=ON``: Arrow Flight RPC system, which depends at least on
  gRPC
* ``-DARROW_GANDIVA=ON``: Gandiva expression compiler, depends on LLVM,
  Protocol Buffers, and re2
* ``-DARROW_GANDIVA_JAVA=ON``: Gandiva JNI bindings for Java
* ``-DARROW_HDFS=ON``: Arrow integration with libhdfs for accessing the Hadoop
  Filesystem
* ``-DARROW_HIVESERVER2=ON``: Client library for HiveServer2 database protocol
* ``-DARROW_ORC=ON``: Arrow integration with Apache ORC
* ``-DARROW_PARQUET=ON``: Apache Parquet libraries and Arrow integration
* ``-DARROW_PLASMA=ON``: Plasma Shared Memory Object Store
* ``-DARROW_PLASMA_JAVA_CLIENT=ON``: Build Java client for Plasma
* ``-DARROW_PYTHON=ON``: Arrow Python C++ integration library (required for
  building pyarrow). This library must be built against the same Python version
  for which you are building pyarrow, e.g. Python 2.7 or Python 3.6. NumPy must
  also be installed.
* ``-DARROW_WITH_BZ2=ON``: Build support for BZ2 compression
* ``-DARROW_WITH_ZLIB=ON``: Build suport for zlib (gzip) compression
* ``-DARROW_WITH_LZ4=ON``: Build suport for lz4 compression
* ``-DARROW_WITH_SNAPPY=ON``: Build suport for Snappy compression
* ``-DARROW_WITH_ZSTD=ON``: Build suport for ZSTD compression
* ``-DARROW_WITH_BROTLI=ON``: Build suport for Brotli compression

Some features of the core Arrow shared library can be switched off for improved
build times if they are not required for your application:

* ``-DARROW_COMPUTE=ON``: build the in-memory analytics module
* ``-DARROW_IPC=ON``: build the IPC extensions

CMake version requirements
~~~~~~~~~~~~~~~~~~~~~~~~~~

While we support CMake 3.2 and higher, some features require a newer version of
CMake:

* Building the benchmarks requires 3.6 or higher
* Building zstd from source requires 3.7 or higher
* Building Gandiva JNI bindings requires 3.11 or higher

LLVM and Clang Tools
~~~~~~~~~~~~~~~~~~~~

We are currently using LLVM 7 for library builds and for other developer tools
such as code formatting with ``clang-format``. LLVM can be installed via most
modern package managers (apt, yum, conda, Homebrew, chocolatey).

.. _cpp-build-dependency-management:

Build Dependency Management
===========================

The build system supports a number of third-party dependencies

  * ``BOOST``: for cross-platform support
  * ``BROTLI``: for data compression
  * ``double-conversion``: for text-to-numeric conversions
  * ``Snappy``: for data compression
  * ``gflags``: for command line utilities (formerly Googleflags)
  * ``glog``: for logging
  * ``Thrift``: Apache Thrift, for data serialization
  * ``Protobuf``: Google Protocol Buffers, for data serialization
  * ``GTEST``: Googletest, for testing
  * ``benchmark``: Google benchmark, for testing
  * ``RapidJSON``: for data serialization
  * ``ZLIB``: for data compression
  * ``BZip2``: for data compression
  * ``LZ4``: for data compression
  * ``ZSTD``: for data compression
  * ``RE2``: for regular expressions
  * ``gRPC``: for remote procedure calls
  * ``c-ares``: a dependency of gRPC
  * ``LLVM``: a dependency of Gandiva

The CMake option ``ARROW_DEPENDENCY_SOURCE`` is a global option that instructs
the build system how to resolve each dependency. There are a few options:

* ``AUTO``: try to find package in the system default locations and build from
  source if not found
* ``BUNDLED``: Building the dependency automatically from source
* ``SYSTEM``: Finding the dependency in system paths using CMake's built-in
  ``find_package`` function, or using ``pkg-config`` for packages that do not
  have this feature
* ``BREW``: Use Homebrew default paths as an alternative ``SYSTEM`` path
* ``CONDA``: Use ``$CONDA_PREFIX`` as alternative ``SYSTEM`` PATH

The default method is ``AUTO`` unless you are developing within an active conda
environment (detected by presence of the ``$CONDA_PREFIX`` environment
variable), in which case it is ``CONDA``.

Individual Dependency Resolution
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

While ``-DARROW_DEPENDENCY_SOURCE=$SOURCE`` sets a global default for all
packages, the resolution strategy can be overridden for individual packages by
setting ``-D$PACKAGE_NAME_SOURCE=..``. For example, to build Protocol Buffers
from source, set

.. code-block:: shell

   -DProtobuf_SOURCE=BUNDLED

This variable is unfortunately case-sensitive; the name used for each package
is listed above, but the most up-to-date listing can be found in
`cpp/cmake_modules/ThirdpartyToolchain.cmake <https://github.com/apache/arrow/blob/master/cpp/cmake_modules/ThirdpartyToolchain.cmake>`_.

Bundled Dependency Versions
~~~~~~~~~~~~~~~~~~~~~~~~~~~

When using the ``BUNDLED`` method to build a dependency from source, the
version number from ``cpp/thirdparty/versions.txt`` is used. There is also a
dependency source downloader script (see below), which can be used to set up
offline builds.

Boost-related Options
~~~~~~~~~~~~~~~~~~~~~

We depend on some Boost C++ libraries for cross-platform suport. In most cases,
the Boost version available in your package manager may be new enough, and the
build system will find it automatically. If you have Boost installed in a
non-standard location, you can specify it by passing
``-DBOOST_ROOT=$MY_BOOST_ROOT`` or setting the ``BOOST_ROOT`` environment
variable.

Offline Builds
~~~~~~~~~~~~~~

If you do not use the above variables to direct the Arrow build system to
preinstalled dependencies, they will be built automatically by the Arrow build
system. The source archive for each dependency will be downloaded via the
internet, which can cause issues in environments with limited access to the
internet.

To enable offline builds, you can download the source artifacts yourself and
use environment variables of the form ``ARROW_$LIBRARY_URL`` to direct the
build system to read from a local file rather than accessing the internet.

To make this easier for you, we have prepared a script
``thirdparty/download_dependencies.sh`` which will download the correct version
of each dependency to a directory of your choosing. It will print a list of
bash-style environment variable statements at the end to use for your build
script.

.. code-block:: shell

   # Download tarballs into $HOME/arrow-thirdparty
   $ ./thirdparty/download_dependencies.sh $HOME/arrow-thirdparty

You can then invoke CMake to create the build directory and it will use the
declared environment variable pointing to downloaded archives instead of
downloading them (one for each build dir!).

General C++ Development
=======================

This section provides information for developers who wish to contribute to the
C++ codebase.

.. note::

   Since most of the project's developers work on Linux or macOS, not all
   features or developer tools are uniformly supported on Windows. If you are
   on Windows, have a look at :ref:`developers-cpp-windows`.

Compiler warning levels
~~~~~~~~~~~~~~~~~~~~~~~

The ``BUILD_WARNING_LEVEL`` CMake option switches between sets of predetermined
compiler warning levels that we use for code tidiness. For release builds, the
default warning level is ``PRODUCTION``, while for debug builds the default is
``CHECKIN``.

When using ``CHECKIN`` for debug builds, ``-Werror`` is added when using gcc
and clang, causing build failures for any warning, and ``/WX`` is set with MSVC
having the same effect.

Code Style, Linting, and CI
~~~~~~~~~~~~~~~~~~~~~~~~~~~

This project follows `Google's C++ Style Guide
<https://google.github.io/styleguide/cppguide.html>`_ with minor exceptions:

* We relax the line length restriction to 90 characters.
* We use the ``NULLPTR`` macro in header files (instead of ``nullptr``) defined
  in ``src/arrow/util/macros.h`` to support building C++/CLI (ARROW-1134)

Our continuous integration builds in Travis CI and Appveyor run the unit test
suites on a variety of platforms and configuration, including using
``valgrind`` to check for memory leaks or bad memory accesses. In addition, the
codebase is subjected to a number of code style and code cleanliness checks.

In order to have a passing CI build, your modified git branch must pass the
following checks:

* C++ builds with the project's active version of ``clang`` without
  compiler warnings with ``-DBUILD_WARNING_LEVEL=CHECKIN``. Note that
  there are classes of warnings (such as `-Wdocumentation`, see more
  on this below) that are not caught by `gcc`.
* C++ unit test suite with valgrind enabled, use ``-DARROW_TEST_MEMCHECK=ON``
  when invoking CMake
* Passes cpplint checks, checked with ``make lint``
* Conforms to ``clang-format`` style, checked with ``make check-format``
* Passes C++/CLI header file checks, invoked with
  ``cpp/build-support/lint_cpp_cli.py cpp/src``
* CMake files pass style checks, can be fixed by running
  ``run-cmake-format.py`` from the root of the repository. This requires Python
  3 and `cmake_format <https://github.com/cheshirekow/cmake_format>`_ (note:
  this currently does not work on Windows)

In order to account for variations in the behavior of ``clang-format`` between
major versions of LLVM, we pin the version of ``clang-format`` used (current
LLVM 7).

Depending on how you installed clang-format, the build system may not be able
to find it. You can provide an explicit path to your LLVM installation (or the
root path for the clang tools) with the environment variable
`$CLANG_TOOLS_PATH` or by passing ``-DClangTools_PATH=$PATH_TO_CLANG_TOOLS`` when
invoking CMake.

To make linting more reproducible for everyone, we provide a ``docker-compose``
target that is executable from the root of the repository:

.. code-block:: shell

   docker-compose run lint

See :ref:`integration` for more information about the project's
``docker-compose`` configuration.

API Documentation
~~~~~~~~~~~~~~~~~

We use Doxygen style comments (``///``) in header files for comments
that we wish to show up in API documentation for classes and
functions.

When using ``clang`` and building with
``-DBUILD_WARNING_LEVEL=CHECKIN``, the ``-Wdocumentation`` flag is
used which checks for some common documnetation inconsistencies, like
documenting some, but not all function parameters with ``\param``. See
the `LLVM documentation warnings section
<https://releases.llvm.org/7.0.1/tools/clang/docs/DiagnosticsReference.html#wdocumentation>`_
for more about this.

While we publish the API documentation as part of the main Sphinx-based
documentation site, you can also build the C++ API documentation anytime using
Doxygen. Run the following command from the ``cpp/apidoc`` directory:

.. code-block:: shell

   doxygen Doxyfile

This requires `Doxygen <https://www.doxygen.org>`_ to be installed.

Modular Build Targets
~~~~~~~~~~~~~~~~~~~~~

Since there are several major parts of the C++ project, we have provided
modular CMake targets for building each library component, group of unit tests
and benchmarks, and their dependencies:

* ``make arrow`` for Arrow core libraries
* ``make parquet`` for Parquet libraries
* ``make gandiva`` for Gandiva (LLVM expression compiler) libraries
* ``make plasma`` for Plasma libraries, server

To build the unit tests or benchmarks, add ``-tests`` or ``-benchmarks`` to the
target name. So ``make arrow-tests`` will build the Arrow core unit
tests. Using the ``-all`` target, e.g. ``parquet-all``, will build everything.

If you wish to only build and install one or more project subcomponents, we
have provided the CMake option ``ARROW_OPTIONAL_INSTALL`` to only install
targets that have been built. For example, if you only wish to build the
Parquet libraries, its tests, and its dependencies, you can run:

.. code-block:: shell

   cmake .. -DARROW_PARQUET=ON \
         -DARROW_OPTIONAL_INSTALL=ON \
         -DARROW_BUILD_TESTS=ON
   make parquet
   make install

If you omit an explicit target when invoking ``make``, all targets will be
built.

Benchmarking
~~~~~~~~~~~~

Follow the directions for simple build except run cmake with the
``ARROW_BUILD_BENCHMARKS`` parameter set to ``ON``:

.. code-block:: shell

    cmake -DARROW_BUILD_TESTS=ON -DARROW_BUILD_BENCHMARKS=ON ..

and instead of make unittest run either ``make; ctest`` to run both unit tests
and benchmarks or ``make benchmark`` to run only the benchmarks. Benchmark logs
will be placed in the build directory under ``build/benchmark-logs``.

You can also invoke a single benchmark executable directly:

.. code-block:: shell

   ./release/arrow-builder-benchmark

The build system uses ``CMAKE_BUILD_TYPE=release`` by default which enables
compiler optimizations. It is also recommended to disable CPU throttling or
such hardware features as "Turbo Boost" to obtain more consistent and
comparable. benchmark results

Testing with LLVM AddressSanitizer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To use AddressSanitizer (ASAN) to find bad memory accesses or leaks with LLVM,
pass ``-DARROW_USE_ASAN=ON`` when building. You must use clang to compile with
ASAN, and ``ARROW_USE_ASAN`` is mutually-exclusive with the valgrind option
``ARROW_TEST_MEMCHECK``.

Fuzz testing with libfuzzer
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fuzzers can help finding unhandled exceptions and problems with untrusted input
that may lead to crashes, security issues and undefined behavior. They do this
by generating random input data and observing the behavior of the executed
code. To build the fuzzer code, LLVM is required (GCC-based compilers won't
work). You can build them using the following code:

.. code-block:: shell

   export CC=clang
   export CXX=clang++
   cmake -DARROW_FUZZING=ON -DARROW_USE_ASAN=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
   make

``ARROW_FUZZING`` will enable building of fuzzer executables as well as enable the
addition of coverage helpers via ``ARROW_USE_COVERAGE``, so that the fuzzer can observe
the program execution.

It is also wise to enable some sanitizers like ``ARROW_USE_ASAN`` (see above), which
activates the address sanitizer. This way, we ensure that bad memory operations
provoked by the fuzzer will be found early. You may also enable other sanitizers as
well. Just keep in mind that some of them do not work together and some may result
in very long execution times, which will slow down the fuzzing procedure.

We use the ``RelWithDebInfo`` build type which is optimized ``Release`` but contains
debug information. Just using ``Debug`` would be too slow to get proper fuzzing
results and ``Release`` would make it impossible to get proper tracebacks. Also, some
bugs might (but hopefully are not) be specific to the release build due to
misoptimization.

Now you can start one of the fuzzer, e.g.:

.. code-block:: shell

   ./relwithdebinfo/arrow-ipc-fuzzing-test corpus

This will try to find a malformed input that crashes the payload. A corpus of
interesting inputs will be stored into the ``corpus`` directory. You can save and
share this with others if you want, or even pre-fill it with files to provide the
fuzzer with a warm-start. Apache provides a test corpus under
https://github.com/apache/arrow-testing. If a crash was found, the program will
show the stack trace as well as the input data. The input data will also be written
to a file named ``crash-<some id>``. After a problem was found this way, it should be
reported and fixed. Usually, the fuzzing process cannot be continued until the fix is
applied, since the fuzzer usually converts to the problem again. To debug the
underlying issue, you can use GDB:

.. code-block:: shell

   env ASAN_OPTIONS=abort_on_error=1 gdb -ex r --args ./relwithdebinfo/arrow-ipc-fuzzing-test crash-<some id>

For more options, use:

.. code-block:: shell

   ./relwithdebinfo/arrow-ipc-fuzzing-test -help=1

or visit the `libFuzzer documentation <https://llvm.org/docs/LibFuzzer.html>`_.

If you build fuzzers with ASAN, you need to set the ``ASAN_SYMBOLIZER_PATH``
environment variable to the absolute path of ``llvm-symbolizer``, which is a tool
that ships with LLVM.

.. code-block:: shell

   export ASAN_SYMBOLIZER_PATH=$(type -p llvm-symbolizer)

Note that some fuzzer builds currently reject paths with a version qualifier
(like ``llvm-sanitizer-5.0``). To overcome this, set an appropriate symlink
(here, when using LLVM 5.0):

.. code-block:: shell

   ln -sf /usr/bin/llvm-sanitizer-5.0 /usr/bin/llvm-sanitizer

There are some problems that may occur during the compilation process:

- libfuzzer was not distributed with your LLVM: ``ld: file not found: .../libLLVMFuzzer.a``
- your LLVM is too old: ``clang: error: unsupported argument 'fuzzer' to option 'fsanitize='``

Extra debugging help
~~~~~~~~~~~~~~~~~~~~

If you use the CMake option ``-DARROW_EXTRA_ERROR_CONTEXT=ON`` it will compile
the libraries with extra debugging information on error checks inside the
``RETURN_NOT_OK`` macro. In unit tests with ``ASSERT_OK``, this will yield error
outputs like:

.. code-block:: shell

   ../src/arrow/ipc/ipc-read-write-test.cc:609: Failure
   Failed
   ../src/arrow/ipc/metadata-internal.cc:508 code: TypeToFlatbuffer(fbb, *field.type(), &children, &layout, &type_enum, dictionary_memo, &type_offset)
   ../src/arrow/ipc/metadata-internal.cc:598 code: FieldToFlatbuffer(fbb, *schema.field(i), dictionary_memo, &offset)
   ../src/arrow/ipc/metadata-internal.cc:651 code: SchemaToFlatbuffer(fbb, schema, dictionary_memo, &fb_schema)
   ../src/arrow/ipc/writer.cc:697 code: WriteSchemaMessage(schema_, dictionary_memo_, &schema_fb)
   ../src/arrow/ipc/writer.cc:730 code: WriteSchema()
   ../src/arrow/ipc/writer.cc:755 code: schema_writer.Write(&dictionaries_)
   ../src/arrow/ipc/writer.cc:778 code: CheckStarted()
   ../src/arrow/ipc/ipc-read-write-test.cc:574 code: writer->WriteRecordBatch(batch)
   NotImplemented: Unable to convert type: decimal(19, 4)

Deprecations and API Changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We use the compiler definition ``ARROW_NO_DEPRECATED_API`` to disable APIs that
have been deprecated. It is a good practice to compile third party applications
with this flag to proactively catch and account for API changes.

Cleaning includes with include-what-you-use (IWYU)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We occasionally use Google's `include-what-you-use
<https://github.com/include-what-you-use/include-what-you-use>`_ tool, also
known as IWYU, to remove unnecessary imports. Since setting up IWYU can be a
bit tedious, we provide a ``docker-compose`` target for running it on the C++
codebase:

.. code-block:: shell

   make -f Makefile.docker build-iwyu
   docker-compose run lint

Checking for ABI and API stability
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To build ABI compliance reports, you need to install the two tools
``abi-dumper`` and ``abi-compliance-checker``.

Build Arrow C++ in Debug mode, alternatively you could use ``-Og`` which also
builds with the necessary symbols but includes a bit of code optimization.
Once the build has finished, you can generate ABI reports using:

.. code-block:: shell

   abi-dumper -lver 9 debug/libarrow.so -o ABI-9.dump

The above version number is freely selectable. As we want to compare versions,
you should now ``git checkout`` the version you want to compare it to and re-run
the above command using a different version number. Once both reports are
generated, you can build a comparision report using

.. code-block:: shell

   abi-compliance-checker -l libarrow -d1 ABI-PY-9.dump -d2 ABI-PY-10.dump

The report is then generated in ``compat_reports/libarrow`` as a HTML.

.. _developers-cpp-windows:

Debugging with Xcode on macOS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Xcode is the IDE provided with macOS and can be use to develop and debug Arrow
by generating an Xcode project:

.. code-block:: shell

   cd cpp
   mkdir xcode-build
   cd xcode-build
   cmake .. -G Xcode -DARROW_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=DEBUG
   open arrow.xcodeproj

This will generate a project and open it in the Xcode app. As an alternative,
the command ``xcodebuild`` will perform a command-line build using the
generated project. It is recommended to use the "Automatically Create Schemes"
option when first launching the project.  Selecting an auto-generated scheme
will allow you to build and run a unittest with breakpoints enabled.

Developing on Windows
=====================

Like Linux and macOS, we have worked to enable builds to work "out of the box"
with CMake for a reasonably large subset of the project.

System Setup
~~~~~~~~~~~~

Microsoft provides the free Visual Studio Community edition. When doing
development in the the shell, you must initialize the development
environment.

For Visual Studio 2015, execute the following batch script:

.. code-block:: shell

   "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

For Visual Studio 2017, the script is:

.. code-block:: shell

   "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" -arch=amd64

One can configure a console emulator like `cmder <https://cmder.net/>`_ to
automatically launch this when starting a new development console.

Using conda-forge for build dependencies
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`Miniconda <https://conda.io/miniconda.html>`_ is a minimal Python distribution
including the `conda <https://conda.io>`_ package manager. Some memers of the
Apache Arrow community participate in the maintenance of `conda-forge
<https://conda-forge.org/>`_, a community-maintained cross-platform package
repository for conda.

To use ``conda-forge`` for your C++ build dependencies on Windows, first
download and install a 64-bit distribution from the `Miniconda homepage
<https://conda.io/miniconda.html>`_

To configure ``conda`` to use the ``conda-forge`` channel by default, launch a
command prompt (``cmd.exe``) and run the command:

.. code-block:: shell

   conda config --add channels conda-forge

Now, you can bootstrap a build environment (call from the root directory of the
Arrow codebase):

.. code-block:: shell

   conda create -y -n arrow-dev --file=ci\conda_env_cpp.yml

Then "activate" this conda environment with:

.. code-block:: shell

   activate arrow-dev

If the environment has been activated, the Arrow build system will
automatically see the ``%CONDA_PREFIX%`` environment variable and use that for
resolving the build dependencies. This is equivalent to setting

.. code-block:: shell

   -DARROW_DEPENDENCY_SOURCE=SYSTEM ^
   -DARROW_PACKAGE_PREFIX=%CONDA_PREFIX%\Library

Note that these packages are only supported for release builds. If you intend
to use ``-DCMAKE_BUILD_TYPE=debug`` then you must build the packages from
source.

.. note::

   If you run into any problems using conda packages for dependencies, a very
   common problem is mixing packages from the ``defaults`` channel with those
   from ``conda-forge``. You can examine the installed packages in your
   environment (and their origin) with ``conda list``

Building using Visual Studio (MSVC) Solution Files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change working directory in ``cmd.exe`` to the root directory of Arrow and do
an out of source build by generating a MSVC solution:

.. code-block:: shell

   cd cpp
   mkdir build
   cd build
   cmake .. -G "Visual Studio 14 2015 Win64" ^
         -DARROW_BUILD_TESTS=ON
   cmake --build . --config Release

Building with Ninja and clcache
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The `Ninja <https://ninja-build.org/>`_ build system offsets better build
parallelization, and the optional `clcache
<https://github.com/frerich/clcache/>`_ compiler cache which keeps track of
past compilations to avoid running them over and over again (in a way similar
to the Unix-specific ``ccache``).

Activate your conda build environment to first install those utilities:

.. code-block:: shell

   activate arrow-dev
   conda install -c conda-forge ninja
   pip install git+https://github.com/frerich/clcache.git

Change working directory in ``cmd.exe`` to the root directory of Arrow and
do an out of source build by generating Ninja files:

.. code-block:: shell

   cd cpp
   mkdir build
   cd build
   cmake -G "Ninja" -DARROW_BUILD_TESTS=ON ^
         -DGTest_SOURCE=BUNDLED ..
   cmake --build . --config Release

Building with NMake
~~~~~~~~~~~~~~~~~~~

Change working directory in ``cmd.exe`` to the root directory of Arrow and
do an out of source build using ``nmake``:

.. code-block:: shell

   cd cpp
   mkdir build
   cd build
   cmake -G "NMake Makefiles" ..
   nmake

Building on MSYS2
~~~~~~~~~~~~~~~~~

You can build on MSYS2 terminal, ``cmd.exe`` or PowerShell terminal.

On MSYS2 terminal:

.. code-block:: shell

   cd cpp
   mkdir build
   cd build
   cmake -G "MSYS Makefiles" ..
   make

On ``cmd.exe`` or PowerShell terminal, you can use the following batch
file:

.. code-block:: batch

   setlocal

   REM For 64bit
   set MINGW_PACKAGE_PREFIX=mingw-w64-x86_64
   set MINGW_PREFIX=c:\msys64\mingw64
   set MSYSTEM=MINGW64

   set PATH=%MINGW_PREFIX%\bin;c:\msys64\usr\bin;%PATH%

   rmdir /S /Q cpp\build
   mkdir cpp\build
   pushd cpp\build
   cmake -G "MSYS Makefiles" .. || exit /B
   make || exit /B
   popd

Debug builds
~~~~~~~~~~~~

To build Debug version of Arrow you should have pre-installed a Debug version
of Boost. It's recommended to configure cmake build with the following
variables for Debug build:

* ``-DARROW_BOOST_USE_SHARED=OFF``: enables static linking with boost debug
  libs and simplifies run-time loading of 3rd parties
* ``-DBOOST_ROOT``: sets the root directory of boost libs. (Optional)
* ``-DBOOST_LIBRARYDIR``: sets the directory with boost lib files. (Optional)

The command line to build Arrow in Debug will look something like this:

.. code-block:: shell

   cd cpp
   mkdir build
   cd build
   cmake .. -G "Visual Studio 14 2015 Win64" ^
         -DARROW_BOOST_USE_SHARED=OFF ^
         -DCMAKE_BUILD_TYPE=Debug ^
         -DBOOST_ROOT=C:/local/boost_1_63_0  ^
         -DBOOST_LIBRARYDIR=C:/local/boost_1_63_0/lib64-msvc-14.0
   cmake --build . --config Debug

Windows dependency resolution issues
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Because Windows uses ``.lib`` files for both static and dynamic linking of
dependencies, the static library sometimes may be named something different
like ``%PACKAGE%_static.lib`` to distinguish itself. If you are statically
linking some dependencies, we provide some options

* ``-DBROTLI_MSVC_STATIC_LIB_SUFFIX=%BROTLI_SUFFIX%``
* ``-DSNAPPY_MSVC_STATIC_LIB_SUFFIX=%SNAPPY_SUFFIX%``
* ``-LZ4_MSVC_STATIC_LIB_SUFFIX=%LZ4_SUFFIX%``
* ``-ZSTD_MSVC_STATIC_LIB_SUFFIX=%ZSTD_SUFFIX%``

To get the latest build instructions, you can reference `ci/appveyor-built.bat
<https://github.com/apache/arrow/blob/master/ci/appveyor-cpp-build.bat>`_,
which is used by automated Appveyor builds.

Statically linking to Arrow on Windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The Arrow headers on Windows static library builds (enabled by the CMake
option ``ARROW_BUILD_STATIC``) use the preprocessor macro ``ARROW_STATIC`` to
suppress dllimport/dllexport marking of symbols. Projects that statically link
against Arrow on Windows additionally need this definition. The Unix builds do
not use the macro.

Replicating Appveyor Builds
~~~~~~~~~~~~~~~~~~~~~~~~~~~

For people more familiar with linux development but need to replicate a failing
appveyor build, here are some rough notes from replicating the
``Static_Crt_Build`` (make unittest will probably still fail but many unit
tests can be made with there individual make targets).

1. Microsoft offers trial VMs for `Windows with Microsoft Visual Studio
   <https://developer.microsoft.com/en-us/windows/downloads/virtual-machines>`_.
   Download and install a version.
2. Run the VM and install CMake and Miniconda or Anaconda (these instructions
   assume Anaconda).
3. Download `pre-built Boost debug binaries
   <https://sourceforge.net/projects/boost/files/boost-binaries/>`_ and install
   it (run from command prompt opened by "Developer Command Prompt for MSVC
   2017"):

.. code-block:: shell

   cd $EXTRACT_BOOST_DIRECTORY
   .\bootstrap.bat
   @rem This is for static libraries needed for static_crt_build in appvyor
   .\b2 link=static -with-filesystem -with-regex -with-system install
   @rem this should put libraries and headers in c:\Boost

4. Activate ananaconda/miniconda:

.. code-block:: shell

  @rem this might differ for miniconda
  C:\Users\User\Anaconda3\Scripts\activate

5. Clone and change directories to the arrow source code (you might need to
   install git).
6. Setup environment variables:

.. code-block:: shell

   @rem Change the build type based on which appveyor job you want.
   SET JOB=Static_Crt_Build
   SET GENERATOR=Ninja
   SET APPVEYOR_BUILD_WORKER_IMAGE=Visual Studio 2017
   SET USE_CLCACHE=false
   SET ARROW_BUILD_GANDIVA=OFF
   SET ARROW_LLVM_VERSION=7.0.*
   SET PYTHON=3.6
   SET ARCH=64
   SET PATH=C:\Users\User\Anaconda3;C:\Users\User\Anaconda3\Scripts;C:\Users\User\Anaconda3\Library\bin;%PATH%
   SET BOOST_LIBRARYDIR=C:\Boost\lib
   SET BOOST_ROOT=C:\Boost

7. Run appveyor scripts:

.. code-block:: shell

   .\ci\appveyor-install.bat
   @rem this might fail but at this point most unit tests should be buildable by there individual targets
   @rem see next line for example.
   .\ci\appveyor-build.bat
   cmake --build . --config Release --target arrow-compute-hash-test

Apache Parquet Development
==========================

To build the C++ libraries for Apache Parquet, add the flag
``-DARROW_PARQUET=ON`` when invoking CMake. The Parquet libraries and unit tests
can be built with the ``parquet`` make target:

.. code-block:: shell

   make parquet

On Linux and macOS if you do not have Apache Thrift installed on your system,
or you are building with ``-DThrift_SOURCE=BUNDLED``, you must install
``bison`` and ``flex`` packages. On Windows we handle these build dependencies
automatically when building Thrift from source.

Running ``ctest -L unittest`` will run all built C++ unit tests, while ``ctest -L
parquet`` will run only the Parquet unit tests. The unit tests depend on an
environment variable ``PARQUET_TEST_DATA`` that depends on a git submodule to the
repository https://github.com/apache/parquet-testing:

.. code-block:: shell

   git submodule update --init
   export PARQUET_TEST_DATA=$ARROW_ROOT/cpp/submodules/parquet-testing/data

Here ``$ARROW_ROOT`` is the absolute path to the Arrow codebase.

Arrow Flight RPC
================

In addition to the Arrow dependencies, Flight requires:

* gRPC (>= 1.14, roughly)
* Protobuf (>= 3.6, earlier versions may work)
* c-ares (used by gRPC)

By default, Arrow will try to download and build these dependencies
when building Flight.

The optional ``flight`` libraries and tests can be built by passing
``-DARROW_FLIGHT=ON``.

.. code-block:: shell

   cmake .. -DARROW_FLIGHT=ON -DARROW_BUILD_TESTS=ON
   make

You can also use existing installations of the extra dependencies.
When building, set the environment variables ``gRPC_ROOT`` and/or
``Protobuf_ROOT`` and/or ``c-ares_ROOT``.

We are developing against recent versions of gRPC, and the versions. The
``grpc-cpp`` package available from https://conda-forge.org/ is one reliable
way to obtain gRPC in a cross-platform way. You may try using system libraries
for gRPC and Protobuf, but these are likely to be too old. On macOS, you can
try `Homebrew <https://brew.sh/>`_:

.. code-block:: shell

   brew install grpc

Development Conventions
=======================

This section provides some information about some of the abstractions and
development approaches we use to solve problems common to many parts of the C++
project.

File Naming
~~~~~~~~~~~

C++ source and header files should use underscores for word separation, not hyphens.
Compiled executables, however, will automatically use hyphens (such that
e.g. ``src/arrow/scalar_test.cc`` will be compiled into ``arrow-scalar-test``).

C++ header files use the ``.h`` extension. Any header file name not
containing ``internal`` is considered to be a public header, and will be
automatically installed by the build.

Memory Pools
~~~~~~~~~~~~

We provide a default memory pool with ``arrow::default_memory_pool()``. As a
matter of convenience, some of the array builder classes have constructors
which use the default pool without explicitly passing it. One can override the
default optional memory pool by defining the ``ARROW_MEMORY_POOL_DEFAULT``
macro to an assignment of a global function,
e.g. ``= my_default_memory_pool()``.

Error Handling and Exceptions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For error handling, we return ``arrow::Status`` values instead of throwing C++
exceptions. Since the Arrow C++ libraries are intended to be useful as a
component in larger C++ projects, using ``Status`` objects can help with good
code hygiene by making explicit when a function is expected to be able to fail.

A more recent option is to return a ``arrow::Result<T>`` object that can
represent either a successful result with a ``T`` value, or an error result
with a ``Status`` value.

For expressing internal invariants and "cannot fail" errors, we use ``DCHECK`` macros
defined in ``arrow/util/logging.h``. These checks are disabled in release builds
and are intended to catch internal development errors, particularly when
refactoring. These macros are not to be included in any public header files.

Since we do not use exceptions, we avoid doing expensive work in object
constructors. Objects that are expensive to construct may often have private
constructors, with public static factory methods that return ``Status`` or
``Result<T>``.

There are a number of object constructors, like ``arrow::Schema`` and
``arrow::RecordBatch`` where larger STL container objects like ``std::vector`` may
be created. While it is possible for ``std::bad_alloc`` to be thrown in these
constructors, the circumstances where they would are somewhat esoteric, and it
is likely that an application would have encountered other more serious
problems prior to having ``std::bad_alloc`` thrown in a constructor.

redpajama_set_name: RedPajamaGithub


text:
When /^I start an empty Transfer Of Funds document$/ do
  @transfer_of_funds = create TransferOfFundsObject
end


text:
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace MixedRealityToolkit.Utilities
{
    /// <summary>
    /// Min-heap priority queue. In other words, lower priorities will be removed from the queue first.
    /// See http://en.wikipedia.org/wiki/Binary_heap for more info.
    /// </summary>
    /// <typeparam name="TPriority">Type for the priority used for ordering.</typeparam>
    /// <typeparam name="TValue">Type of values in the queue.</typeparam>
    class PriorityQueue<TPriority, TValue> : IEnumerable<KeyValuePair<TPriority, TValue>>
    {
        public class ValueCollection : IEnumerable<TValue>
        {
            private readonly PriorityQueue<TPriority, TValue> parentCollection;

            public ValueCollection(PriorityQueue<TPriority, TValue> parentCollection)
            {
                this.parentCollection = parentCollection;
            }

            #region IEnumerable

            public IEnumerator<TValue> GetEnumerator()
            {
                foreach (KeyValuePair<TPriority, TValue> pair in parentCollection)
                {
                    yield return pair.Value;
                }
            }

            IEnumerator IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }

            #endregion
        }

        private readonly IComparer<TPriority> priorityComparer;

        public PriorityQueue() : this(Comparer<TPriority>.Default) { }

        public PriorityQueue(IComparer<TPriority> comparer)
        {
            if (comparer == null)
            {
                throw new ArgumentNullException();
            }

            priorityComparer = comparer;
        }

        private readonly List<KeyValuePair<TPriority, TValue>> queue = new List<KeyValuePair<TPriority, TValue>>();
        private ValueCollection valueCollection;

        public ValueCollection Values
        {
            get
            {
                if (valueCollection == null)
                {
                    valueCollection = new ValueCollection(this);
                }

                return valueCollection;
            }
        }

        #region IEnumerable

        public IEnumerator<KeyValuePair<TPriority, TValue>> GetEnumerator()
        {
            return queue.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion

        /// <summary>
        /// Clears the priority queue
        /// </summary>
        public void Clear()
        {
            queue.Clear();
        }

        /// <summary>
        /// Add an element to the priority queue.
        /// </summary>
        /// <param name="priority">Priority of the element</param>
        /// <param name="value"></param>
        public void Push(TPriority priority, TValue value)
        {
            queue.Add(new KeyValuePair<TPriority, TValue>(priority, value));
            BubbleUp();
        }

        /// <summary>
        /// Number of elements in priority queue
        /// </summary>
        public int Count
        {
            get
            {
                return queue.Count;
            }
        }

        /// <summary>
        /// Get the element with the minimum priority in the queue. The Key in the return value is the priority.
        /// </summary>
        public KeyValuePair<TPriority, TValue> Top
        {
            get
            {
                return queue[0];
            }
        }

        /// <summary>
        /// Pop the minimal element of the queue. Will fail at runtime if queue is empty.
        /// </summary>
        /// <returns>The minimal element</returns>
        public KeyValuePair<TPriority, TValue> Pop()
        {
            KeyValuePair<TPriority, TValue> ret = queue[0];
            queue[0] = queue[queue.Count - 1];
            queue.RemoveAt(queue.Count - 1);
            BubbleDown();
            return ret;
        }

        /// <summary>
        /// Returns whether or not the value is contained in the queue
        /// </summary>
        public bool Contains(TValue value)
        {
            return queue.Any(itm => EqualityComparer<TValue>.Default.Equals(itm.Value, value));
        }

        /// <summary>
        /// Removes the first element that equals the value from the queue
        /// </summary>
        public bool Remove(TValue value)
        {
            int idx = queue.FindIndex(itm => EqualityComparer<TValue>.Default.Equals(itm.Value, value));
            if (idx == -1)
            {
                return false;
            }

            queue[idx] = queue[queue.Count - 1];
            queue.RemoveAt(queue.Count - 1);
            BubbleDown();

            return true;
        }

        /// <summary>
        /// Removes all elements with this priority from the queue.
        /// </summary>
        /// <returns>True if elements were removed</returns>
        public bool RemoveAtPriority(TPriority priority, Predicate<TValue> shouldRemove)
        {
            bool removed = false;

            for (int i = queue.Count - 1; i >= 0; --i)
            {
                // TODO: early out if key < priority
                if (queue[i].Key.Equals(priority) && (shouldRemove == null || shouldRemove(queue[i].Value)))
                {
                    queue[i] = queue[queue.Count - 1];
                    queue.RemoveAt(queue.Count - 1);
                    BubbleDown();

                    removed = true;
                }
            }

            return removed;
        }

        /// <summary>
        /// Bubble up the last element in the queue until it's in the correct spot.
        /// </summary>
        private void BubbleUp()
        {
            int node = queue.Count - 1;
            while (node > 0)
            {
                int parent = (node - 1) >> 1;
                if (priorityComparer.Compare(queue[parent].Key, queue[node].Key) < 0)
                {
                    break; // we're in the right order, so we're done
                }
                KeyValuePair<TPriority, TValue> tmp = queue[parent];
                queue[parent] = queue[node];
                queue[node] = tmp;
                node = parent;
            }
        }

        /// <summary>
        /// Bubble down the first element until it's in the correct spot.
        /// </summary>
        private void BubbleDown()
        {
            int node = 0;
            while (true)
            {
                // Find smallest child
                int child0 = (node << 1) + 1;
                int child1 = (node << 1) + 2;
                int smallest;
                if (child0 < queue.Count && child1 < queue.Count)
                {
                    smallest = priorityComparer.Compare(queue[child0].Key, queue[child1].Key) < 0 ? child0 : child1;
                }
                else if (child0 < queue.Count)
                {
                    smallest = child0;
                }
                else if (child1 < queue.Count)
                {
                    smallest = child1;
                }
                else
                {
                    break; // 'node' is a leaf, since both children are outside the array
                }

                if (priorityComparer.Compare(queue[node].Key, queue[smallest].Key) < 0)
                {
                    break; // we're in the right order, so we're done.
                }

                KeyValuePair<TPriority, TValue> tmp = queue[node];
                queue[node] = queue[smallest];
                queue[smallest] = tmp;
                node = smallest;
            }
        }
    }
}


text:
package kafka.javaapi

import kafka.api._
import java.nio.ByteBuffer
import scala.collection.mutable
import kafka.network.{BoundedByteBufferSend, RequestChannel}
import kafka.common.ErrorMapping
import kafka.network.RequestChannel.Response

class TopicMetadataRequest(val versionId: Short,
                           override val correlationId: Int,
                           val clientId: String,
                           val topics: java.util.List[String])
    extends RequestOrResponse(Some(kafka.api.RequestKeys.MetadataKey), correlationId) {

  val underlying: kafka.api.TopicMetadataRequest = {
    import scala.collection.JavaConversions._
    new kafka.api.TopicMetadataRequest(versionId, correlationId, clientId, topics: mutable.Buffer[String])
  }

  def this(topics: java.util.List[String]) =
    this(kafka.api.TopicMetadataRequest.CurrentVersion, 0, kafka.api.TopicMetadataRequest.DefaultClientId, topics)

  def this(topics: java.util.List[String], correlationId: Int) =
    this(kafka.api.TopicMetadataRequest.CurrentVersion, correlationId, kafka.api.TopicMetadataRequest.DefaultClientId, topics)

  def writeTo(buffer: ByteBuffer) = underlying.writeTo(buffer)

  def sizeInBytes: Int = underlying.sizeInBytes()

  override def toString(): String = {
    describe(true)
  }

  override def describe(details: Boolean): String = {
    val topicMetadataRequest = new StringBuilder
    topicMetadataRequest.append("Name: " + this.getClass.getSimpleName)
    topicMetadataRequest.append("; Version: " + versionId)
    topicMetadataRequest.append("; CorrelationId: " + correlationId)
    topicMetadataRequest.append("; ClientId: " + clientId)
    if(details) {
      topicMetadataRequest.append("; Topics: ")
      val topicIterator = topics.iterator()
      while (topicIterator.hasNext) {
        val topic = topicIterator.next()
        topicMetadataRequest.append("%s".format(topic))
        if(topicIterator.hasNext)
          topicMetadataRequest.append(",")
      }
    }
    topicMetadataRequest.toString()
  }
}


text:
#ifndef ServiceWorkerError_h
#define ServiceWorkerError_h

#include "platform/heap/Handle.h"
#include "public/platform/modules/serviceworker/WebServiceWorkerError.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"

namespace blink {

class DOMException;
class ScriptPromiseResolver;

class ServiceWorkerError {
    STATIC_ONLY(ServiceWorkerError);
public:
    // For CallbackPromiseAdapter
    using WebType = const WebServiceWorkerError&;
    static DOMException* take(ScriptPromiseResolver*, const WebServiceWorkerError& webError);
};

} // namespace blink

#endif // ServiceWorkerError_h


text:
import DisplayObject = require('./DisplayObject');
import Methods = require('../util/Methods');
import DisplayType = require('../enum/DisplayType');
import Size = require('../geom/Size');
import m2 = require('../geom/Matrix2');
import Rectangle = require('../geom/Rectangle');

import TimeEvent = require('../../createts/event/TimeEvent');

/**
 * A Container is a nestable display list that allows you to work with compound display elements. For  example you could
 * group arm, leg, torso and head {{#crossLink "Bitmap"}}{{/crossLink}} instances together into a Person Container, and
 * transform them as a group, while still being able to move the individual parts relative to each other. Children of
 * containers have their transform and alpha properties concatenated with their parent
 * Container.
 *
 * For example, a {{#crossLink "Shape"}}{{/crossLink}} with x=100 and alpha=0.5, placed in a Container with x=50
 * and alpha=0.7 will be rendered to the canvas at x=150 and alpha=0.35.
 * Containers have some overhead, so you generally shouldn't create a Container to hold a single child.
 *
 *
Example

 *
 *      var container = new createjs.Container();
 *      container.addChild(bitmapInstance, shapeInstance);
 *      container.x = 100;
 *
 * @class Container
 * @extends DisplayObject
 * @constructor
 **/
class Container extends DisplayObject
{
	// public properties:
	public type:DisplayType = DisplayType.CONTAINER;

	/**
	 * The array of children in the display list. You should usually use the child management methods such as
	 * {{#crossLink "Container/addChild"}}{{/crossLink}}, {{#crossLink "Container/removeChild"}}{{/crossLink}},
	 * {{#crossLink "Container/swapChildren"}}{{/crossLink}}, etc, rather than accessing this directly, but it is
	 * included for advanced uses.
	 * @property children
	 * @type Array
	 * @default null
	 **/
	public children:any[] = [];

	/**
	 * Indicates whether the children of this container are independently enabled for mouse/pointer interaction.
	 * If false, the children will be aggregated under the container - for example, a click on a child shape would
	 * trigger a click event on the container.
	 * @property mouseChildren
	 * @type Boolean
	 * @default false
	 **/
	public mouseChildren:boolean = true;

	/**
	 * If false, the tick will not be propagated to children of this Container. This can provide some performance benefits.
	 * In addition to preventing the "tick" event from being dispatched, it will also prevent tick related updates
	 * on some display objects (ex. Sprite & MovieClip frame advancing, DOMElement visibility handling).
	 * @property tickChildren
	 * @type Boolean
	 * @default false
	 **/
	public tickChildren:boolean = true;

	private _isRenderIsolated:boolean = false;
	private _willUpdateRenderIsolation:boolean = true;

	/**
	 *
	 * @type {HTMLCanvasElement}
	 * @private
	 */
	protected _renderIsolationCanvas:HTMLCanvasElement = null;

	/**
	 * @constructor
	 * @param width {string|number}
	 * @param height {string|number}
	 * @param x {string|number}
	 * @param y {string|number}
	 * @param regX {string|number}
	 * @param regY {string|number}
	 */
	constructor(width:any = '100%', height:any = '100%', x:any = 0, y:any = 0, regX:any = 0, regY:any = 0)
	{
		super(width, height, x, y, regX, regY);
	}

	/**
	 * Returns true or false indicating whether the display object would be visible if drawn to a canvas.
	 * This does not account for whether it would be visible within the boundaries of the stage.
	 *
	 * NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
	 * @method isVisible
	 * @return {Boolean} Boolean indicating whether the display object would be visible if drawn to a canvas
	 **/
	public isVisible()
	{
		return !!(this.visible && this.alpha > 0 && this.scaleX != 0 && this.scaleY != 0 && (this.cacheCanvas || this.children.length) );
	}

	/**
	 * All render calls done in this Container are done on a seperate canvas. This way you can add multiple COMPOSITE_OPERATIONS in you draw loops.
	 * @param value
	 * @returns {Container}
	 */
	public setRenderIsolation(value:boolean):Container
	{
		if(this._isRenderIsolated && !value)
		{
			this._isRenderIsolated = value;
			this._renderIsolationCanvas = null;
		}
		else if(!this._isRenderIsolated && value)
		{
			this._isRenderIsolated = value;
			this._renderIsolationCanvas = Methods.createCanvas();
		}

		return this;
	}

	/**
	 * @method isRenderIsolated
	 * @returns {boolean}
	 */
	public isRenderIsolated():boolean
	{
		return this._isRenderIsolated
	}

	/**
	 * @method willUpdateRenderIsolation
	 * @returns {boolean}
	 */
	public willUpdateRenderIsolation():boolean
	{
		return this._willUpdateRenderIsolation
	}

	/**
	 * When set to false, no internal calls will be to update the view. Basicle it works like a cache'd container.
	 *
	 * @metho
	 * @param {boolean} value
	 */
	public setUpdateRenderIsolation(value:boolean):void
	{
		if(!this._isRenderIsolated)
		{
			throw new Error('draw calls are not isolated, first call setRenderIsolation(true)')
		}

		this._willUpdateRenderIsolation = value;
	}

	/**
	 *
	 * @method enableMouseInteraction
	 */
	public enableMouseInteraction():void
	{
		this.mouseChildren = true;
		super.enableMouseInteraction();
	}

	public disableMouseInteraction():void
	{
		this.mouseChildren = false;
		super.disableMouseInteraction();
	}

	/**
	 * Draws the display object into the specified context ignoring its visible, alpha, shadow, and transform.
	 * Returns true if the draw was handled (useful for overriding functionality).
	 *
	 * NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
	 * @method draw
	 * @param {CanvasRenderingContext2D} ctx The canvas 2D context object to draw into.
	 * @param {Boolean} [ignoreCache=false] Indicates whether the draw operation should ignore any current cache.
	 * For example, used for drawing the cache (to prevent it from simply drawing an existing cache back
	 * into itself).
	 **/
	public draw(ctx:CanvasRenderingContext2D, ignoreCache?:boolean):boolean
	{
		var localCtx:CanvasRenderingContext2D = ctx;

		if(super.draw(ctx, ignoreCache))
		{
			return true;
		}

		if(this._isRenderIsolated)
		{
			localCtx = this._renderIsolationCanvas.getContext('2d');

			if(this._willUpdateRenderIsolation)
			{
				localCtx.clearRect(0, 0, this.width, this.height);
			}
		}

		if(this._willUpdateRenderIsolation)
		{
			// this ensures we don't have issues with display list changes that occur during a draw:
			var list = this.children,
				child;

			for(var i = 0, l = list.length; i < l; i++)
			{
				child = list[i];

				if(!child.isVisible())
				{
					continue;
				}

				// draw the child:
				localCtx.save();
				child.updateContext(localCtx);
				child.draw(localCtx);
				localCtx.restore();
			}
		}

		if(this._isRenderIsolated)
		{

			ctx.drawImage(this._renderIsolationCanvas, 0, 0, this.width, this.height);

		}

		return true;
	}

	/**
	 * Adds a child to the top of the display list.
	 *
	 *
Example

	 *
	 *      container.addChild(bitmapInstance);
	 *
	 *  You can also add multiple children at once:
	 *
	 *      container.addChild(bitmapInstance, shapeInstance, textInstance);
	 *
	 * @method addChild
	 * @param {DisplayObject} child The display object to add.
	 * @return {DisplayObject} The child that was added, or the last child if multiple children were added.
	 **/
	public addChild(...children:DisplayObject[]):DisplayObject
	{
		var length = children.length;
		if(length == 0)
		{
			return null;
		}

		if(length > 1)
		{
			for(var i = 0; i < length; i++)
			{
				this.addChild(children[i]);
			}

			return children[length - 1];
		}

		var child = children[0];

		if(child.parent)
		{
			child.parent.removeChild(child);
		}

		child.parent = <Container> this;
		child.isDirty = true;

		if(this.stage)
		{
			child.stage = this.stage;
			if(child.onStageSet)
			{
				child.onStageSet.call(child);
			}
		}

		this.children.push(child);
		child.onResize(child.parent.width, child.parent.height);

		return child;
	}

	/**
	 * @method onStageSet
	 * @description When the stage is set this method is called to all its children.
	 */
	public onStageSet():void
	{
		var children = this.children;
		for(var i = 0; i < children.length; i++)
		{
			var child = children[i];

			if(child.stage != this.stage)
			{
				child.stage = this.stage;

				if(child.onStageSet)
				{
					child.onStageSet.call(child);
				}
			}
		}
	}

	/**
	 * Adds a child to the display list at the specified index, bumping children at equal or greater indexes up one, and
	 * setting its parent to this Container.
	 *
	 *
Example

	 *
	 *      addChildAt(child1, index);
	 *
	 * The index must be between 0 and numChildren. For example, to add myShape under otherShape in the display list,
	 * you could use:
	 *
	 *      container.addChildAt(myShape, container.getChildIndex(otherShape));
	 *
	 * This would also bump otherShape's index up by one. Fails silently if the index is out of range.
	 *
	 * @method addChildAt
	 * @param {DisplayObject} child The display object to add.
	 * @param {number} index The index to add the child at.
	 * @return {DisplayObject} Returns the last child that was added, or the last child if multiple children were added.
	 **/
	public addChildAt(child:DisplayObject, index:number):DisplayObject
	{
		if(child.parent)
		{
			child.parent.removeChild(child);
		}

		if(this.stage)
		{
			child.stage = this.stage;
			if(child.onStageSet)
			{
				child.onStageSet.call(child);
			}
		}

		child.parent = <Container> this;
		child.isDirty = true;

		this.children.splice(index, 0, child);
		child.onResize(this.width, this.height);

		return child;
	}

	/**
	 * Removes the specified child from the display list. Note that it is faster to use removeChildAt() if the index is
	 * already known.
	 *
	 *
Example

	 *
	 *      container.removeChild(child);
	 *
	 * You can also remove multiple children:
	 *
	 *      removeChild(child1, child2, ...);
	 *
	 * Returns true if the child (or children) was removed, or false if it was not in the display list.
	 * @method removeChild
	 * @param {DisplayObject} child The child to remove.
	 * @return {Boolean} true if the child (or children) was removed, or false if it was not in the display list.
	 **/
	public removeChild(...children:DisplayObject[]):boolean
	{
		var l = children.length;
		if(l > 1)
		{
			var good = true;
			for(var i = 0; i < l; i++)
			{
				good = good && this.removeChild(children[i]);
			}
			return good;
		}

		return this.removeChildAt(this.children.indexOf(children[0]));
	}

	/**
	 * Removes the child at the specified index from the display list, and sets its parent to null.
	 *
	 *
Example

	 *
	 *      container.removeChildAt(2);
	 *
	 * You can also remove multiple children:
	 *
	 *      container.removeChild(2, 7, ...)
	 *
	 * Returns true if the child (or children) was removed, or false if any index was out of range.
	 * @method removeChildAt
	 * @param {Number} index The index of the child to remove.
	 * @return {Boolean} true if the child (or children) was removed, or false if any index was out of range.
	 **/
	public removeChildAt(...index:number[]):boolean
	{
		var l = index.length;
		if(l > 1)
		{
			index.sort(function(a, b)
			{
				return b - a;
			});
			var good = true;
			for(var i = 0; i < l; i++)
			{
				good = good && this.removeChildAt(index[i]);
			}
			return good;
		}

		// check if remove command is valid.
		if(index[0] < 0 || index[0] > this.children.length - 1)
		{
			return false;
		}

		var child = this.children[index[0]];

		// remove parent
		if(child)
		{
			child.parent = null;
		}

		this.children.splice(index[0], 1);
		return true;
	}

	/**
	 * Removes all children from the display list.
	 *
	 *
Example

	 *
	 *      container.removeAlLChildren();
	 *
	 * @method removeAllChildren
	 **/
	public removeAllChildren()
	{
		var children = this.children;
		while(children.length)
		{
			children.pop().parent = null;
		}
	}

	/**
	 * Returns the child at the specified index.
	 *
	 *
Example

	 *
	 *      container.getChildAt(2);
	 *
	 * @method getChildAt
	 * @param {Number} index The index of the child to return.
	 * @return {DisplayObject} The child at the specified index. Returns null if there is no child at the index.
	 **/
	public getChildAt(index:number):DisplayObject
	{
		return this.children[index];
	}

	/**
	 * Returns the child with the specified name.
	 * @method getChildByName
	 * @param {String} name The name of the child to return.
	 * @return {DisplayObject} The child with the specified name.
	 **/
	public getChildByName(name:string):DisplayObject
	{
		var children = this.children;
		for(var i = 0, l = children.length; i < l; i++)
		{
			if(children[i].name == name)
			{
				return children[i];
			}
		}
		return null;
	}

	/**
	 * Performs an array sort operation on the child list.
	 *
	 *
Example: Display children with a higher y in front.

	 *
	 *      var sortFunction = function(obj1, obj2, options) {
	 *          if (obj1.y > obj2.y) { return 1; }
	 *          if (obj1.y < obj2.y) { return -1; }
	 *          return 0;
	 *      }
	 *      container.sortChildren(sortFunction);
	 *
	 * @method sortChildren
	 * @param {Function} sortFunction the function to use to sort the child list. See JavaScript's Array.sort
	 * documentation for details.
	 **/
	public sortChildren(sortFunction:(a:DisplayObject, b:DisplayObject) => number):void
	{
		this.children.sort(sortFunction);
	}

	/**
	 * Returns the index of the specified child in the display list, or -1 if it is not in the display list.
	 *
	 *
Example

	 *
	 *      var index = container.getChildIndex(child);
	 *
	 * @method getChildIndex
	 * @param {DisplayObject} child The child to return the index of.
	 * @return {Number} The index of the specified child. -1 if the child is not found.
	 **/
	public getChildIndex(child:DisplayObject):number
	{
		return this.children.indexOf(child);
	}

	/**
	 * Returns the number of children in the display list.
	 * @method getNumChildren
	 * @return {Number} The number of children in the display list.
	 **/
	public getNumChildren():number
	{
		return this.children.length;
	}

	/**
	 * Swaps the children at the specified indexes. Fails silently if either index is out of range.
	 * @method swapChildrenAt
	 * @param {Number} index1
	 * @param {Number} index2
	 **/
	public swapChildrenAt(index1:number, index2:number):void
	{
		var children = this.children;
		var o1 = children[index1];
		var o2 = children[index2];
		if(!o1 || !o2)
		{
			return;
		}
		children[index1] = o2;
		children[index2] = o1;
	}

	/**
	 * Swaps the specified children's depth in the display list. Fails silently if either child is not a child of this
	 * Container.
	 * @method swapChildren
	 * @param {DisplayObject} child0
	 * @param {DisplayObject} child1
	 **/
	public swapChildren(child0:DisplayObject, child1:DisplayObject):void
	{
		var children = this.children;
		var index1, index2;
		for(var i = 0, l = children.length; i < l; i++)
		{
			if(children[i] == child0)
			{
				index1 = i;
			}
			if(children[i] == child1)
			{
				index2 = i;
			}
			if(index1 != null && index2 != null)
			{
				break;
			}
		}
		if(i == l)
		{
			return;
		} // TODO: throw error?
		children[index1] = child1;
		children[index2] = child0;
	}

	/**
	 * Changes the depth of the specified child. Fails silently if the child is not a child of this container, or the index is out of range.
	 *
	 * @method setChildIndex
	 * @param {DisplayObject} child
	 * @param {Number} index
	 **/
	public setChildIndex(child:DisplayObject, index:number):void
	{
		var children = this.children, l = children.length;
		if(child.parent != this || index < 0 || index >= l)
		{
			return;
		}
		for(var i = 0; i < l; i++)
		{
			if(children[i] == child)
			{
				break;
			}
		}
		if(i == l || i == index)
		{
			return;
		}
		children.splice(i, 1);
		children.splice(index, 0, child);
	}

	/**
	 * Returns true if the specified display object either is this container or is a descendent (child, grandchild, etc)
	 * of this container.
	 *
	 * @method contains
	 * @param {DisplayObject} child The DisplayObject to be checked.
	 * @return {Boolean} true if the specified display object either is this container or is a descendent.
	 **/
	public contains(child:DisplayObject):boolean
	{
		while(child)
		{
			if(child == this)
			{
				return true;
			}
			child = child.parent;
		}
		return false;
	}

	/**
	 * Tests whether the display object intersects the specified local point (ie. draws a pixel with alpha > 0 at the
	 * specified position). This ignores the alpha, shadow and compositeOperation of the display object, and all
	 * transform properties including regX/Y.
	 *
	 * @method hitTest
	 * @param {Number} x The x position to check in the display object's local coordinates.
	 * @param {Number} y The y position to check in the display object's local coordinates.
	 * @return {Boolean} A Boolean indicating whether there is a visible section of a DisplayObject that overlaps the specified
	 * coordinates.
	 **/
	public hitTest(x:number, y:number):boolean
	{
		// TODO: optimize to use the fast cache check where possible.
		return (this.getObjectUnderPoint(x, y) != null);
	}

	/**
	 * Returns an array of all display objects under the specified coordinates that are in this container's display
	 * list. This routine ignores any display objects with mouseEnabled set to false. The array will be sorted in order
	 * of visual depth, with the top-most display object at index 0. This uses shape based hit detection, and can be an
	 * expensive operation to run, so it is best to use it carefully. For example, if testing for objects under the
	 * mouse, test on tick (instead of on mousemove), and only if the mouse's position has changed.
	 *
	 * Accounts for both {{#crossLink "DisplayObject/hitArea:property"}}{{/crossLink}} and {{#crossLink "DisplayObject/mask:property"}}{{/crossLink}}.
	 * @method getObjectsUnderPoint
	 * @param {Number} x The x position in the container to test.
	 * @param {Number} y The y position in the container to test.
	 * @return {Array} An Array of DisplayObjects under the specified coordinates.
	 **/
	public getObjectsUnderPoint(x:number, y:number):DisplayObject[]
	{
		var arr = [];
		var pt = this.localToGlobal(x, y);
		this._getObjectsUnderPoint(pt.x, pt.y, arr);
		return arr;
	}

	/**
	 * Similar to {{#crossLink "Container/getObjectsUnderPoint()"}}{{/crossLink}}, but returns only the top-most display
	 * object. This runs significantly faster than getObjectsUnderPoint(), but is still an expensive
	 * operation. See {{#crossLink "Container/getObjectsUnderPoint"}}{{/crossLink}} for more information.
	 * @method getObjectUnderPoint
	 * @param {Number} x The x position in the container to test.
	 * @param {Number} y The y position in the container to test.
	 * @return {DisplayObject} The top-most display object under the specified coordinates.
	 **/
	public getObjectUnderPoint(x:number, y:number):DisplayObject[]
	{
		var pt = this.localToGlobal(x, y);
		return this._getObjectsUnderPoint(pt.x, pt.y);
	}

	/**
	 * Docced in superclass.
	 */
	public getBounds()
	{
		return this._getBounds(null, true);
	}

	/**
	 * Docced in superclass.
	 */
	public getTransformedBounds()
	{
		return this._getBounds(null, true);
	}

	/**
	 * Returns a clone of this Container. Some properties that are specific to this instance's current context are
	 * reverted to their defaults (for example .parent).
	 * @method clone
	 * @param {Boolean} recursive If true, all of the descendants of this container will be cloned recursively. If false, the
	 * properties of the container will be cloned, but the new instance will not have any children.
	 * @return {Container} A clone of the current Container instance.
	 **/
	public clone(recursive:boolean):Container
	{
		var container = new Container();
		this.cloneProps(container);
		if(recursive)
		{
			var arr = container.children = [];
			for(var i = 0, l = this.children.length; i < l; i++)
			{
				var clone = this.children[i].clone(recursive);
				clone.parent = container;
				arr.push(clone);
			}
		}

		return container;
	}

	/**
	 * Returns a string representation of this object.
	 * @method toString
	 * @return {String} a string representation of the instance.
	 **/
	public toString():string
	{
		return "[Container (name=" + this.name + ")]";
	}

	public onResize(width:number, height:number):void
	{
		var oldWidth = this.width;
		var oldHeight = this.height;

		super.onResize(width, height);

		var newWidth = this.width;
		var newHeight = this.height;

		if(this._isRenderIsolated)
		{
			this._renderIsolationCanvas.width = newWidth;
			this._renderIsolationCanvas.height = newHeight;
		}

		for(var i = 0; i < this.children.length; i++)
		{
			var child = this.children[i];
			if(child.onResize)
			{
				child.onResize(newWidth, newHeight);
			}
		}

	}

	// private properties:
	/**
	 * @property DisplayObject__tick
	 * @type Function
	 * @private
	 **/
	//	p.DisplayObject__tick = p._tick;

	/**
	 * @method _tick
	 * @param {Object} props Properties to copy to the DisplayObject {{#crossLink "DisplayObject/tick"}}{{/crossLink}} event object.
	 * function.
	 * @protected
	 **/
	public onTick(delta:number):void
	{
		super.onTick(delta);

		if(this.tickChildren)
		{
			var children = this.children;
			for(var i = children.length - 1; i >= 0; i--)
			{
				var child = children[i];
				if(child.tickEnabled)
				{
					child.onTick(delta);
				}
			}

		}
	}

	/**
	 * @method _getObjectsUnderPoint
	 * @param {Number} x
	 * @param {Number} y
	 * @param {Array} arr
	 * @param {Boolean} mouse If true, it will respect mouse interaction properties like mouseEnabled, mouseChildren, and active listeners.
	 * @param {Boolean} activeListener If true, there is an active mouse event listener.
	 * @return {Array}
	 * @protected
	 **/
	public _getObjectsUnderPoint(x, y, arr?:any[], mouse?:boolean, activeListener?:boolean)
	{
		var ctx = DisplayObject._hitTestContext;
		var mtx = this._matrix;
		activeListener = activeListener || (mouse && this._hasMouseEventListener());

		// draw children one at a time, and check if we get a hit:
		var children = this.children;
		var l = children.length;
		for(var i = l - 1; i >= 0; i--)
		{
			var child = children[i];
			var hitArea = child.hitArea;
			var mask = child.mask;

			if(!child.visible || (!child.isVisible()) || (mouse && !child.mouseEnabled))
			{
				continue;
			}

			if(!hitArea && mask && mask.graphics && !mask.graphics.isEmpty())
			{
				var maskMtx = mask.getMatrix(mask._matrix).prependMatrix(this.getConcatenatedMatrix(mtx));
				ctx.setTransform(maskMtx.a, maskMtx.b, maskMtx.c, maskMtx.d, maskMtx.tx - x, maskMtx.ty - y);

				// draw the mask as a solid fill:
				mask.graphics.drawAsPath(ctx);
				ctx.fillStyle = "#000";
				ctx.fill();

				// if we don't hit the mask, then no need to keep looking at this DO:

				if(!this._testHit(ctx))
				{
					continue;
				}
				ctx.setTransform(1, 0, 0, 1, 0, 0);
				ctx.clearRect(0, 0, 2, 2);
			}

			// if a child container has a hitArea then we only need to check its hitArea, so we can treat it as a normal DO:
			if(!hitArea && child.type == DisplayType.CONTAINER)
			{
				var result = ( <Container> child)._getObjectsUnderPoint(x, y, arr, mouse, activeListener);
				if(!arr && result)
				{
					return (mouse && !this.mouseChildren) ? this : result;
				}
			}
			else
			{

				if(mouse && !activeListener && !child._hasMouseEventListener())
				{
					continue;
				}

				child.getConcatenatedMatrix(mtx);

				if(hitArea)
				{
					mtx.appendTransform(hitArea.x, hitArea.y, hitArea.scaleX, hitArea.scaleY, hitArea.rotation, hitArea.skewX, hitArea.skewY, hitArea.regX, hitArea.regY);
					mtx.alpha = hitArea.alpha;
				}

				ctx.globalAlpha = mtx.alpha;
				ctx.setTransform(mtx.a, mtx.b, mtx.c, mtx.d, mtx.tx - x, mtx.ty - y);
				(hitArea || child).draw(ctx);

				if(!this._testHit(ctx))
				{
					continue;
				}
				ctx.setTransform(1, 0, 0, 1, 0, 0);
				ctx.clearRect(0, 0, 2, 2);

				if(arr)
				{
					arr.push(child);
				}
				else
				{

					return (mouse && !this.mouseChildren) ? this : child;
				}
			}
		}

		return null;
	}

	/**
	 * @method _getBounds
	 * @param {Matrix2D} matrix
	 * @param {Boolean} ignoreTransform If true, does not apply this object's transform.
	 * @return {Rectangle}
	 * @protected
	 **/
	public _getBounds(matrix:m2.Matrix2, ignoreTransform:boolean):Rectangle
	{
		var bounds = super.getBounds();
		if(bounds)
		{
			return this._transformBounds(bounds, matrix, ignoreTransform);
		}

		var minX, maxX, minY, maxY;
		var mtx = ignoreTransform ? this._matrix.identity() : this.getMatrix(this._matrix);
		if(matrix)
		{
			mtx.prependMatrix(matrix);
		}

		var l = this.children.length;
		for(var i = 0; i < l; i++)
		{
			var child = this.children[i];
			if(!child.visible || !(bounds = child._getBounds(mtx)))
			{
				continue;
			}
			var x1 = bounds.x, y1 = bounds.y, x2 = x1 + bounds.width, y2 = y1 + bounds.height;
			if(x1 < minX || minX == null)
			{
				minX = x1;
			}
			if(x2 > maxX || maxX == null)
			{
				maxX = x2;
			}
			if(y1 < minY || minY == null)
			{
				minY = y1;
			}
			if(y2 > maxY || maxY == null)
			{
				maxY = y2;
			}
		}

		return (maxX == null) ? null : this._rectangle.setProperies(minX, minY, maxX - minX, maxY - minY);
	}

	public destruct():void
	{
		this.removeAllChildren();

		for(var i = 0; i < this.children.length; i++)
		{
			if(typeof this.children[i].destruct == 'function')
			{
				this.children[i].destruct();
			}
		}

		this.disableMouseInteraction();

		super.destruct();
	}
}

export = Container;


text:
/*
 * YatesDTASelectFilter2_0Parser.java
 * Created on Aug 15, 2006
 * Created by Michael Riffle <mriffle@u.washington.edu>
 */

package org.yeastrc.yates;

import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.yeastrc.nr_seq.NRDatabaseUtils;
import org.yeastrc.nr_seq.NRProtein;
import org.yeastrc.nr_seq.NRReference;

/**
 * Description of class goes here.
 *
 * @author Michael Riffle <mriffle@u.washington.edu>
 * @version Aug 15, 2006
 */

public class YatesDTASelectFilter2_0Parser  implements
IYatesDTASelectFilterParser {

	/* (non-Javadoc)
	 * @see org.yeastrc.yates.IYatesDTASelectFilterParser#parseFile(java.io.BufferedReader)
	 */
	public List parseFile(BufferedReader br, int databaseID) throws Exception {

		List<YatesResult> results = new ArrayList<YatesResult>();		// The list we're returning
		String line;						// The line we're parsing
		List<YatesPeptide> peptides = new ArrayList<YatesPeptide>();	// The list of peptides we're assocating with a result
		Set<YatesResult> tempResults = new HashSet<YatesResult>();	// The results we're currently parsing for peptides
		Set<NRProtein> tempProteins = new HashSet<NRProtein>();	// The proteins set in the above results
		String lastLineType = "";			// The last type of line we parsed
		boolean isZscore = false;

		// Our NR database search utils
		NRDatabaseUtils dbutils = NRDatabaseUtils.getInstance();

		/*
		 * Format of two types of lines we're interested in:
		 *
		 * FASTA Header line: Describes the result (identified protein) and experimental values:
		 * Locus	Sequence Count	Spectrum Count	Sequence Coverage	Length	MolWt	pI	Validation Status	Descriptive Name
		 * ORFP:YKR009C	2	2	1.4%	900	98703	9.0	M	FOX2 SGDID:S0001717, Chr XI from 456692-453990, reverse complement
		 *
		 * Peptide line: Describes the peptide used in the identification of a protein:
		 * Unique	FileName	XCorr	DeltCN	M+H+	CalcM+H+	TotalIntensity	SpRank	SpScore	IonProportion	Redundancy	Sequence
		 * *	kaufman028-03.1140.1140.1	2.7682	0.3597	1127.63	1128.357	10023.7	1	1027.2	62.5	1	R.VVVITGAGGGLGK.V
		 *
		 */

		while ((line = br.readLine()) != null) {
			String[] fields = line.split("\\t");

			if (fields.length == 9 || (fields.length > 2 && fields[1].equals("Proteins"))) {
				if (fields[0].equals("Locus")) continue;

				// we're on a fasta header line or have passed the data in the file

				if (lastLineType.equals("peptide")) {

					// we last encountered a peptide line.  we should save the peptides to the results, and reset the results,proteins
					for ( YatesResult result : tempResults ) {
						result.setPeptides(peptides);
						results.add(result);
					}

					// reset these
					tempResults = new HashSet<YatesResult>();
					tempProteins = new HashSet<NRProtein>();
					peptides = new ArrayList<YatesPeptide>();

					// If this isn't a fasta line, but actually a line past the data, just stop
					if (fields.length != 9) break;
				}

				// get the accession string from the fasta line
				String[] tmp = fields[0].split(" ");
				String acc = tmp[0];

				// attempt to get the reference to this accession string from the database
				NRReference ref = dbutils.getCurrentReferenceBeginWithAccessionString(acc, databaseID);
				if (ref == null)
					throw new Exception ("Unable to map a protein ID to " + acc);

				NRProtein protein = ref.getProtein();
				if (!tempProteins.contains(protein)) {

					// Add this to the set, it's not in there yet
					YatesResult result = new YatesResult();
					result.setHitProtein(ref.getProtein());
					result.setSequenceCount(Integer.parseInt(fields[1]));
					result.setSpectrumCount(Integer.parseInt(fields[2]));

					fields[3] = fields[3].replaceAll("\\%", "");
					result.setSequenceCoverage(Double.parseDouble(fields[3]));

					result.setLength(Integer.parseInt(fields[4]));
					result.setMolecularWeight(Integer.parseInt(fields[5]));
					result.setPI(Double.parseDouble(fields[6]));
					result.setValidationStatus(fields[7]);
					result.setDescription(fields[8]);

					tempResults.add(result);
					tempProteins.add(protein);
				}

				lastLineType = "fasta";

			} else if (fields.length == 13) {
				if (fields[0].equals("Unique")) {
					if (fields[9].equals( "Zscore" ))
						isZscore = true;

					continue;
				}

				// we're on a peptide line

				if (lastLineType.equals("fasta")) {
					// we've encountered a peptide line after a fasta
					peptides = new ArrayList<YatesPeptide>();
				}

				YatesPeptide pep = new YatesPeptide();
				if (fields[0].equals("*"))
					pep.setUnique(true);
				else
					pep.setUnique(false);

				pep.setFilename(fields[1]);
				pep.setXCorr(Double.parseDouble(fields[2]));
				pep.setDeltaCN(Double.parseDouble(fields[3]));
				pep.setConfPercent(Double.parseDouble(fields[4]));
				pep.setMH(Double.parseDouble(fields[5]));
				pep.setCalcMH(Double.parseDouble(fields[6]));
				pep.setTotalIntensity(Double.parseDouble(fields[7]));
				pep.setSpRank(Integer.parseInt(fields[8]));

				if (isZscore)
					pep.setZScore(Double.parseDouble(fields[9]));
				else
					pep.setSpScore(Double.parseDouble(fields[9]));

				pep.setIonProportion(Double.parseDouble(fields[10]));
				pep.setRedundancy(Integer.parseInt(fields[11]));
				pep.setSequence(fields[12]);

				// Save this peptide to the list
				peptides.add(pep);

				lastLineType = "peptide";
			} else {

				// we're on squat
				lastLineType = "squat";
				continue;
			}
		}

		return results;
	}

}


text:
<package xmlns="http://www.basex.org/modules/pkg">
   <jar>quodatum-async-0.1.4.jar</jar>
   <class>com.quodatum.async.Async</class>
</package>


text:
created: 2015-08-25 15:52:15.918955
description: The individual begins in a push-up position, with the body in a straight
  line and elbows locked.
groups: [Push]
muscles: [Shoulders, Abdominals, Core]
template: exercise.html
title: Mountain Climber
variants: []
---
The individual begins in a push-up position, with the body in a straight line and elbows locked. The left knee is brought to the chest and the left foot placed on the ground, with the right leg remaining outstretched. The individual then performs a small hop and switches the position of the feet so that the right knee is brought to the chest, the right foot placed on the ground and the left leg is extended behind the body. The exercise is then repeated, most commonly at a fast pace for a defined length of time.

## Resources

* [Wikipedia: Bodyweight exercise](https://en.wikipedia.org/wiki/Bodyweight_exercise)