text:
/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 *    SparseInstance.java
 *    Copyright (C) 2000-2012 University of Waikato, Hamilton, New Zealand
 *
 */

package weka.core;

import java.util.ArrayList;
import java.util.Enumeration;

/**
 * Class for storing an instance as a sparse vector. A sparse instance only
 * requires storage for those attribute values that are non-zero. Since the
 * objective is to reduce storage requirements for datasets with large numbers
 * of default values, this also includes nominal attributes -- the first nominal
 * value (i.e. that which has index 0) will not require explicit storage, so
 * rearrange your nominal attribute value orderings if necessary. Missing values
 * will be stored explicitly.
 *
 * @author Eibe Frank
 * @version $Revision: 10203 $
 */
public class SparseInstance extends AbstractInstance {

  /** for serialization */
  private static final long serialVersionUID = -3579051291332630149L;

  /** The index of the attribute associated with each stored value. */
  protected int[] m_Indices;

  /** The maximum number of values that can be stored. */
  protected int m_NumAttributes;

  /**
   * Constructor that generates a sparse instance from the given instance.
   * Reference to the dataset is set to null. (ie. the instance doesn't have
   * access to information about the attribute types)
   *
   * @param instance the instance from which the attribute values and the weight
   *          are to be copied
   */
  public SparseInstance(Instance instance) {

    m_Weight = instance.weight();
    m_Dataset = null;
    m_NumAttributes = instance.numAttributes();
    if (instance instanceof SparseInstance) {
      m_AttValues = ((SparseInstance) instance).m_AttValues;
      m_Indices = ((SparseInstance) instance).m_Indices;
    } else {
      double[] tempValues = new double[instance.numAttributes()];
      int[] tempIndices = new int[instance.numAttributes()];
      int vals = 0;
      for (int i = 0; i < instance.numAttributes(); i++) {
        if (instance.value(i) != 0) {
          tempValues[vals] = instance.value(i);
          tempIndices[vals] = i;
          vals++;
        }
      }
      m_AttValues = new double[vals];
      m_Indices = new int[vals];
      System.arraycopy(tempValues, 0, m_AttValues, 0, vals);
      System.arraycopy(tempIndices, 0, m_Indices, 0, vals);
    }
  }

  /**
   * Constructor that copies the info from the given instance. Reference to the
   * dataset is set to null. (ie. the instance doesn't have access to
   * information about the attribute types)
   *
   * @param instance the instance from which the attribute info is to be copied
   */
  public SparseInstance(SparseInstance instance) {

    m_AttValues = instance.m_AttValues;
    m_Indices = instance.m_Indices;
    m_Weight = instance.m_Weight;
    m_NumAttributes = instance.m_NumAttributes;
    m_Dataset = null;
  }

  /**
   * Constructor that generates a sparse instance from the given parameters.
   * Reference to the dataset is set to null. (ie. the instance doesn't have
   * access to information about the attribute types)
   *
   * @param weight the instance's weight
   * @param attValues a vector of attribute values
   */
  public SparseInstance(double weight, double[] attValues) {

    m_Weight = weight;
    m_Dataset = null;
    m_NumAttributes = attValues.length;
    double[] tempValues = new double[m_NumAttributes];
    int[] tempIndices = new int[m_NumAttributes];
    int vals = 0;
    for (int i = 0; i < m_NumAttributes; i++) {
      if (attValues[i] != 0) {
        tempValues[vals] = attValues[i];
        tempIndices[vals] = i;
        vals++;
      }
    }
    m_AttValues = new double[vals];
    m_Indices = new int[vals];
    System.arraycopy(tempValues, 0, m_AttValues, 0, vals);
    System.arraycopy(tempIndices, 0, m_Indices, 0, vals);
  }

  /**
   * Constructor that inititalizes instance variable with given values.
   * Reference to the dataset is set to null. (ie. the instance doesn't have
   * access to information about the attribute types) Note that the indices need
   * to be sorted in ascending order. Otherwise things won't work properly.
   *
   * @param weight the instance's weight
   * @param attValues a vector of attribute values (just the ones to be stored)
   * @param indices the indices of the given values in the full vector (need to
   *          be sorted in ascending order)
   * @param maxNumValues the maximium number of values that can be stored
   */
  public SparseInstance(double weight, double[] attValues, int[] indices,
    int maxNumValues) {

    int vals = 0;
    m_AttValues = new double[attValues.length];
    m_Indices = new int[indices.length];
    for (int i = 0; i < attValues.length; i++) {
      if (attValues[i] != 0) {
        m_AttValues[vals] = attValues[i];
        m_Indices[vals] = indices[i];
        vals++;
      }
    }
    if (vals != attValues.length) {
      // Need to truncate.
      double[] newVals = new double[vals];
      System.arraycopy(m_AttValues, 0, newVals, 0, vals);
      m_AttValues = newVals;
      int[] newIndices = new int[vals];
      System.arraycopy(m_Indices, 0, newIndices, 0, vals);
      m_Indices = newIndices;
    }
    m_Weight = weight;
    m_NumAttributes = maxNumValues;
    m_Dataset = null;
  }

  /**
   * Constructor of an instance that sets weight to one, all values to be
   * missing, and the reference to the dataset to null. (ie. the instance
   * doesn't have access to information about the attribute types)
   *
   * @param numAttributes the size of the instance
   */
  public SparseInstance(int numAttributes) {

    m_AttValues = new double[numAttributes];
    m_NumAttributes = numAttributes;
    m_Indices = new int[numAttributes];
    for (int i = 0; i < m_AttValues.length; i++) {
      m_AttValues[i] = Utils.missingValue();
      m_Indices[i] = i;
    }
    m_Weight = 1;
    m_Dataset = null;
  }

  /**
   * Produces a shallow copy of this instance. The copy has access to the same
   * dataset. (if you want to make a copy that doesn't have access to the
   * dataset, use new SparseInstance(instance)
   *
   * @return the shallow copy
   */
  @Override
  public Object copy() {

    SparseInstance result = new SparseInstance(this);
    result.m_Dataset = m_Dataset;
    return result;
  }

  /**
   * Returns the index of the attribute stored at the given position.
   *
   * @param position the position
   * @return the index of the attribute stored at the given position
   */
  @Override
  public int index(int position) {

    return m_Indices[position];
  }

  /**
   * Locates the greatest index that is not greater than the given index.
   *
   * @return the internal index of the attribute index. Returns -1 if no index
   *         with this property could be found
   */
  public int locateIndex(int index) {

    int min = 0, max = m_Indices.length - 1;

    if (max == -1) {
      return -1;
    }

    // Binary search
    while ((m_Indices[min] <= index) && (m_Indices[max] >= index)) {
      int current = (max + min) / 2;
      if (m_Indices[current] > index) {
        max = current - 1;
      } else if (m_Indices[current] < index) {
        min = current + 1;
      } else {
        return current;
      }
    }
    if (m_Indices[max] < index) {
      return max;
    } else {
      return min - 1;
    }
  }

  /**
   * Merges this instance with the given instance and returns the result.
   * Dataset is set to null.
   *
   * @param inst the instance to be merged with this one
   * @return the merged instances
   */
  @Override
  public Instance mergeInstance(Instance inst) {

    double[] values = new double[numValues() + inst.numValues()];
    int[] indices = new int[numValues() + inst.numValues()];

    int m = 0;
    for (int j = 0; j < numValues(); j++, m++) {
      values[m] = valueSparse(j);
      indices[m] = index(j);
    }
    for (int j = 0; j < inst.numValues(); j++, m++) {
      values[m] = inst.valueSparse(j);
      indices[m] = numAttributes() + inst.index(j);
    }

    return new SparseInstance(1.0, values, indices, numAttributes()
      + inst.numAttributes());
  }

  /**
   * Returns the number of attributes.
   *
   * @return the number of attributes as an integer
   */
  @Override
  public int numAttributes() {

    return m_NumAttributes;
  }

  /**
   * Returns the number of values in the sparse vector.
   *
   * @return the number of values
   */
  @Override
  public int numValues() {

    return m_Indices.length;
  }

  /**
   * Replaces all missing values in the instance with the values contained in
   * the given array. A deep copy of the vector of attribute values is performed
   * before the values are replaced.
   *
   * @param array containing the means and modes
   * @exception IllegalArgumentException if numbers of attributes are unequal
   */
  @Override
  public void replaceMissingValues(double[] array) {

    if ((array == null) || (array.length != m_NumAttributes)) {
      throw new IllegalArgumentException("Unequal number of attributes!");
    }
    double[] tempValues = new double[m_AttValues.length];
    int[] tempIndices = new int[m_AttValues.length];
    int vals = 0;
    for (int i = 0; i < m_AttValues.length; i++) {
      if (isMissingSparse(i)) {
        if (array[m_Indices[i]] != 0) {
          tempValues[vals] = array[m_Indices[i]];
          tempIndices[vals] = m_Indices[i];
          vals++;
        }
      } else {
        tempValues[vals] = m_AttValues[i];
        tempIndices[vals] = m_Indices[i];
        vals++;
      }
    }
    m_AttValues = new double[vals];
    m_Indices = new int[vals];
    System.arraycopy(tempValues, 0, m_AttValues, 0, vals);
    System.arraycopy(tempIndices, 0, m_Indices, 0, vals);
  }

  /**
   * Sets a specific value in the instance to the given value (internal
   * floating-point format). Performs a deep copy of the vector of attribute
   * values before the value is set.
   *
   * @param attIndex the attribute's index
   * @param value the new attribute value (If the corresponding attribute is
   *          nominal (or a string) then this is the new value's index as a
   *          double).
   */
  @Override
  public void setValue(int attIndex, double value) {

    int index = locateIndex(attIndex);

    if ((index >= 0) && (m_Indices[index] == attIndex)) {
      if (value != 0) {
        double[] tempValues = new double[m_AttValues.length];
        System.arraycopy(m_AttValues, 0, tempValues, 0, m_AttValues.length);
        tempValues[index] = value;
        m_AttValues = tempValues;
      } else {
        double[] tempValues = new double[m_AttValues.length - 1];
        int[] tempIndices = new int[m_Indices.length - 1];
        System.arraycopy(m_AttValues, 0, tempValues, 0, index);
        System.arraycopy(m_Indices, 0, tempIndices, 0, index);
        System.arraycopy(m_AttValues, index + 1, tempValues, index,
          m_AttValues.length - index - 1);
        System.arraycopy(m_Indices, index + 1, tempIndices, index,
          m_Indices.length - index - 1);
        m_AttValues = tempValues;
        m_Indices = tempIndices;
      }
    } else {
      if (value != 0) {
        double[] tempValues = new double[m_AttValues.length + 1];
        int[] tempIndices = new int[m_Indices.length + 1];
        System.arraycopy(m_AttValues, 0, tempValues, 0, index + 1);
        System.arraycopy(m_Indices, 0, tempIndices, 0, index + 1);
        tempIndices[index + 1] = attIndex;
        tempValues[index + 1] = value;
        System.arraycopy(m_AttValues, index + 1, tempValues, index + 2,
          m_AttValues.length - index - 1);
        System.arraycopy(m_Indices, index + 1, tempIndices, index + 2,
          m_Indices.length - index - 1);
        m_AttValues = tempValues;
        m_Indices = tempIndices;
      }
    }
  }

  /**
   * Sets a specific value in the instance to the given value (internal
   * floating-point format). Performs a deep copy of the vector of attribute
   * values before the value is set.
   *
   * @param indexOfIndex the index of the attribute's index
   * @param value the new attribute value (If the corresponding attribute is
   *          nominal (or a string) then this is the new value's index as a
   *          double).
   */
  @Override
  public void setValueSparse(int indexOfIndex, double value) {

    if (value != 0) {
      double[] tempValues = new double[m_AttValues.length];
      System.arraycopy(m_AttValues, 0, tempValues, 0, m_AttValues.length);
      m_AttValues = tempValues;
      m_AttValues[indexOfIndex] = value;
    } else {
      double[] tempValues = new double[m_AttValues.length - 1];
      int[] tempIndices = new int[m_Indices.length - 1];
      System.arraycopy(m_AttValues, 0, tempValues, 0, indexOfIndex);
      System.arraycopy(m_Indices, 0, tempIndices, 0, indexOfIndex);
      System.arraycopy(m_AttValues, indexOfIndex + 1, tempValues, indexOfIndex,
        m_AttValues.length - indexOfIndex - 1);
      System.arraycopy(m_Indices, indexOfIndex + 1, tempIndices, indexOfIndex,
        m_Indices.length - indexOfIndex - 1);
      m_AttValues = tempValues;
      m_Indices = tempIndices;
    }
  }

  /**
   * Returns the values of each attribute as an array of doubles.
   *
   * @return an array containing all the instance attribute values
   */
  @Override
  public double[] toDoubleArray() {

    double[] newValues = new double[m_NumAttributes];
    for (int i = 0; i < m_AttValues.length; i++) {
      newValues[m_Indices[i]] = m_AttValues[i];
    }
    return newValues;
  }

  /**
   * Returns the description of one instance in sparse format. If the instance
   * doesn't have access to a dataset, it returns the internal floating-point
   * values. Quotes string values that contain whitespace characters.
   *
   * @return the instance's description as a string
   */
  @Override
  public String toStringNoWeight() {
    return toStringNoWeight(AbstractInstance.s_numericAfterDecimalPoint);
  }

  /**
   * Returns the description of one instance in sparse format. If the instance
   * doesn't have access to a dataset, it returns the internal floating-point
   * values. Quotes string values that contain whitespace characters.
   *
   * @param afterDecimalPoint maximum number of digits permitted after the
   *          decimal point for numeric values
   *
   * @return the instance's description as a string
   */
  @Override
  public String toStringNoWeight(int afterDecimalPoint) {

    StringBuffer text = new StringBuffer();

    text.append('{');
    for (int i = 0; i < m_Indices.length; i++) {
      if (i > 0) {
        text.append(",");
      }
      if (isMissingSparse(i)) {
        text.append(m_Indices[i] + " ?");
      } else {
        if (m_Dataset == null) {
          text.append(m_Indices[i] + " "
            + Utils.doubleToString(m_AttValues[i], afterDecimalPoint));
        } else {
          if (m_Dataset.attribute(m_Indices[i]).isNominal()
            || m_Dataset.attribute(m_Indices[i]).isString()
            || m_Dataset.attribute(m_Indices[i]).isDate()) {
            try {
              text.append(m_Indices[i] + " "
                + Utils.quote(stringValue(m_Indices[i])));
            } catch (Exception e) {
              e.printStackTrace();
              System.err.println(new Instances(m_Dataset, 0));
              System.err.println("Att:" + m_Indices[i] + " Val:"
                + valueSparse(i));
              throw new Error("This should never happen!");
            }
          } else if (m_Dataset.attribute(m_Indices[i]).isRelationValued()) {
            try {
              text.append(m_Indices[i]
                + " "
                + Utils.quote(m_Dataset.attribute(m_Indices[i])
                  .relation((int) valueSparse(i)).stringWithoutHeader()));
            } catch (Exception e) {
              e.printStackTrace();
              System.err.println(new Instances(m_Dataset, 0));
              System.err.println("Att:" + m_Indices[i] + " Val:"
                + valueSparse(i));
              throw new Error("This should never happen!");
            }
          } else {
            text.append(m_Indices[i] + " "
              + Utils.doubleToString(m_AttValues[i], afterDecimalPoint));
          }
        }
      }
    }
    text.append('}');

    return text.toString();
  }

  /**
   * Returns an instance's attribute value in internal format.
   *
   * @param attIndex the attribute's index
   * @return the specified value as a double (If the corresponding attribute is
   *         nominal (or a string) then it returns the value's index as a
   *         double).
   */
  @Override
  public double value(int attIndex) {

    int index = locateIndex(attIndex);
    if ((index >= 0) && (m_Indices[index] == attIndex)) {
      return m_AttValues[index];
    } else {
      return 0.0;
    }
  }

  /**
   * Deletes an attribute at the given position (0 to numAttributes() - 1).
   *
   * @param pos the attribute's position
   */
  @Override
  protected void forceDeleteAttributeAt(int position) {

    int index = locateIndex(position);

    m_NumAttributes--;
    if ((index >= 0) && (m_Indices[index] == position)) {
      int[] tempIndices = new int[m_Indices.length - 1];
      double[] tempValues = new double[m_AttValues.length - 1];
      System.arraycopy(m_Indices, 0, tempIndices, 0, index);
      System.arraycopy(m_AttValues, 0, tempValues, 0, index);
      for (int i = index; i < m_Indices.length - 1; i++) {
        tempIndices[i] = m_Indices[i + 1] - 1;
        tempValues[i] = m_AttValues[i + 1];
      }
      m_Indices = tempIndices;
      m_AttValues = tempValues;
    } else {
      int[] tempIndices = new int[m_Indices.length];
      double[] tempValues = new double[m_AttValues.length];
      System.arraycopy(m_Indices, 0, tempIndices, 0, index + 1);
      System.arraycopy(m_AttValues, 0, tempValues, 0, index + 1);
      for (int i = index + 1; i < m_Indices.length; i++) {
        tempIndices[i] = m_Indices[i] - 1;
        tempValues[i] = m_AttValues[i];
      }
      m_Indices = tempIndices;
      m_AttValues = tempValues;
    }
  }

  /**
   * Inserts an attribute at the given position (0 to numAttributes()) and sets
   * its value to be missing.
   *
   * @param pos the attribute's position
   */
  @Override
  protected void forceInsertAttributeAt(int position) {

    int index = locateIndex(position);

    m_NumAttributes++;
    if ((index >= 0) && (m_Indices[index] == position)) {
      int[] tempIndices = new int[m_Indices.length + 1];
      double[] tempValues = new double[m_AttValues.length + 1];
      System.arraycopy(m_Indices, 0, tempIndices, 0, index);
      System.arraycopy(m_AttValues, 0, tempValues, 0, index);
      tempIndices[index] = position;
      tempValues[index] = Utils.missingValue();
      for (int i = index; i < m_Indices.length; i++) {
        tempIndices[i + 1] = m_Indices[i] + 1;
        tempValues[i + 1] = m_AttValues[i];
      }
      m_Indices = tempIndices;
      m_AttValues = tempValues;
    } else {
      int[] tempIndices = new int[m_Indices.length + 1];
      double[] tempValues = new double[m_AttValues.length + 1];
      System.arraycopy(m_Indices, 0, tempIndices, 0, index + 1);
      System.arraycopy(m_AttValues, 0, tempValues, 0, index + 1);
      tempIndices[index + 1] = position;
      tempValues[index + 1] = Utils.missingValue();
      for (int i = index + 1; i < m_Indices.length; i++) {
        tempIndices[i + 1] = m_Indices[i] + 1;
        tempValues[i + 1] = m_AttValues[i];
      }
      m_Indices = tempIndices;
      m_AttValues = tempValues;
    }
  }

  /**
   * Constructor for sub classes.
   */
  protected SparseInstance() {
  };

  /**
   * Main method for testing this class.
   */
  public static void main(String[] options) {

    try {

      // Create numeric attributes "length" and "weight"
      Attribute length = new Attribute("length");
      Attribute weight = new Attribute("weight");

      // Create vector to hold nominal values "first", "second", "third"
      ArrayList<String> my_nominal_values = new ArrayList<String>(3);
      my_nominal_values.add("first");
      my_nominal_values.add("second");
      my_nominal_values.add("third");

      // Create nominal attribute "position"
      Attribute position = new Attribute("position", my_nominal_values);

      // Create vector of the above attributes
      ArrayList<Attribute> attributes = new ArrayList<Attribute>(3);
      attributes.add(length);
      attributes.add(weight);
      attributes.add(position);

      // Create the empty dataset "race" with above attributes
      Instances race = new Instances("race", attributes, 0);

      // Make position the class attribute
      race.setClassIndex(position.index());

      // Create empty instance with three attribute values
      SparseInstance inst = new SparseInstance(3);

      // Set instance's values for the attributes "length", "weight", and
      // "position"
      inst.setValue(length, 5.3);
      inst.setValue(weight, 300);
      inst.setValue(position, "first");

      // Set instance's dataset to be the dataset "race"
      inst.setDataset(race);

      // Print the instance
      System.out.println("The instance: " + inst);

      // Print the first attribute
      System.out.println("First attribute: " + inst.attribute(0));

      // Print the class attribute
      System.out.println("Class attribute: " + inst.classAttribute());

      // Print the class index
      System.out.println("Class index: " + inst.classIndex());

      // Say if class is missing
      System.out.println("Class is missing: " + inst.classIsMissing());

      // Print the instance's class value in internal format
      System.out.println("Class value (internal format): " + inst.classValue());

      // Print a shallow copy of this instance
      SparseInstance copy = (SparseInstance) inst.copy();
      System.out.println("Shallow copy: " + copy);

      // Set dataset for shallow copy
      copy.setDataset(inst.dataset());
      System.out.println("Shallow copy with dataset set: " + copy);

      // Print out all values in internal format
      System.out.print("All stored values in internal format: ");
      for (int i = 0; i < inst.numValues(); i++) {
        if (i > 0) {
          System.out.print(",");
        }
        System.out.print(inst.valueSparse(i));
      }
      System.out.println();

      // Set all values to zero
      System.out.print("All values set to zero: ");
      while (inst.numValues() > 0) {
        inst.setValueSparse(0, 0);
      }
      for (int i = 0; i < inst.numValues(); i++) {
        if (i > 0) {
          System.out.print(",");
        }
        System.out.print(inst.valueSparse(i));
      }
      System.out.println();

      // Set all values to one
      System.out.print("All values set to one: ");
      for (int i = 0; i < inst.numAttributes(); i++) {
        inst.setValue(i, 1);
      }
      for (int i = 0; i < inst.numValues(); i++) {
        if (i > 0) {
          System.out.print(",");
        }
        System.out.print(inst.valueSparse(i));
      }
      System.out.println();

      // Unset dataset for copy, delete first attribute, and insert it again
      copy.setDataset(null);
      copy.deleteAttributeAt(0);
      copy.insertAttributeAt(0);
      copy.setDataset(inst.dataset());
      System.out.println("Copy with first attribute deleted and inserted: "
        + copy);

      // Same for second attribute
      copy.setDataset(null);
      copy.deleteAttributeAt(1);
      copy.insertAttributeAt(1);
      copy.setDataset(inst.dataset());
      System.out.println("Copy with second attribute deleted and inserted: "
        + copy);

      // Same for last attribute
      copy.setDataset(null);
      copy.deleteAttributeAt(2);
      copy.insertAttributeAt(2);
      copy.setDataset(inst.dataset());
      System.out.println("Copy with third attribute deleted and inserted: "
        + copy);

      // Enumerate attributes (leaving out the class attribute)
      System.out.println("Enumerating attributes (leaving out class):");
      Enumeration<Attribute> enu = inst.enumerateAttributes();
      while (enu.hasMoreElements()) {
        Attribute att = enu.nextElement();
        System.out.println(att);
      }

      // Headers are equivalent?
      System.out.println("Header of original and copy equivalent: "
        + inst.equalHeaders(copy));

      // Test for missing values
      System.out.println("Length of copy missing: " + copy.isMissing(length));
      System.out.println("Weight of copy missing: "
        + copy.isMissing(weight.index()));
      System.out.println("Length of copy missing: "
        + Utils.isMissingValue(copy.value(length)));

      // Prints number of attributes and classes
      System.out.println("Number of attributes: " + copy.numAttributes());
      System.out.println("Number of classes: " + copy.numClasses());

      // Replace missing values
      double[] meansAndModes = { 2, 3, 0 };
      copy.replaceMissingValues(meansAndModes);
      System.out.println("Copy with missing value replaced: " + copy);

      // Setting and getting values and weights
      copy.setClassMissing();
      System.out.println("Copy with missing class: " + copy);
      copy.setClassValue(0);
      System.out.println("Copy with class value set to first value: " + copy);
      copy.setClassValue("third");
      System.out.println("Copy with class value set to \"third\": " + copy);
      copy.setMissing(1);
      System.out.println("Copy with second attribute set to be missing: "
        + copy);
      copy.setMissing(length);
      System.out.println("Copy with length set to be missing: " + copy);
      copy.setValue(0, 0);
      System.out.println("Copy with first attribute set to 0: " + copy);
      copy.setValue(weight, 1);
      System.out.println("Copy with weight attribute set to 1: " + copy);
      copy.setValue(position, "second");
      System.out.println("Copy with position set to \"second\": " + copy);
      copy.setValue(2, "first");
      System.out.println("Copy with last attribute set to \"first\": " + copy);
      System.out.println("Current weight of instance copy: " + copy.weight());
      copy.setWeight(2);
      System.out.println("Current weight of instance copy (set to 2): "
        + copy.weight());
      System.out.println("Last value of copy: " + copy.toString(2));
      System.out.println("Value of position for copy: "
        + copy.toString(position));
      System.out.println("Last value of copy (internal format): "
        + copy.value(2));
      System.out.println("Value of position for copy (internal format): "
        + copy.value(position));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  /**
   * Returns the revision string.
   *
   * @return the revision
   */
  @Override
  public String getRevision() {
    return RevisionUtils.extract("$Revision: 10203 $");
  }
}


text:
FOUNDATION_EXPORT double Pods_LaPosteEasyServicesVersionNumber;
FOUNDATION_EXPORT const unsigned char Pods_LaPosteEasyServicesVersionString[];

redpajama_set_name: RedPajamaGithub


text:
local is_admin = require "core.usermanager".is_admin;
local t_remove = table.remove;

local restricted_options = module:get_option_set("muc_config_restricted", {})._items;

function handle_config_submit(event)
	local stanza = event.stanza;
	if is_admin(stanza.attr.from, module.host) then return; end -- Don't restrict admins
	local fields = event.fields;
	for option in restricted_options do
		fields[option] = nil; -- Like it was never there
	end
end

function handle_config_request(event)
	if is_admin(event.actor, module.host) then return; end -- Don't restrict admins
	local form = event.form;
	for i = #form, 1, -1 do
		if restricted_options[form[i].name] then
			t_remove(form, i);
		end
	end
end

module:hook("muc-config-submitted", handle_config_submit);
module:hook("muc-config-form", handle_config_request);


text:
package org.iith.scitech.infero.infox.util;

import android.text.format.Time;

import java.util.ArrayList;
import java.util.regex.Pattern;

/**
 * Various utility methods used by {@link org.iith.scitech.infero.infox}.
 */
public class ParserUtils {
    /** Used to sanitize a string to be {@link android.net.Uri} safe. */
    private static final Pattern sSanitizePattern = Pattern.compile("[^a-z0-9-_]");

    private static final Time sTime = new Time();

    /**
     * Sanitize the given string to be {@link android.net.Uri} safe for building
     * {@link android.content.ContentProvider} paths.
     */
    public static String sanitizeId(String input) {
        if (input == null) {
            return null;
        }
        return sSanitizePattern.matcher(input.replace("+", "plus").toLowerCase()).replaceAll("");
    }

    /**
     * Parse the given string as a RFC 3339 timestamp, returning the value as
     * milliseconds since the epoch.
     */
    public static long parseTime(String time) {
        sTime.parse3339(time);
        return sTime.toMillis(false);
    }

    public static String joinStrings(String connector, ArrayList<String> strings, StringBuilder recycle) {
        if (strings.size() <= 0) {
            return "";
        }
        if (recycle == null) {
            recycle = new StringBuilder();
        } else {
            recycle.setLength(0);
        }
        recycle.append(strings.get(0));
        for (int i = 1; i < strings.size(); i++) {
            recycle.append(connector);
            recycle.append(strings.get(i));
        }
        return recycle.toString();
    }
}


text:
'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true
});

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _whenNode = require('when/node');

var _whenNode2 = _interopRequireDefault(_whenNode);

var _origami = require('origami');

var _libRestClient = require('../lib/rest-client');

var _libRestClient2 = _interopRequireDefault(_libRestClient);

function createNotificationChannel(options, callback) {
  var settings = {
    method: 'POST',
    path: 'https://api.cronofy.com/v1/channels',
    headers: {
      Authorization: 'Bearer ' + options.access_token
    },
    params: _lodash2['default'].omit(options, 'access_token')
  };
  var result = (0, _libRestClient2['default'])(settings).fold(_origami.reach, 'entity');

  return _whenNode2['default'].bindCallback(result, callback);
}

exports['default'] = createNotificationChannel;
module.exports = exports['default'];


text:
package de.lessvoid.nifty.examples.defaultcontrols.treebox;

import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.builder.ControlBuilder;
import de.lessvoid.nifty.builder.ControlDefinitionBuilder;
import de.lessvoid.nifty.builder.PanelBuilder;
import de.lessvoid.nifty.controls.treebox.builder.TreeBoxBuilder;
import de.lessvoid.nifty.examples.defaultcontrols.common.CommonBuilders;
import de.lessvoid.nifty.examples.defaultcontrols.common.DialogPanelControlDefinition;

/**
 * The ChatControlDialogRegister registers a new control (the whole
 * ChatControlDialog) with Nifty. We can later simply generate the whole dialog
 * using a control with the given NAME.
 *
 * @author void
 */
public class TreeBoxControlDialogDefinition {
	public static String NAME = "treeboxControlDialogControl";
	private static CommonBuilders builders = new CommonBuilders();

	public static void register(final Nifty nifty) {
		new ControlDefinitionBuilder(NAME) {{
			controller(new TreeboxControlDialogController());
			control(new ControlBuilder(DialogPanelControlDefinition.NAME) {{
				panel(new PanelBuilder() {{
					childLayoutVertical();
					control(builders.createLabel("TreeBox:"));
					control(new TreeBoxBuilder("tree-box") {{
            displayItems(4);
            selectionModeSingle();
            showVerticalScrollbar();
            showHorizontalScrollbar();
            width("*");
				    }});
				}});
				panel(new PanelBuilder() {{
					childLayoutHorizontal();
					control(builders.createLabel("Selected:"));
					control(new ControlBuilder("selectedItemText", "textfield"));
				}});
			}});
		}}.registerControlDefintion(nifty);
	}
}


text:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Assigned_jobmanagement extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('login','', TRUE);
		$this->load->helper('functions');
		$this->load->helper('form');
		$this->load->library('session');
        $this->load->model('student_data');
        $this->load->model('register');
		$this->load->model('course');
		$this->load->model('lcc_inbox');
		$this->load->model('lcc_communication');
		$this->load->model('student_data','', TRUE);
		$this->load->model('staff','', TRUE);
		$this->load->model('job_department','', TRUE);
		$this->load->model('jobs','', TRUE);
		$this->load->model('job_induction','', TRUE);
        $this->load->model('job_induction_process','', TRUE);
		$this->load->model('job_assign','', TRUE);
		$this->load->model('lcc_inbox','', TRUE);
		$this->load->model('job_type','', TRUE);
		$this->load->model('job_applied_student','', TRUE);
	}

	public function index(){

	    $data                   =   array();
	    $menuleft               =   array();
	    $data["statements"]     =   array();
	    $varsessioncheck_id     =   $this->session->userdata('uid');

	    $label                  =   $this->session->userdata('label');
	    $data["fullname"]       =   $this->session->userdata('fullname');
	    $data['message']        =   "";

	    //////////////////////////////////////////////////////
		/// get staff access
        if($this->session->userdata('label')=="staff"){
                  $staff_access = $this->login->getStaffAccess($this->session->userdata('uid'));

                  if(!empty($staff_access['staff_privileges']['assigned_job_management']) && count($staff_access['staff_privileges']['assigned_job_management'])>0) $priv = $data['priv'] = $staff_access['staff_privileges']['assigned_job_management'];
                else{ $priv[0] = ""; }

        }
	    /////////////////////////////////////////////////////

	    // alert count part

	    $data["alert_count"]                =   0;
	    $data["inbox_alert_count"]          =   0;

	    $data["alert_count"]          = $this->lcc_inbox->get_alert_of_staff($varsessioncheck_id);
	    $data["inbox_alert_count"]    = $this->lcc_inbox->get_communication_alert_of_staff($varsessioncheck_id);

	    // alert count part end

    	$action 				= $this->input->get('action');
    	$id 					= $this->input->get('id');
    	$dept_id 				= $this->input->get('dept_id');
        $page                   = $this->input->get('page');

        //if($this->input->post('ref')=="edit" && (!empty($staff_privileges_course_management['course_mng_edit']) || $this->session->userdata('label')=="admin")){
        if($this->input->post('ref')=="edit"){

			$id = $this->input->post('ref_id');
			$args['id'] = $id;
			foreach($this->input->post() as $k=>$v){

				if($k!="ref" && $k!="ref_id" && $k!="jobs_list"){ $$k = tinymce_encode($v); $args[$k] = $$k; }
				else if($k=="jobs_list"){ $$k = $v; $args[$k] = serialize($$k); }
			}
			//var_dump($args);
			$insertedid=$this->job_induction_process->update($args);
	       $data['error']=0;
	       if($insertedid){

	       		$data['message'] = "
 Job department has been successfully updated.
";

		   }

        //}else if($this->input->post('ref')=="add"  && (!empty($staff_privileges_course_management['course_mng_add']) || $this->session->userdata('label')=="admin")){
        }else if($this->input->post('ref')=="add"){

			//$id = $this->input->post('ref_id');

			foreach($this->input->post() as $k=>$v){
				if($k!="ref" && $k!="ref_id" && $k!="jobs_list"){ $$k = tinymce_encode($v); $args[$k] = $$k; }
				else if($k=="jobs_list"){ $$k = $v; $args[$k] = serialize($$k); }
			}
			//var_dump($args);
			///------------------------ Sending inbox notification to students
			if($args['students_notified']=="yes"){

				$induction = $this->job_induction->get_by_ID($args['job_induction_id']);

				if(!empty($induction['assigned_students'])){
					$std_arr = unserialize($induction['assigned_students']);

					foreach($std_arr as $student_data_id){
						$inbox_args = array();
						$inbox_args['communication_id'] = 0;
						$inbox_args['student_data_id'] = $student_data_id;
						$inbox_args['staff_id'] = $this->session->userdata('uid');
						$inbox_args['notification_type'] = "induction";
						$inbox_args['notification_from'] = "staff";
						$inbox_args['notification_to'] = "student";
						$inbox_args['notification_to_staff_id'] = 0;
						$inbox_args['induction_id'] = $args['job_induction_id'];
						$this->lcc_inbox->add($inbox_args);
					}
				}

			}
			///------------------------ END OF Sending inbox notification to students

			$insertedid=$this->job_induction_process->add($args);
	       $data['error']=0;
	       if($insertedid){

	       		$data['message'] = "
 Job department has been successfully added.
";

		   }
        }

	    //if(!empty($varsessioncheck_id) && ($action==NULL || $action=="list") && (!empty($staff_privileges_course_management['course_mng']) || $this->session->userdata('label')=="admin")){
	    if( !empty($varsessioncheck_id) && $action!="archive" && ( !empty($priv[0]) || $this->session->userdata('label')=="admin" ) ){

	        $data['bodytitle']       =   "Assigned Job Lists";
	        $data['faicon']          =   "fa-info";
	        $data['breadcrumbtitle'] =   "Dashboard > job management > Assigned Job lists";

	        //$data['assigned_job_list'] = $this->job_assign->get_all();

	        //---- get departments

	        $all_departmets = $this->job_department->get_all();
	        $assigned_departments = array();
	        foreach($all_departmets as $k=>$v){
	        	if(!empty($v['staff_list'])){
					$staff_list = unserialize($v['staff_list']);
					//var_dump($staff_list);
					foreach($staff_list as $a){
						if($a == $this->session->userdata("uid")){
							$data['assigned_departments'][$v['id']] = $assigned_departments[$v['id']] = $v['name'];
						}
					}
				}
	        }
	        $job_list = array(); $induction_job_list = array();
	        if(!empty($dept_id)){
				/*$jobs = $this->jobs->get_all();
				foreach($jobs as $k=>$v){
					if(!empty($v['job_department_id'])){
						$departments = unserialize($v['job_department_id']);
						foreach($departments as $dept){
							if($dept==$dept_id){
								$job_list[$v['id']] = $v['name'];
							}
						}
					}
				}
				if(!empty($job_list) && count($job_list)>0){

					foreach($job_list as $k=>$v){
						$job_data = $this->jobs->get_by_ID($k);
						if($job_data['job_type']=="common"){
					 		$common_job_list[$job_data['id']] = $job_data['name'];
						}else if($job_data['job_type']=="induction"){
							$induction_job_list[$job_data['id']] = $job_data['name'];
						}
					}
				    if(!empty($common_job_list) && count($common_job_list)>0)
				    $data['common_job_list'] 	= $common_job_list;
				    else $data['common_job_list'] = "";
				    if(!empty($induction_job_list) && count($induction_job_list)>0)
				    $data['induction_job_list'] = $induction_job_list;
				    else $data['induction_job_list'] ="";

				}*/
				//-- if(!empty($job_list) && count($job_list)>0){

				$job_type = array();
				$job_type = $this->job_type->get_all();
				$jobs = $this->job_assign->get_by_job_department_id_and_status_pending($dept_id);
				//var_dump($jobs);
				foreach($job_type as $k=>$v){

					foreach($jobs as $a=>$b){

						$job_data = $this->jobs->get_by_ID($b['jobs_id']);
						if(!empty($job_data)){
							if($job_data['job_type_id'] == $v['id']){

								$job_list[$v['name']][] = array("job_data"	=>	$job_data,"job_assign_data"	=>	$b);

							}
							/*
                                else if($job_data['job_type_id'] == $v['id'] && $v['name']=="Induction"){

								$induction_id = $b['job_induction_id'];

								$job_list[$v['name']][] = array(	"job_data"	=>	$job_data,"job_assign_data"	=>	$b);

							}*/
						}

					}

				}

               $data['job_list'] = $job_list;

	        }

	        //var_dump($data['course_list']);

	        $this->load->view('staff/dashboard_header',$data);
	        $this->load->view('staff/dashboard_topmenu');
	        $this->load->view('staff/dashboard_sidebar');
	        $this->load->view('staff/job_induction/job_assigned_list');
	        $this->load->view('staff/other_footer');

		}else if(!empty($varsessioncheck_id) && $action=="archive" && ( !empty($priv[0]) || $this->session->userdata('label')=="admin" ) ){

	        $data['bodytitle']       =   "Assigned Job Lists";
	        $data['faicon']          =   "fa-info";
	        $data['breadcrumbtitle'] =   "Dashboard > job management > Assigned Job lists";

	        $all_departmets = $this->job_department->get_all();
	        $assigned_departments = array();
	        foreach($all_departmets as $k=>$v){
	        	if(!empty($v['staff_list'])){
					$staff_list = unserialize($v['staff_list']);
					//var_dump($staff_list);
					foreach($staff_list as $a){
						if($a == $this->session->userdata("uid")){
							$data['assigned_departments'][$v['id']] = $assigned_departments[$v['id']] = $v['name'];
						}
					}
				}
	        }

	        if(!empty($dept_id)){

	        	$data['archive']	= $this->job_assign->makeJobAssignListWithpagination(array("job_department_id"=>$dept_id),$page,base_url()."index.php/job_induction/assigned_jobmanagement/?action=archive&dept_id=".$dept_id,"yes");

	        }

	        $this->load->view('staff/dashboard_header',$data);
	        $this->load->view('staff/dashboard_topmenu');
	        $this->load->view('staff/dashboard_sidebar');
	        $this->load->view('staff/job_induction/job_assigned_list');
	        $this->load->view('staff/other_footer');

	    } else if(!empty($varsessioncheck_id) && ( $label == "admin"  || $label == "staff" )) {
	        redirect('/admin_dashboard/');
		}else if(!empty($varsessioncheck_id) && $label=="student" ){
		    redirect('/user_dashboard/');
		}else if(!empty($varsessioncheck_id) && $label=="registered" ){
		    redirect('/student_dashboard/');
	    }else{
	        redirect('/logout/');
	    }

	} // end of index

}

/* End of file gender_management.php */
/* Location: ./application/controllers/registration/gender_management.php */


text:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.damienfremont.codingame</groupId>
	<artifactId>codingame-training-easy-the_descent</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<properties>
		<java.version>8</java.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.3</version>
				<configuration>
					<source>1.${java.version}</source>
					<target>1.${java.version}</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>


text:
from telemetry.page import page as page_module
from telemetry.page import page_set as page_set_module

class SimplePage(page_module.Page):

  def __init__(self, url, page_set):
    super(SimplePage, self).__init__(url=url, page_set=page_set)
    self.credentials_path = 'data/credentials.json'
    self.archive_data_file = 'data/simple_mobile_sites.json'

  def RunNavigateSteps(self, action_runner):
    action_runner.NavigateToPage(self)
    # TODO(epenner): Remove this wait (http://crbug.com/366933)
    action_runner.Wait(5)

class SimpleScrollPage(SimplePage):

  def __init__(self, url, page_set):
    super(SimpleScrollPage, self).__init__(url=url, page_set=page_set)

  def RunSmoothness(self, action_runner):
    # Make the scroll longer to reduce noise.
    interaction = action_runner.BeginGestureInteraction(
        'ScrollAction', is_smooth=True)
    action_runner.ScrollPage(direction='down', speed_in_pixels_per_second=300)
    interaction.End()

class SimpleMobileSitesPageSet(page_set_module.PageSet):

  """ Simple mobile sites """

  def __init__(self):
    super(SimpleMobileSitesPageSet, self).__init__(
      credentials_path='data/credentials.json',
      user_agent_type='tablet_10_inch',
      archive_data_file='data/simple_mobile_sites.json',
      bucket=page_set_module.PUBLIC_BUCKET)

    scroll_page_list = [
      # Why: Scrolls moderately complex pages (up to 60 layers)
      'http://www.ebay.co.uk/',
      'https://www.flickr.com/',
      'http://www.apple.com/mac/',
      'http://www.nyc.gov',
      'http://m.nytimes.com/',
      'https://www.yahoo.com/',
      'http://m.us.wsj.com/',
    ]

    for url in scroll_page_list:
      self.AddPage(SimpleScrollPage(url, self))


text:
require 'example'

# Call our gcd() function

x = 42
y = 105
g = Example.gcd(x,y)
printf "The gcd of %d and %d is %d\n",x,y,g

# Manipulate the Foo global variable

# Output its current value
print "Foo = ", Example.Foo, "\n"

# Change its value
Example.Foo = 3.1415926

# See if the change took effect
print "Foo = ", Example.Foo, "\n"


text:
from tests.integration.create_token import create_token
from tests.integration.star_wars import BLOCK_2_DEFAULT_ANSWERS
from tests.integration.star_wars.star_wars_tests import StarWarsTestCase

class TestPageErrors(StarWarsTestCase):
    def test_multi_page_errors(self):
        # Get a token
        self.login()

        first_page = self.start_questionnaire_and_navigate_routing()

        resp = self.submit_page(first_page, BLOCK_2_DEFAULT_ANSWERS)

        self.assertNotEqual(resp.location, first_page)
        # Second page
        second_page = resp.location

        self.check_second_quiz_page(second_page)

        # Our answers
        form_data = {
            # Make this data missing
            "215015b1-f87c-4740-9fd4-f01f707ef558": "",  # Required answer
            # User Action
            "action[save_continue]": "Save & Continue"
        }

        self.submit_page(second_page, form_data)

        # We fill in our answers missing one required field
        form_data = BLOCK_2_DEFAULT_ANSWERS.copy()
        del form_data['a5dc09e8-36f2-4bf4-97be-c9e6ca8cbe0d']

        # We submit the form
        resp = self.submit_page(first_page, form_data)

        content = resp.get_data(True)
        self.assertRegex(content, 'href="#a5dc09e8-36f2-4bf4-97be-c9e6ca8cbe0d"')
        # We DO NOT have the error from page two
        self.assertNotRegex(content, 'href="215015b1-f87c-4740-9fd4-f01f707ef558"')

    def test_skip_question_errors(self):
        # Given on the page with skip question with skip condition
        token = create_token('skip_condition', 'test')
        self.client.get('/session?token=' + token.decode(), follow_redirects=True)
        post_data = {'action[start_questionnaire]': 'Start Questionnaire'}
        self.client.post('/questionnaire/test/skip_condition/201604/789/introduction', data=post_data, follow_redirects=True)
        post_data = {'food-answer': 'Bacon', 'action[save_continue]': 'Save & Continue'}
        self.client.post('/questionnaire/test/skip_condition/201604/789/breakfast/0/food-block', data=post_data, follow_redirects=True)

        # When submit no answers which is invalid
        post_data = {'action[save_continue]': 'Save & Continue'}
        resp = self.client.post('/questionnaire/test/skip_condition/789/breakfast/0/drink-block', data=post_data)

        # Then errors exists on page
        self.assertEqual(resp.status_code, 200)
        self.assertRegex(resp.get_data(True), 'This page has 1 errors')


text:
package org.vaadin.enhancements.sqlcontainer;

import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.logging.Logger;

import com.vaadin.data.Property;
import com.vaadin.data.util.LegacyPropertyHelper;
import com.vaadin.data.util.converter.Converter.ConversionException;

/**
 * ColumnProperty represents the value of one column in a RowItem. In addition
 * to the value, ColumnProperty also contains some basic column attributes such
 * as nullability status, read-only status and data type.
 *
 * Note that depending on the QueryDelegate in use this does not necessarily map
 * into an actual column in a database table.
 */
final public class ColumnProperty implements Property {
    private static final long serialVersionUID = -3694463129581802457L;

    private RowItem owner;

    private String propertyId;

    private boolean readOnly;
    private boolean allowReadOnlyChange = true;
    private boolean nullable = true;

    private Object value;
    private Object changedValue;
    private Class<?> type;

    private boolean modified;

    private boolean versionColumn;
    private boolean primaryKey = false;

    /**
     * Prevent instantiation without required parameters.
     */
    @SuppressWarnings("unused")
    private ColumnProperty() {
    }

    /**
     * Deprecated constructor for ColumnProperty. If this is used the primary
     * keys are not identified correctly in some cases for some databases (i.e.
     * Oracle). See http://dev.vaadin.com/ticket/9145.
     *
     * @param propertyId
     * @param readOnly
     * @param allowReadOnlyChange
     * @param nullable
     * @param value
     * @param type
     *
     * @deprecated As of 7.0. Use
     *             {@link #ColumnProperty(String, boolean, boolean, boolean, boolean, Object, Class)}
     *             instead
     */
    @Deprecated
    public ColumnProperty(String propertyId, boolean readOnly,
            boolean allowReadOnlyChange, boolean nullable, Object value,
            Class<?> type) {
        this(propertyId, readOnly, allowReadOnlyChange, nullable, false, value,
                type);
    }

    /**
     * Creates a new ColumnProperty instance.
     *
     * @param propertyId
     *            The ID of this property.
     * @param readOnly
     *            Whether this property is read-only.
     * @param allowReadOnlyChange
     *            Whether the read-only status of this property can be changed.
     * @param nullable
     *            Whether this property accepts null values.
     * @param primaryKey
     *            Whether this property corresponds to a database primary key.
     * @param value
     *            The value of this property.
     * @param type
     *            The type of this property.
     */
    public ColumnProperty(String propertyId, boolean readOnly,
            boolean allowReadOnlyChange, boolean nullable, boolean primaryKey,
            Object value, Class<?> type) {

        if (propertyId == null) {
            throw new IllegalArgumentException("Properties must be named.");
        }
        if (type == null) {
            throw new IllegalArgumentException("Property type must be set.");
        }
        this.propertyId = propertyId;
        this.type = type;
        this.value = value;

        this.allowReadOnlyChange = allowReadOnlyChange;
        this.nullable = nullable;
        this.readOnly = readOnly;
        this.primaryKey = primaryKey;
    }

    /**
     * Returns the current value for this property. To get the previous value
     * (if one exists) for a modified property use {@link #getOldValue()}.
     *
     * @return
     */
    @Override
    public Object getValue() {
        if (isModified()) {
            return changedValue;
        }
        return value;
    }

    /**
     * Returns the original non-modified value of this property if it has been
     * modified.
     *
     * @return The original value if isModified() is true,
     *         getValue() otherwise.
     */
    public Object getOldValue() {
        return value;
    }

    @Override
    public void setValue(Object newValue)
            throws ReadOnlyException, ConversionException {
        if (newValue == null && !nullable) {
            throw new NotNullableException(
                    "Null values are not allowed for this property.");
        }
        if (readOnly) {
            throw new ReadOnlyException(
                    "Cannot set value for read-only property.");
        }

        /* Check if this property is a date property. */
        boolean isDateProperty = Time.class.equals(getType())
                || Date.class.equals(getType())
                || Timestamp.class.equals(getType());

        if (newValue != null) {
            /* Handle SQL dates, times and Timestamps given as java.util.Date */
            if (isDateProperty) {
                /*
                 * Try to get the millisecond value from the new value of this
                 * property. Possible type to convert from is java.util.Date.
                 */
                long millis = 0;
                if (newValue instanceof java.util.Date) {
                    millis = ((java.util.Date) newValue).getTime();
                    /*
                     * Create the new object based on the millisecond value,
                     * according to the type of this property.
                     */
                    if (Time.class.equals(getType())) {
                        newValue = new Time(millis);
                    } else if (Date.class.equals(getType())) {
                        newValue = new Date(millis);
                    } else if (Timestamp.class.equals(getType())) {
                        newValue = new Timestamp(millis);
                    }
                }
            }

            if (!getType().isAssignableFrom(newValue.getClass())) {
                throw new IllegalArgumentException(
                        "Illegal value type for ColumnProperty");
            }

            /*
             * If the value to be set is the same that has already been set, do
             * not set it again.
             */
            if (isValueAlreadySet(newValue)) {
                return;
            }
        }

        /* Set the new value and notify container of the change. */
        changedValue = newValue;
        modified = true;
        owner.getContainer().itemChangeNotification(owner);
    }

    private boolean isValueAlreadySet(Object newValue) {
        Object referenceValue = isModified() ? changedValue : value;

        return (isNullable() && newValue == null && referenceValue == null)
                || newValue.equals(referenceValue);
    }

    @Override
    public Class<?> getType() {
        return type;
    }

    @Override
    public boolean isReadOnly() {
        return readOnly;
    }

    /**
     * Returns whether the read-only status of this property can be changed
     * using {@link #setReadOnly(boolean)}.
     *

     * Used to prevent setting to read/write mode a property that is not allowed
     * to be written by the underlying database. Also used for values like
     * VERSION and AUTO_INCREMENT fields that might be set to read-only by the
     * container but the database still allows writes.
     *
     * @return true if the read-only status can be changed, false otherwise.
     */
    public boolean isReadOnlyChangeAllowed() {
        return allowReadOnlyChange;
    }

    @Override
    public void setReadOnly(boolean newStatus) {
        if (allowReadOnlyChange) {
            readOnly = newStatus;
        }
    }

    public boolean isPrimaryKey() {
        return primaryKey;
    }

    public String getPropertyId() {
        return propertyId;
    }

    /**
     * Returns a string representation of this object. The returned string
     * representation depends on if the legacy Property toString mode is enabled
     * or disabled.
     *

     * If legacy Property toString mode is enabled, returns the value of this
     * Property converted to a String.
     *

     *

     * If legacy Property toString mode is disabled, the string representation
     * has no special meaning
     *

     *
     * @see LegacyPropertyHelper#isLegacyToStringEnabled()
     *
     * @return A string representation of the value value stored in the Property
     *         or a string representation of the Property object.
     * @deprecated As of 7.0. To get the property value, use {@link #getValue()}
     *             instead (and possibly toString on that)
     */
    @Deprecated
    @Override
    public String toString() {
        if (!LegacyPropertyHelper.isLegacyToStringEnabled()) {
            return super.toString();
        } else {
            return LegacyPropertyHelper.legacyPropertyToString(this);
        }
    }

    private static Logger getLogger() {
        return Logger.getLogger(ColumnProperty.class.getName());
    }

    public void setOwner(RowItem owner) {
        if (owner == null) {
            throw new IllegalArgumentException("Owner can not be set to null.");
        }
        if (this.owner != null) {
            throw new IllegalStateException(
                    "ColumnProperties can only be bound once.");
        }
        this.owner = owner;
    }

    public boolean isModified() {
        return modified;
    }

    public boolean isVersionColumn() {
        return versionColumn;
    }

    public void setVersionColumn(boolean versionColumn) {
        this.versionColumn = versionColumn;
    }

    public boolean isNullable() {
        return nullable;
    }

    /**
     * Return whether the value of this property should be persisted to the
     * database.
     *
     * @return true if the value should be written to the database, false
     *         otherwise.
     */
    public boolean isPersistent() {
        if (isVersionColumn()) {
            return false;
        } else if (isReadOnlyChangeAllowed() && !isReadOnly()) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Returns whether or not this property is used as a row identifier.
     *
     * @return true if the property is a row identifier, false otherwise.
     */
    public boolean isRowIdentifier() {
        return isPrimaryKey() || isVersionColumn();
    }

    /**
     * An exception that signals that a null value was passed to
     * the setValue method, but the value of this property can not
     * be set to null.
     */
    @SuppressWarnings("serial")
    public class NotNullableException extends RuntimeException {

        /**
         * Constructs a new NotNullableException without a detail
         * message.
         */
        public NotNullableException() {
        }

        /**
         * Constructs a new NotNullableException with the specified
         * detail message.
         *
         * @param msg
         *            the detail message
         */
        public NotNullableException(String msg) {
            super(msg);
        }

        /**
         * Constructs a new NotNullableException from another
         * exception.
         *
         * @param cause
         *            The cause of the failure
         */
        public NotNullableException(Throwable cause) {
            super(cause);
        }
    }

    public void commit() {
        if (isModified()) {
            modified = false;
            value = changedValue;
        }
    }
}


text:
require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')

context "Apiv1Controller" do
  context "description here" do
    setup do
      get "/"
    end

    asserts("the response body") { last_response.body }.equals "Hello World"
  end
end


text: require 'sqs_worker/serializer/json'


text:
call "%VS100COMNTOOLS%vsvars32.bat"
vbc.exe /imports:Microsoft.VisualBasic,System /out:.\executions_bin\%1.exe .\executions\%1 > ./compilelogs/%1.txt 2>&1


text:
// SotD
//  stability warning
//
Publication as a Working Draft does not imply endorsement by W3C and its Members.

import { filter } from '../../util.js';

/**
 * @param candidates
 * @param sr
 */
function findSW(candidates, sr) {
    let wanted = '';
    let sw = '';
    if (
        sr.config.longStatus === 'Group Note' ||
        sr.config.longStatus === 'Group Draft Note'
    ) {
        // Find the sentence of 'Group Notes are not endorsed by W3C nor its Members.'
        wanted = `${sr.config.longStatus}s are not endorsed by W3C nor its Members.`;
    } else if (sr.config.longStatus === 'Statement') {
        wanted =
            'A W3C Statement is a specification that, after extensive consensus-building, is endorsed by W3C and its Members.';
    } else if (sr.config.longStatus === 'Discontinued Draft') {
        wanted =
            'Publication as a Discontinued Draft implies that this document is no longer intended to advance or to be maintained. It is inappropriate to cite this document as other than abandoned work.';
    } else if (sr.config.longStatus === 'Registry') {
        wanted =
            'A W3C Registry is a specification that, after extensive consensus-building, is endorsed by W3C and its Members.';
    } else {
        const { crType } = sr.config;
        const INTRO_S =
            ' A Candidate Recommendation Snapshot has received wide review, is intended to gather implementation experience, and has commitments from Working Group members to royalty-free licensing for implementations.';
        const INTRO_D =
            ' A Candidate Recommendation Draft integrates changes from the previous Candidate Recommendation that the Working Group intends to include in a subsequent Candidate Recommendation Snapshot.';
        const CR_INTRO = crType === 'Draft' ? INTRO_D : INTRO_S;

        const { cryType } = sr.config;
        const INTRO_CRY =
            ' A Candidate Registry Snapshot has received wide review.';
        const INTRO_CRYD =
            ' A Candidate Registry Draft integrates changes from the previous Candidate Registry that the Working Group intends to include in a subsequent Candidate Registry Snapshot.';
        const CRY_INTRO = cryType === 'Draft' ? INTRO_CRYD : INTRO_CRY;
        sw = null;
        const article =
            sr.config.longStatus === 'Interest Group Note' ? 'an' : 'a';
        const represent =
            sr.config.status === 'WD' || sr.config.status === 'FPWD'
                ? '( does not necessarily represent a consensus of the Working Group and)?'
                : '';
        wanted = `Publication as ${article} ${sr.config.longStatus}${
            sr.config.cryType ? ` ${sr.config.cryType}` : ''
        }${represent} does not imply endorsement by W3C and its Members.${
            crType ? CR_INTRO : ''
        }${cryType ? CRY_INTRO : ''}`;
    }

    // TODO: better some
    Array.prototype.some.call(candidates, p => {
        const text = sr.norm(p.textContent);
        if (text.match(wanted)) {
            sw = p;
            return true;
        }
        return false;
    });
    return { sw, expected: wanted };
}

const self = {
    name: 'sotd.stability',
    section: 'document-status',
    rule: 'stability',
};

export const { name } = self;

/**
 * @param sr
 * @param done
 */
export function check(sr, done) {
    const sotd = sr.getSotDSection();
    if (sotd) {
        if (sr.config.status === 'REC') {
            const txt = sr.norm(sotd && sotd.textContent);
            const wanted = `A W3C Recommendation is a specification that, after extensive consensus-building, is endorsed by W3C and its Members, and has commitments from Working Group members to royalty-free licensing for implementations.`;
            const rex = new RegExp(wanted);
            if (!rex.test(txt)) sr.error(self, 'no-rec-review');
        } else {
            const paragraph = filter(sotd, 'p');
            const { sw, expected } = findSW(
                paragraph.length ? paragraph : sotd.querySelectorAll('p'),
                sr
            );
            if (!sw) sr.error(self, 'no-stability', { expected });
            else if (
                sr.config.crType === 'Snapshot' ||
                sr.config.cryType === 'Snapshot'
            ) {
                const review = Array.prototype.find.call(
                    sw.querySelectorAll('a'),
                    ele => ele.textContent === 'wide review'
                );
                if (!review) sr.error(self, 'no-cr-review');
                else if (
                    review.href !==
                    'https://www.w3.org/2021/Process-20211102/#dfn-wide-review'
                )
                    sr.error(self, 'wrong-cr-review-link');
            }
        }

        // check 'royalty-free licensing' link
        if (sr.config.status === 'REC' || sr.config.status === 'CR') {
            const links = sotd.querySelectorAll('a');
            const licensingText = 'royalty-free licensing';
            const licensingLink =
                'https://www.w3.org/Consortium/Patent-Policy/#sec-Requirements';
            const licensingFound = Array.prototype.some.call(
                links,
                link =>
                    sr.norm(link.textContent) === licensingText &&
                    link.href === licensingLink
            );
            if (!licensingFound)
                sr.error(self, 'no-licensing-link', {
                    licensingText,
                    licensingLink,
                });
        }
    }
    return done();
}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using static LanguageExt.Parsec.Prim;
using static LanguageExt.Parsec.Char;

namespace LanguageExt.Parsec
{
    /// <summary>
    /// The GenLanguageDef type is a record that contains all parameteridable
    /// features of the "Parsec.Text.Token" module.  The module "Parsec.Text.Language"
    /// contains some default definitions.
    /// </summary>
    public class GenLanguageDef
    {
        /// <summary>
        /// Describes the start of a block comment. Use the empty string if the
        /// language doesn't support block comments. For example "/*".
        /// </summary>
        public readonly string CommentStart;

        /// <summary>
        /// Describes the end of a block comment. Use the empty string if the
        /// language doesn't support block comments. For example "*\".
        /// </summary>
        public readonly string CommentEnd;

        /// <summary>
        /// Describes the start of a line comment. Use the empty string if the
        /// language doesn't support line comments. For example "//".
        /// </summary>
        public readonly string CommentLine;

        /// <summary>
        /// Set to 'True' if the language supports nested block comments.
        /// </summary>
        public readonly bool NestedComments;

        /// <summary>
        /// This parser should accept any start characters of identifiers. For
        /// example either(letter,char('_')).
        /// </summary>
        public readonly Parser<char> IdentStart;

        /// <summary>
        /// This parser should accept any legal tail characters of identifiers.
        /// For example either(alphaNum, char('_')).
        /// </summary>
        public readonly Parser<char> IdentLetter;

        /// <summary>
        /// This parser should accept any start characters of operators. For
        /// example oneOf(":!#$%&*+.\/\<=>?\@\\\\^|-~")
        /// </summary>
        public readonly Parser<char> OpStart;

        /// <summary>
        /// This parser should accept any legal tail characters of operators.
        /// Note that this parser should even be defined if the language doesn't
        /// support user-defined operators, or otherwise the 'reservedOp'
        /// parser won't work correctly.
        /// </summary>
        public readonly Parser<char> OpLetter;

        /// <summary>
        /// The list of reserved identifiers.
        /// </summary>
        public readonly Lst<string> ReservedNames;

        /// <summary>
        /// The list of reserved operators.
        /// </summary>
        public readonly Lst<string> ReservedOpNames;

        /// <summary>
        /// Set to 'True' if the language is case sensitive.
        /// </summary>
        public readonly bool CaseSensitive;

        /// <summary>
        /// Empty definition, use With to build
        /// </summary>
        public static readonly GenLanguageDef Empty =
            new GenLanguageDef("", "", "", true, zero<char>(), zero<char>(), zero<char>(), zero<char>(), List.empty<string>(), List.empty<string>(), true);

        private GenLanguageDef(
            string commentStart,
            string commentEnd,
            string commentLine,
            bool nestedComments,
            Parser<char> identStart,
            Parser<char> identLetter,
            Parser<char> opStart,
            Parser<char> opLetter,
            Lst<string> reservedNames,
            Lst<string> reservedOpNames,
            bool caseSensitive
            )
        {
            CommentStart = commentStart;
            CommentEnd = commentEnd;
            CommentLine = commentLine;
            NestedComments = nestedComments;
            IdentStart = identStart;
            IdentLetter = identLetter;
            OpStart = opStart;
            OpLetter = opLetter;
            ReservedNames = reservedNames.OrderBy(x => x).Freeze();
            ReservedOpNames = reservedOpNames.OrderBy(x=> x).Freeze();
            CaseSensitive = caseSensitive;
        }

        public GenLanguageDef With(
            string CommentStart = null,
            string CommentEnd = null,
            string CommentLine = null,
            bool? NestedComments = null,
            Parser<char> IdentStart = null,
            Parser<char> IdentLetter = null,
            Parser<char> OpStart = null,
            Parser<char> OpLetter = null,
            Lst<string>? ReservedNames = null,
            Lst<string>? ReservedOpNames = null,
            bool? CaseSensitive = null
            ) =>
            new GenLanguageDef(
                CommentStart ?? this.CommentStart,
                CommentEnd ?? this.CommentEnd,
                CommentLine ?? this.CommentLine,
                NestedComments ?? this.NestedComments,
                IdentStart ?? this.IdentStart,
                IdentLetter ?? this.IdentLetter,
                OpStart ?? this.OpStart,
                OpLetter ?? this.OpLetter,
                ReservedNames ?? this.ReservedNames,
                ReservedOpNames ?? this.ReservedOpNames,
                CaseSensitive ?? this.CaseSensitive
            );
    }
}


text:
#ifndef __FOO_H__
#define __FOO_H__

#define NAXSI_VERSION "0.46-1"

#include <nginx.h>
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include <ngx_event.h>
#include <ngx_md5.h>
#include <ngx_http_core_module.h>
#include <pcre.h>
#include <ctype.h>

extern ngx_module_t ngx_http_naxsi_module;

/*
** Here is globally how the structures are organized :
**
** [[ngx_http_dummy_main_conf_t]] is the main structure for the module.
** it contains the core rules and a set of ngx_http_dummy_loc_conf_t,
** for each NGINX location.
** ---
** [[ngx_http_dummy_loc_conf_t]] is the main structure for any NGINX
** locations, that is - a web site. It contains both pointers to the core
** rules, as well as whitelists, scores, denied_url and all flags. all
** the data of a nginx location is held into the loc_conf_t struct.
** The sets of rules are actually containted into [[ngx_http_rule_t]] structs.
** ---
** [[ngx_http_rule_t]] structs are used to hold any info about a rule, as well
** as whitelists. (whitelists is just a 'kind' of rule).
**
*/

enum MATCH_TYPE {
  URI_ONLY=0,
  NAME_ONLY,
  MIXED
};

enum DUMMY_MATCH_ZONE {
  HEADERS=0,
  URL,
  ARGS,
  BODY,
  FILE_EXT,
  UNKNOWN
};

/*
** struct used to store a specific match zone
** in conf : MATCH_ZONE:[GET_VAR|HEADER|POST_VAR]:VAR_NAME:
*/
typedef struct
{
  /* match in [name] var of body */
  ngx_flag_t		body_var:1;
  /* match in [name] var of headers */
  ngx_flag_t		headers_var:1;
  /* match in [name] var of args */
  ngx_flag_t		args_var:1;
  /* match on URL [name] */
  ngx_flag_t		specific_url:1;
  ngx_str_t		target;
  ngx_uint_t		hash;
} ngx_http_custom_rule_location_t;

/*
** WhiteList Rules Definition :
** A whitelist contains :
** - an URI
**
** - one or several sets containing :
**	- an variable name ('foo') associated with a zone ($GET_VAR:foo)
**	- one or several rules id to whitelist
*/

#define WEIRD_REQUEST_INTERNAL_RULE_ID 1
#define BIG_BODY_INTERNAL_RULE_ID 2
typedef struct
{
  /* match in full body (POST DATA) */
  ngx_flag_t		body:1;
  /* match in [name] var of body */
  ngx_flag_t		body_var:1;
  /* match in all headers */
  ngx_flag_t		headers:1;
  /* match in [name] var of headers */
  ngx_flag_t		headers_var:1;
  /* match in URI */
  ngx_flag_t		url:1;
  /* match in args (bla.php?<ARGS>) */
  ngx_flag_t		args:1;
  /* match in [name] var of args */
  ngx_flag_t		args_var:1;
  /* match on a global flag : weird_request, big_body etc. */
  ngx_flag_t		flags:1;
  /* match on file upload extension */
  ngx_flag_t		file_ext:1;
  /* set if defined "custom" match zone (GET_VAR/POST_VAR/...)  */
  ngx_array_t		*ids;
  ngx_str_t		*name;
} ngx_http_whitelist_location_t;

/*
** this struct is used to aggregate all whitelist
** that point to the same URI or the same VARNAME
** all the "subrules" will then be stored in the "whitelist_locations"
*/
typedef struct
{
  //ngx_http_whitelist_location_t
  ngx_array_t			*whitelist_locations;
  // zone to wich the WL applies
  enum DUMMY_MATCH_ZONE		zone;
  // if the "name" is only an url, specify it
  int				uri_only:1;
  /* does the rule targets the name
     instead of the content ?*/
  int				target_name;

  ngx_str_t			*name;
  ngx_int_t			hash;
  ngx_array_t			*ids;
} ngx_http_whitelist_rule_t;

/* basic rule */
typedef struct
{
  ngx_str_t		*str; // string
  ngx_regex_compile_t   *rx;  // or regex
  ngx_int_t		transform; //transform rule to apply, as flags.
  /* ~~~~~ match zones ~~~~~~ */
  /* match in full body (POST DATA) */
  ngx_flag_t		body:1;
  ngx_flag_t		body_var:1;
  /* match in all headers */
  ngx_flag_t		headers:1;
  ngx_flag_t		headers_var:1;
  /* match in URI */
  ngx_flag_t		url:1;
  /* match in args (bla.php?<ARGS>) */
  ngx_flag_t		args:1;
  ngx_flag_t		args_var:1;
  /* match on flags (weird_uri, big_body etc. */
  ngx_flag_t		flags:1;
  /* match on file upload extension */
  ngx_flag_t		file_ext:1;
  /* set if defined "custom" match zone (GET_VAR/POST_VAR/...)  */
  ngx_flag_t		custom_location:1;
  ngx_int_t		custom_location_only;
  /* does the rule targets variable name instead ? */
  ngx_int_t		target_name;

  /* custom location match zones list (GET_VAR/POST_VAR ...) */
  ngx_array_t		*custom_locations;
  /* ~~~~~~~ specific flags ~~~~~~~~~ */
  ngx_flag_t		negative:1;
} ngx_http_basic_rule_t;

/* define for RULE TYPE in rule_t */
#define BR 1
//#define FR 2 UNUSED
//#define WR 3 UNUSED

/* flags used for 'custom match rules', like $XSS > 7 */
#define SUP 1
#define SUP_OR_EQUAL 2
#define INF 3
#define INF_OR_EQUAL 4

/*
** This struct is used to store custom scores at runtime.
**  ie : $XSS = 7
** tag is the $XSS and sc_score is 7
*/
typedef struct
{
  ngx_str_t	*sc_tag;
  ngx_int_t	sc_score;
  ngx_flag_t	block:1;
  ngx_flag_t	allow:1;
} ngx_http_special_score_t;

/*
** This one is very related to the previous one,
** it's used to store a score rule comparison.
** ie : $XSS > 7
*/
typedef struct
{
  ngx_str_t	sc_tag;
  ngx_int_t	sc_score;
  ngx_int_t	cmp;
  ngx_flag_t	block:1;
  ngx_flag_t	allow:1;
  //ngx_flag_t	log:1;  /*unused*/
} ngx_http_check_rule_t;

/* TOP level rule structure */
typedef struct
{
  /* type of the rule */
  ngx_int_t			type;
  // simply put a flag if it's a wlr, wl_id array will be used to store the whitelisted IDs
  ngx_flag_t			whitelist:1;
  ngx_int_t			*wl_id;
  /* "common" data for all rules */
  ngx_int_t			rule_id;
  ngx_str_t			*log_msg; // a specific log message
  ngx_int_t			score; //also handles DENY and ALLOW

  /* List of scores increased on rule match. */
  ngx_array_t			*sscores;
  /*ngx_str_t			*sc_tag; //specific score tag
    ngx_int_t			sc_score;  //specific score value*/
  ngx_flag_t			sc_block:1; //
  ngx_flag_t			sc_allow:1; //
  // end of specific score tag stuff
  ngx_flag_t			block:1;
  ngx_flag_t			allow:1;
  /* flag set if we're linked FROM or TO another rule  */
  ngx_flag_t			lnk_to:1;
  ngx_flag_t			lnk_from:1;
  /* pointers on specific rule stuff */
  ngx_http_basic_rule_t		*br;
} ngx_http_rule_t;

typedef struct
{
  ngx_array_t	*get_rules; /*ngx_http_rule_t*/
  ngx_array_t	*body_rules;
  ngx_array_t	*header_rules;
  ngx_array_t	*generic_rules;
  ngx_array_t	*locations; /*ngx_http_dummy_loc_conf_t*/
  ngx_log_t	*log;
} ngx_http_dummy_main_conf_t;

/* TOP level configuration structure */
typedef struct
{
  ngx_array_t	*get_rules;
  ngx_array_t	*body_rules;
  ngx_array_t	*header_rules;
  ngx_array_t	*generic_rules;
  ngx_array_t	*check_rules;
  /* raw array of whitelisted rules */
  ngx_array_t   *whitelist_rules;
  /* raw array of transformed whitelists */
  ngx_array_t	*tmp_wlr;
  /* hash table of whitelisted URL rules */
  ngx_hash_t	*wlr_url_hash;
  /* hash table of whitelisted ARGS rules */
  ngx_hash_t	*wlr_args_hash;
  /* hash table of whitelisted BODY rules */
  ngx_hash_t	*wlr_body_hash;
  /* hash table of whitelisted HEADERS rules */
  ngx_hash_t	*wlr_headers_hash;
  /* rules that are globally disabled in one location */
  ngx_array_t	*disabled_rules;
  /* counters for both processed requests and
     blocked requests, used in naxsi_fmt */
  ngx_int_t	request_processed;
  ngx_int_t	request_blocked;
  ngx_int_t	error;
  ngx_array_t	*persistant_data;
  ngx_flag_t	learning:1;
  ngx_flag_t	enabled:1;
  ngx_flag_t	force_disabled:1;
  ngx_flag_t	pushed:1;
  ngx_str_t	*denied_url;
} ngx_http_dummy_loc_conf_t;

/*
** used to store sets of matched rules during runtime
*/
typedef struct
{
  /* matched in [name] var of body */
  ngx_flag_t		body_var:1;
  /* matched in [name] var of headers */
  ngx_flag_t		headers_var:1;
  /* matched in [name] var of args */
  ngx_flag_t		args_var:1;
  /* matched on URL */
  ngx_flag_t		url:1;
  /* matched within the 'NAME' */
  ngx_flag_t		target_name:1;

  ngx_str_t		*name;
  ngx_http_rule_t	*rule;
} ngx_http_matched_rule_t;

/*
** Context structure
*/
typedef struct
{
  ngx_array_t	*special_scores;
  ngx_int_t	score;
  // blocking flags
  ngx_flag_t	block:1;
  ngx_flag_t	allow:1;
  // state
  ngx_flag_t	wait_for_body:1;
  ngx_flag_t	ready:1;
  ngx_flag_t	over:1;
  // flag request
  ngx_flag_t	weird_request:1;
  ngx_flag_t	big_request:1;
  //
  // matched rules
  ngx_array_t	*matched;
} ngx_http_request_ctx_t;

#define TOP_DENIED_URL_T	"DeniedUrl"
#define TOP_LEARNING_FLAG_T	"LearningMode"
#define TOP_ENABLED_FLAG_T	"SecRulesEnabled"
#define TOP_DISABLED_FLAG_T	"SecRulesDisabled"
#define TOP_CHECK_RULE_T	"CheckRule"
#define TOP_BASIC_RULE_T	"BasicRule"
#define TOP_MAIN_BASIC_RULE_T	"MainRule"

/*possible 'tokens' in rule */
#define ID_T "id:"
#define TRANSFORM_T "t:"
#define SCORE_T "s:"
#define PERSISTANT_SCORE_T "ps:"
#define MSG_T "msg:"
#define RX_T "rx:"
#define STR_T "str:"
#define MATCH_ZONE_T "mz:"
#define WHITELIST_T "wl:"
#define NEGATIVE_T  "negative"

extern ngx_http_dummy_loc_conf_t *dummy_lc;

void		*ngx_http_dummy_cfg_parse_one_rule(ngx_conf_t *cf,
						   ngx_str_t	*value,
						   ngx_http_rule_t *rule,
						   ngx_int_t	nb_elem);
char		*strfaststr(unsigned char *haystack, unsigned int hl,
			    unsigned char *needle, unsigned int nl);
char		*strnchr(const char *s, int c, int len);
char		*strncasechr(const char *s, int c, int len);
ngx_int_t	ngx_http_dummy_create_hashtables(ngx_http_dummy_loc_conf_t *dlc,
						 ngx_conf_t *cf);
ngx_int_t	ngx_http_dummy_create_hashtables_n(ngx_http_dummy_loc_conf_t *dlc,
						 ngx_conf_t *cf);
void		ngx_http_dummy_data_parse(ngx_http_request_ctx_t *ctx,
						  ngx_http_request_t	 *r);
ngx_int_t	ngx_http_output_forbidden_page(ngx_http_request_ctx_t *ctx,
					       ngx_http_request_t *r);
void
naxsi_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type);

/* static ngx_int_t ngx_http_dummy_subrequest(ngx_http_request_t *r,  */
/* 					   ngx_chain_t *in); */
//ngx_int_t ngx_http_dummy_subrequest(ngx_http_request_t *r);
#endif


text:
class AlterStatements < ActiveRecord::Migration[4.2]

  def self.up
    change_table :statements do |t|
      t.column :account_id, :integer
    end
  end

  def self.down
    change_table :statements do |t|
      t.remove :account_id
    end
  end

end


text:
package com.celeral.netlet.benchmark.netty;

import java.io.IOException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.celeral.netlet.benchmark.util.BenchmarkConfiguration;
import com.celeral.netlet.benchmark.util.BenchmarkResults;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * Netty Coral Block based Benchmark Echo Test Server see: http://www.coralblocks.com/index.php/2014/04/coralreactor-vs-netty-performance-comparison,
 * http://stackoverflow.com/questions/23839437/what-are-the-netty-alternatives-for-high-performance-networking,
 * http://www.coralblocks.com/NettyBench.zip
 * and https://groups.google.com/forum/#!topic/mechanical-sympathy/fhbyMnnxmaA
 *
 *
run: mvn exec:exec -Dbenchmark=netty.server
 *
 *
results=Iterations: 1000000 | Avg Time: 14.606 micros | Min Time: 0.0 nanos | Max Time: 113.0
 * micros | 75% Time: 15.0 micros | 90% Time: 17.0 micros | 99% Time: 23.0 micros | 99.9% Time: 34.0
 * micros | 99.99% Time: 72.0 micros | 99.999% Time: 80.0 micros
 */
public class EchoTcpServer extends ChannelHandlerAdapter {

  private static final Logger logger = LogManager.getLogger(EchoTcpServer.class);

  private final BenchmarkResults benchmarkResults =
      new BenchmarkResults(BenchmarkConfiguration.messageCount);
  private long start;

  public EchoTcpServer() throws IOException {
    super();
  }

  @Override
  public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    // Close the connection when an exception is raised.
    cause.printStackTrace();
    ctx.close();
  }

  @Override
  public void channelRead(ChannelHandlerContext ctx, Object msg) {
    ByteBuf byteBuf = (ByteBuf) msg;

    long timestamp = byteBuf.getLong(0);

    if (timestamp > 0) {
      benchmarkResults.addResult(System.nanoTime() - timestamp);
    } else if (timestamp == -1) {
      start = System.currentTimeMillis();
      logger.info("Received the first message.");
    } else if (timestamp == -2) {
      logger.info(
          "Finished receiving messages! Overall test time: {} millis",
          System.currentTimeMillis() - start);
      ctx.close();
      benchmarkResults.printResults(System.out);
      return;
    } else if (timestamp < 0) {
      logger.error("Received bad timestamp {}", timestamp);
      ctx.close();
      return;
    }

    ctx.writeAndFlush(msg);
  }

  public static void main(String[] args) throws Exception {
    int port;
    if (args.length > 0) {
      port = Integer.parseInt(args[0]);
    } else {
      port = 8080;
    }

    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
      ServerBootstrap b = new ServerBootstrap();
      b.group(bossGroup, workerGroup)
          .channel(NioServerSocketChannel.class)
          .childHandler(
              new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) throws Exception {
                  ch.pipeline().addLast(new EchoTcpServer());
                }
              })
          .option(ChannelOption.SO_BACKLOG, 128)
          .childOption(ChannelOption.SO_KEEPALIVE, true);

      ChannelFuture f = b.bind(port).sync(); // (7)
      f.channel().closeFuture().sync();
    } finally {
      workerGroup.shutdownGracefully();
      bossGroup.shutdownGracefully();
    }
  }
}


text:
"""Script of running base tests on utils."""

from simplified_models import TrueModel
from utils import Coordinate2d

def create_input_data():
    """Utility function for creating input data."""
    position = Coordinate2d(3.0, 4.0)
    speed = Coordinate2d(2.0, 5.0)
    sample_time = 0.1
    return {'position': position,
            'speed': speed,
            'sample_time': sample_time}

def test_base():
    """Check we can create the model."""
    input_data = create_input_data()
    base_model = TrueModel(input_data['position'],
                           input_data['speed'],
                           input_data['sample_time'])
    assert(True)

def test_get_position_velocity():
    """Check we can get the right value of velocity."""
    input_data = create_input_data()
    base_model = TrueModel(input_data['position'],
                           input_data['speed'],
                           input_data['sample_time'])
    assert(base_model.get_position() == input_data['position'])
    assert(base_model.get_speed() == input_data['speed'])

def test_get_state():
    """Verify we return the correct state."""
    input_data = create_input_data()
    base_model = TrueModel(input_data['position'],
                           input_data['speed'],
                           input_data['sample_time'])
    state = base_model.get_state()
    assert(state[0] == input_data['position'].get_x())
    assert(state[1] == input_data['speed'].get_x())
    assert(state[2] == input_data['position'].get_y())
    assert(state[3] == input_data['speed'].get_y())

def test_set_state():
    """Verify we set the state correctly."""
    input_data = create_input_data()
    base_model = TrueModel(input_data['position'],
                           input_data['speed'],
                           input_data['sample_time'])
    state = [0, 1, 2, 3]
    base_model.set_state(state)
    new_state = base_model.get_state()
    for idx in range(len(state)):
        assert(state[idx] == new_state[idx])

    assert(base_model.get_position() == Coordinate2d(0, 2))
    assert(base_model.get_speed() == Coordinate2d(1, 3))

def test_update_step():
        """Verify update step."""
        initial_position = Coordinate2d(0, 0)
        initial_speed = Coordinate2d(3, 4)
        sample_time = 0.1
        base_model = TrueModel(initial_position,
                               initial_speed,
                               sample_time)
        acceleration = Coordinate2d(0, 0)
        base_model.update_state(acceleration)
        new_state = base_model.get_state()
        assert abs(new_state[0] - 0.3) < 1e-8
        assert(new_state[1] == 3)
        assert abs(new_state[2] - 0.4) < 1e-8
        assert(new_state[3] == 4)

def compute_new_state(initial_position, initial_speed, acceleration,
                      sample_time):
        expected_position_x = initial_position.get_x() + \
            sample_time * initial_speed.get_x() + \
            (sample_time**2) / 2 * acceleration.get_x()
        expected_position_y = initial_position.get_y() + \
            sample_time * initial_speed.get_y() + \
            (sample_time**2) / 2 * acceleration.get_y()

        expected_speed_x = initial_speed.get_x() + \
            sample_time * acceleration.get_x()
        expected_speed_y = initial_speed.get_y() + \
            sample_time * acceleration.get_y()
        return (expected_position_x, expected_speed_x,
                expected_position_y, expected_speed_y)

def test_update_step_acceleration():
        """Verify update step with non zero acceleration."""
        initial_position = Coordinate2d(0, 0)
        initial_speed = Coordinate2d(0, 0)
        sample_time = 0.1
        base_model = TrueModel(initial_position,
                               initial_speed,
                               sample_time)

        for iteration in range(5):
            acceleration = Coordinate2d(1*iteration, 2*iteration)
            current_position = base_model.get_position()
            current_speed = base_model.get_speed()
            base_model.update_state(acceleration)
            new_state = base_model.get_state()
            expected_state = compute_new_state(
                current_position, current_speed,
                acceleration, sample_time)

            assert all([abs(new_state[i] - expected_state[i]) < 1e-8]
                       for i in range(len(new_state)))


text:
<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <withJansi>false</withJansi>
        <!-- encoders are assigned the type
             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="info">
        <appender-ref ref="STDOUT" />
    </root>

    <logger name="io.micronaut.context.condition" level="DEBUG"/>
</configuration>


text:
// coding: utf-8
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------

#ifndef XPCC__DYNAMIC_ARRAY_HPP
	#error	"Don't include this file directly, use 'vector.hpp' instead"
#endif

// ----------------------------------------------------------------------------
template <typename T, typename Allocator>
xpcc::DynamicArray<T, Allocator>::DynamicArray(const Allocator& alloc) :
	allocator(alloc),
	size(0), capacity(0), values(0)
{
}

template <typename T, typename Allocator>
xpcc::DynamicArray<T, Allocator>::DynamicArray(SizeType n, const Allocator& alloc) :
	allocator(alloc), size(0), capacity(n)
{
	this->values = this->allocator.allocate(n);
}

template <typename T, typename Allocator>
xpcc::DynamicArray<T, Allocator>::DynamicArray(SizeType n, const T& value, const Allocator& alloc) :
	allocator(alloc), size(n), capacity(n)
{
	this->values = this->allocator.allocate(n);
	for (SizeType i = 0; i < n; ++i) {
		allocator.construct(&this->values[i], value);
	}
}

template <typename T, typename Allocator>
xpcc::DynamicArray<T, Allocator>::DynamicArray(std::initializer_list<T> init, const Allocator& alloc) :
	allocator(alloc), size(init.size()), capacity(init.size())
{
	this->values = this->allocator.allocate(init.size());
	std::size_t ii = 0;
	for (auto value : init) {
		allocator.construct(&this->values[ii], value);
		++ii;
	}
}

template <typename T, typename Allocator>
xpcc::DynamicArray<T, Allocator>::DynamicArray(const DynamicArray& other) :
	allocator(other.allocator),
	size(other.size), capacity(other.capacity)
{
	this->values = allocator.allocate(other.capacity);
	for (SizeType i = 0; i < this->size; ++i) {
		this->allocator.construct(&this->values[i], other.values[i]);
	}
}

template <typename T, typename Allocator>
xpcc::DynamicArray<T, Allocator>::~DynamicArray()
{
	for (SizeType i = 0; i < this->size; ++i) {
		this->allocator.destroy(&this->values[i]);
	}
	this->allocator.deallocate(this->values);
}

template <typename T, typename Allocator>
xpcc::DynamicArray<T, Allocator>&
xpcc::DynamicArray<T, Allocator>::operator = (const DynamicArray& other)
{
	for (SizeType i = 0; i < this->size; ++i) {
		this->allocator.destroy(&this->values[i]);
	}
	this->allocator.deallocate(this->values);

	this->allocator = other.allocator;
	this->size = other.size;
	this->capacity = other.capacity;
	this->values = this->allocator.allocate(this->capacity);

	for (SizeType i = 0; i < this->size; ++i) {
		this->allocator.construct(&this->values[i], other.values[i]);
	}
	return *this;
}

// ----------------------------------------------------------------------------
template <typename T, typename Allocator>
void
xpcc::DynamicArray<T, Allocator>::reserve(SizeType n)
{
	if (n <= (this->capacity - this->size)) {
		// capacity is already big enough, nothing to do.
		return;
	}

	// allocate new memory
	this->relocate(this->size + n);
}

// ----------------------------------------------------------------------------
template <typename T, typename Allocator>
void
xpcc::DynamicArray<T, Allocator>::clear()
{
	for (SizeType i = 0; i < this->size; ++i) {
		this->allocator.destroy(&this->values[i]);
	}
	this->allocator.deallocate(this->values);
	this->values = 0;

	this->size = 0;
	this->capacity = 0;
}

// ----------------------------------------------------------------------------
template <typename T, typename Allocator>
void
xpcc::DynamicArray<T, Allocator>::removeAll()
{
	for (SizeType i = 0; i < this->size; ++i) {
		this->allocator.destroy(&this->values[i]);
	}
	this->size = 0;
}

// ----------------------------------------------------------------------------
template <typename T, typename Allocator>
void
xpcc::DynamicArray<T, Allocator>::append(const T& value)
{
	if (this->capacity == this->size)
	{
		// allocate new memory if no more space is left
		SizeType n = this->size + (this->size + 1) / 2;
		if (n == 0) {
			n = 1;
		}
		this->relocate(n);
	}

	this->allocator.construct(&this->values[this->size], value);
	++this->size;
}

// ----------------------------------------------------------------------------
template <typename T, typename Allocator>
void
xpcc::DynamicArray<T, Allocator>::removeBack()
{
	--this->size;

	// call destructor
	this->allocator.destroy(&this->values[this->size]);
}

// ----------------------------------------------------------------------------
template <typename T, typename Allocator>
void
xpcc::DynamicArray<T, Allocator>::relocate(SizeType n)
{
	this->capacity = n;

	T* newBuffer = allocator.allocate(n);
	for (SizeType i = 0; i < this->size; ++i) {
		this->allocator.construct(&newBuffer[i], this->values[i]);
		this->allocator.destroy(&this->values[i]);
	}
	this->allocator.deallocate(this->values);

	this->values = newBuffer;
}

// ----------------------------------------------------------------------------
template <typename T, typename Allocator>
typename xpcc::DynamicArray<T, Allocator>::iterator
xpcc::DynamicArray<T, Allocator>::begin()
{
	return iterator(this, 0);
}

template <typename T, typename Allocator>
typename xpcc::DynamicArray<T, Allocator>::iterator
xpcc::DynamicArray<T, Allocator>::end()
{
	return iterator(this, size);
}

template <typename T, typename Allocator>
typename xpcc::DynamicArray<T, Allocator>::iterator
xpcc::DynamicArray<T, Allocator>::find(const T& value)
{
	xpcc::DynamicArray<T, Allocator>::iterator iter = this->begin();

	for(; iter != this->end(); ++iter)
	{
		if((*iter) == value) {
			return iter;
		}
	}

	// return end() if value has not been found
	return iter;
}

template <typename T, typename Allocator>
typename xpcc::DynamicArray<T, Allocator>::const_iterator
xpcc::DynamicArray<T, Allocator>::begin() const
{
	return const_iterator(this, 0);
}

template <typename T, typename Allocator>
typename xpcc::DynamicArray<T, Allocator>::const_iterator
xpcc::DynamicArray<T, Allocator>::end() const
{
	return const_iterator(this, size);
}

template <typename T, typename Allocator>
typename xpcc::DynamicArray<T, Allocator>::const_iterator
xpcc::DynamicArray<T, Allocator>::find(const T& value) const
{
	xpcc::DynamicArray<T, Allocator>::const_iterator iter = this->begin();

	for(; iter != this->end(); ++iter)
	{
		if((*iter) == value) {
			return iter;
		}
	}

	// return end() if value has not been found
	return iter;
}