text:
"""
Fake Yorktown device (5 qubit).
"""

import os
from qiskit.providers.fake_provider import fake_qasm_backend, fake_backend

class FakeYorktownV2(fake_backend.FakeBackendV2):
    """A fake 5 qubit backend.

    .. code-block:: text

            1
          / |
        0 - 2 - 3
            | /
            4
    """

    dirname = os.path.dirname(__file__)
    conf_filename = "conf_yorktown.json"
    props_filename = "props_yorktown.json"
    backend_name = "fake_yorktown_v2"

class FakeYorktown(fake_qasm_backend.FakeQasmBackend):
    """A fake 5 qubit backend.

    .. code-block:: text

            1
          / |
        0 - 2 - 3
            | /
            4
    """

    dirname = os.path.dirname(__file__)
    conf_filename = "conf_yorktown.json"
    props_filename = "props_yorktown.json"
    backend_name = "fake_yorktown"

redpajama_set_name: RedPajamaGithub


text:
require 'bundler'
begin
  Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
  $stderr.puts e.message
  $stderr.puts "Run `bundle install` to install missing gems"
  exit e.status_code
end

$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
require 'dyndns-host-update'

require 'rspec/expectations'


text:
  Eppes est
       un village
       situé dans le département de l'Aisne en Picardie. Elle comptait 372 habitants en 2008.

Si vous pensez venir habiter à Eppes, vous pourrez facilement trouver une maison à vendre.

La commune offre quelques  équipements, elle propose entre autres un terrain de sport.

À proximité de Eppes sont situées les communes de
Courtrizy-et-Fussigny localisée à 5 km, 75 habitants,
Gizy située à 5 km, 697 habitants,
Athies-sous-Laon située à 4 km, 2 230 habitants,
Festieux située à 4 km, 523 habitants,
Veslud localisée à 2 km, 240 habitants,
Montchâlons située à 4 km, 67 habitants,
 entre autres. De plus, Eppes est située à seulement huit km de Laon.

Le parc de logements, à Eppes, se décomposait en 2011 en huit appartements et 175 maisons soit
 un marché plutôt équilibré.


text:
<?php
declare(strict_types = 1);

namespace Pages\Components;

use Pages\IViewable;

final class TitledSectionComponent implements IViewable{
  public static function wrap(string $title, ?IViewable $component): ?IViewable{
    return $component === null ? null : new TitledSectionComponent($title, $component);
  }

  private string $title;
  private IViewable $component;

  public function __construct(string $title, IViewable $component){
    $this->title = $title;
    $this->component = $component;
  }

  public function echoBody(): void{
    echo '
';
    echo $this->title;
    echo '

';
    $this->component->echoBody();
    echo '
';
  }
}

?>


text:
from __future__ import unicode_literals, print_function, division
import logging
import requests
from requests.auth import HTTPBasicAuth
from expenditure_application.collection import DictObject
from expenditure_application.config import secure_config

LOGGER = logging.getLogger(__name__)

MAILGUN_API_BASE_URL = 'https://api.mailgun.net/v3'

def send_mail(subject, html):
    data = DictObject(to=secure_config.mailgun_to, subject=subject, html=html)
    data['from'] = secure_config.mailgun_from
    response = None
    try:
        response = requests.post('{}/{}/messages'.format(MAILGUN_API_BASE_URL, secure_config.mailgun_domain),
                                 auth=HTTPBasicAuth('api', secure_config.mailgun_api_key), data=data)
        response.raise_for_status()
    except Exception:
        LOGGER.exception('Got exception when send mail to {}, {}'.format(data.to, response.content if response else ''))
        raise
    else:
        LOGGER.info(response.content)
        print(response.content)

if __name__ == '__main__':
    send_mail('test', '
nothing
')


text:
module Switchboard
  class ContactImporter
    def self.from_row(row)
      contact = Contact.find_or_initialize_by email: row[:contact_email]

      contact.name = row[:contact_name]
      contact.title = row[:contact_title]
      #contact.email = row[:contact_email]

      phone = Switchboard::ContactPhoneImporter.from_row(row)
      contact.phones << phone
      phone.save!

      contact
    end
  end
end


text:
/**
 * Question 3.1:
 * Use a single array to implement three stacks.
 */

public class Solution1 {

    public static void main(String[] args) {
        ThreeStacks stacks = new ThreeStacks(5);
        System.out.println(stacks.isEmpty(1));
        stacks.push(2, 1);
        stacks.push(2, 2);
        System.out.println(stacks.pop(2));
        System.out.println(stacks.size(2));
        System.out.println(stacks.isEmpty(2));
    }
}


text:
import os
import sys
import argparse
import traceback
sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir))
from toollib.group import Group,UnsortedInputGrouper
import scipy.stats as ss

class KSGroup(Group):
    def __init__(self, tup):
        super(KSGroup, self).__init__(tup)
        self.samples = []

    def add(self, chunks):
        self.samples.append(float(chunks[args.column]))

    def done(self):
        jdelim = args.delimiter if args.delimiter != None else ' '
        if len(self.tup) > 0:
            args.outfile.write(jdelim.join(self.tup) + jdelim)
        args.outfile.write(jdelim.join(map(str, ss.kstest(self.samples, args.distf, args=args.params))) + '\n')

if __name__ == "__main__":
    # set up command line args
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,\
                                     description='Compare the request distributions of all clients')
    parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
    parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'), default=sys.stdout)
    parser.add_argument('-s', '--source', default='scipy.stats', choices=['scipy.stats', 'lambda'], help='source of the distribution to fit')
    parser.add_argument('-i', '--dist', default='paretoLomax')
    parser.add_argument('-p', '--params', default='', help='initial parameters')
    parser.add_argument('-c', '--column', type=int, default=0)
    parser.add_argument('-g', '--group', nargs='+', type=int, default=[])
    parser.add_argument('-d', '--delimiter', default=None)
    args = parser.parse_args()

    args.params = map(float, args.params.split(args.delimiter))

    if args.source == 'scipy.stats':
        args.source = ss
    else:
        args.source = None

    if args.source:
        mod = args.source
        for c in args.dist.split('.'):
            mod = getattr(mod, c)
        args.distf = mod
    else:
        args.distf = eval(args.dist)

    grouper = UnsortedInputGrouper(args.infile, KSGroup, args.group, args.delimiter)
    grouper.group()


text:
/*
 * DEBUG: section 54    Interprocess Communication
 *
 */

#ifndef SQUID_IPC_FORWARD_H
#define SQUID_IPC_FORWARD_H

namespace Ipc
{

class TypedMsgHdr;
class StrandCoord;
class HereIamMessage;
class StrandSearchResponse;
class Forwarder;
class Inquirer;
class Request;
class Response;

} // namespace Ipc

#endif /* SQUID_IPC_FORWARD_H */


text:
require "app3/engine"

module App3
end


text:
import {Direction, Directionality} from '@angular/cdk/bidi';
import {ENTER, LEFT_ARROW, RIGHT_ARROW, SPACE} from '@angular/cdk/keycodes';
import {
  AfterContentChecked,
  AfterContentInit,
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Component,
  ContentChildren,
  ElementRef,
  EventEmitter,
  Input,
  OnDestroy,
  Optional,
  Output,
  QueryList,
  ViewChild,
  ViewEncapsulation,
} from '@angular/core';
import {CanDisableRipple, mixinDisableRipple} from '@angular/material/core';
import {ViewportRuler} from '@angular/cdk/scrolling';
import {coerceNumberProperty} from '@angular/cdk/coercion';
import {MatTabLabelWrapper} from './tab-label-wrapper';

/**
 * The directions that scrolling can go in when the header's tabs exceed the header width. 'After'
 * will scroll the header towards the end of the tabs list and 'before' will scroll towards the
 * beginning of the list.
 */
export type ScrollDirection = 'after' | 'before';

// Boilerplate for applying mixins to MatTabHeader.
/** @docs-private */
export class MatTabHeaderBase {}
export const _MatTabHeaderMixinBase = mixinDisableRipple(MatTabHeaderBase);

/**
 * The header of the tab group which displays a list of all the tabs in the tab group. Includes
 * an ink bar that follows the currently selected tab. When the tabs list's width exceeds the
 * width of the header container, then arrows will be displayed to allow the user to scroll
 * left and right across the header.
 * @docs-private
 */
@Component({
  moduleId: module.id,
  selector: 'mat-tab-header',
  templateUrl: 'tab-header.html',
  styleUrls: ['tab-header.css'],
  inputs: ['disableRipple'],
  encapsulation: ViewEncapsulation.None,
  preserveWhitespaces: false,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: {
    'class': 'mat-tab-header',
    '[class.mat-tab-header-pagination-controls-enabled]': '_showPaginationControls',
    '[class.mat-tab-header-rtl]': "_getLayoutDirection() == 'rtl'",
  },
})
export class MatTabHeader extends _MatTabHeaderMixinBase
    implements AfterContentChecked, AfterContentInit, OnDestroy, CanDisableRipple {

  @ContentChildren(MatTabLabelWrapper) _labelWrappers: QueryList<MatTabLabelWrapper>;

  /** The tab index that is focused. */
  private _focusIndex: number = 0;

  /** Whether the header should scroll to the selected index after the view has been checked. */
  private _selectedIndexChanged = false;

  /** Whether the tab list can be scrolled more towards the end of the tab label list. */
  _disableScrollAfter = true;

  /** Whether the tab list can be scrolled more towards the beginning of the tab label list. */
  _disableScrollBefore = true;

  private _selectedIndex: number = 0;

  /** The index of the active tab. */
  @Input()
  get selectedIndex(): number { return this._selectedIndex; }
  set selectedIndex(value: number) {
    value = coerceNumberProperty(value);
    this._selectedIndexChanged = this._selectedIndex != value;
    this._selectedIndex = value;
    this._focusIndex = value;
  }

  /** Whether the controls for pagination should be displayed */
  _showPaginationControls = false;

  /** Event emitted when a label is focused. */
  @Output() indexFocused = new EventEmitter();

  constructor(private _elementRef: ElementRef,
    private _changeDetectorRef: ChangeDetectorRef,
    private _viewportRuler: ViewportRuler,
    @Optional() private _dir: Directionality) {
    super();
  }

  ngAfterContentChecked(): void {
  }

  /** When the focus index is set, we must manually send focus to the correct label */
  set focusIndex(value: number) {
    if (!this._isValidIndex(value) || this._focusIndex == value) { return; }

    this._focusIndex = value;
    this.indexFocused.emit(value);
    this._setTabFocus(value);
  }

  /** Tracks which element has focus; used for keyboard navigation */
  get focusIndex(): number { return this._focusIndex; }

  /**
   * Determines if an index is valid.  If the tabs are not ready yet, we assume that the user is
   * providing a valid index and return true.
   */
  _isValidIndex(index: number): boolean {
    if (!this._labelWrappers) { return true; }

    const tab = this._labelWrappers ? this._labelWrappers.toArray()[index] : null;
    return !!tab && !tab.disabled;
  }

  /**
   * Sets focus on the HTML element for the label wrapper and scrolls it into the view if
   * scrolling is enabled.
   */
  _setTabFocus(tabIndex: number) {
    console.log(tabIndex);
  }

  _handleKeydown(event: KeyboardEvent) {
    console.log(event);
  }

  /**
   * Aligns the ink bar to the selected tab on load.
   */
  ngAfterContentInit() {
  }

  ngOnDestroy() {
  }

  /**
   * Callback for when the MutationObserver detects that the content has changed.
   */
  _onContentChanges() {

  }

  /**
   * Moves the tab list in the 'before' or 'after' direction (towards the beginning of the list or
   * the end of the list, respectively). The distance to scroll is computed to be a third of the
   * length of the tab list view window.
   *
   * This is an expensive call that forces a layout reflow to compute box and scroll metrics and
   * should be called sparingly.
   */
  _scrollHeader(scrollDir: ScrollDirection) {
    console.log(scrollDir);
  }

  /** The layout direction of the containing app. */
  _getLayoutDirection(): Direction {
    return this._dir && this._dir.value === 'rtl' ? 'rtl' : 'ltr';
  }

}


text:
**Vanilla** is a template for traditional website builds, providing a conventional file organization system. It includes essential libraries and base files for front-end development. Similar to [HTML5 Reset](https://github.com/murtaugh/HTML5-Reset).

## Libraries and Base Files

### jQuery
Vanilla uses **jQuery 2.1.0** (http://jquery.com/download/). The line breaks in the original file have been removed.

### reset.css
A custom **reset.css** optimized for projects with conventional requirements.

## Attribution
Inspired by HTML5 Reset: https://github.com/murtaugh/HTML5-Reset


text:
package com.foc.formula.function;

import java.sql.Date;

import com.foc.business.currency.Currencies;
import com.foc.business.currency.Currency;
import com.foc.formula.FFormulaNode;
import com.foc.formula.FunctionFactory;
import com.foc.util.FocMath;

public class FunctionCurrencyDifference extends Function{

	private static final String FUNCTION_NAME   = "FX_RATE";
	private static final String OPERATOR_SYMBOL = "";

	@Override
	public synchronized Object compute(FFormulaNode formulaNode) {
		double result = 0.0;

		if(formulaNode != null && formulaNode.getChildCount() >= 2){
			FFormulaNode childNode1 = (FFormulaNode) formulaNode.getChildAt(0);
			FFormulaNode childNode2 = (FFormulaNode) formulaNode.getChildAt(1);
			FFormulaNode childNode3 = null;

			if(formulaNode.getChildCount() > 2){
				childNode3 = (FFormulaNode) formulaNode.getChildAt(2);
			}

			if(childNode1 != null && childNode2 != null){
				Object childNode1Value = childNode1.getCalculatedValue();
				Object childNode2Value = childNode2.getCalculatedValue();
				Object childNode3Value = childNode3.getCalculatedValue();

				Currency curr1 = Currencies.getCurrencyByName(childNode1Value.toString());
				Currency curr2 = Currencies.getCurrencyByName(childNode2Value.toString());

				if(childNode3Value != null){
					result = Currencies.getRate((Date)childNode3Value, curr1, curr2);
				}else{
					result = Currencies.getRate(curr1, curr2);
				}
			}
		}
		return result;

	}

	@Override
	public boolean needsManualNotificationToCompute() {
		return false;
	}

	@Override
	public String getName() {
		return FUNCTION_NAME;
	}

	@Override
	public String getOperatorSymbol() {
		return OPERATOR_SYMBOL;
	}

	@Override
	public int getOperatorPriority() {
		return FunctionFactory.PRIORITY_NOT_APPLICABLE;
	}

}


text:
use std::io;
use std::error;
use std::fmt;
use std::result;
use std::path::PathBuf;

use toml::Parser;
use chemfiles;

use lumol::units::ParseError;
use lumol::sys::TrajectoryError;

/// Custom `Result` type for input files
pub type Result<T> = result::Result<T, Error>;

/// Possible causes of error when reading input files
#[derive(Debug)]
pub enum Error {
    /// Error in the TOML input file
    TOML(String),
    /// IO error, and associated file path
    Io(io::Error, PathBuf),
    /// Error while reading a trajectory file
    Trajectory(TrajectoryError),
    /// File content error: missing sections, bad data types
    Config(String),
    /// Unit parsing error
    Unit(ParseError),
}

impl From<(io::Error, PathBuf)> for Error {
    fn from((err, path): (io::Error, PathBuf)) -> Error {Error::Io(err, path)}
}

impl From<TrajectoryError> for Error {
    fn from(err: TrajectoryError) -> Error {Error::Trajectory(err)}
}

impl From<chemfiles::Error> for Error {
    fn from(err: chemfiles::Error) -> Error {
        Error::Trajectory(TrajectoryError::from(err))
    }
}

impl<'a> From<&'a str> for Error {
    fn from(err: &'a str) -> Error {
        Error::Config(String::from(err))
    }
}

impl From<String> for Error {
    fn from(err: String) -> Error {
        Error::Config(err)
    }
}

impl From<ParseError> for Error {
    fn from(err: ParseError) -> Error {Error::Unit(err)}
}

impl fmt::Display for Error {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
        use std::error::Error as StdError;
        let message = match *self {
            Error::Io(ref err, ref path) => {
                match err.kind() {
                    io::ErrorKind::NotFound => {
                        format!("can not find '{}'", path.display())
                    }
                    io::ErrorKind::PermissionDenied => {
                        format!("permission to access '{}' denied", path.display())
                    }
                    _ => {
                        format!("error with '{}': {}", path.display(), self.description())
                    }
                }
            }
            _ => String::from(self.description())
        };
        try!(write!(fmt, "{}", message));
        Ok(())
    }
}

impl error::Error for Error {
    fn description(&self) -> &str {
        match *self {
            Error::TOML(ref err) | Error::Config(ref err) => err,
            Error::Io(ref err, _) => err.description(),
            Error::Trajectory(ref err) => err.description(),
            Error::Unit(ref err) => err.description(),
        }
    }

    fn cause(&self) -> Option<&error::Error> {
        match *self {
            Error::TOML(..) | Error::Config(..) => None,
            Error::Io(ref err, _) => Some(err),
            Error::Trajectory(ref err) => Some(err),
            Error::Unit(ref err) => Some(err),
        }
    }
}

pub fn toml_error_to_string(parser: &Parser) -> String {
    let errors = parser.errors.iter().map(|error|{
        let (line, _) = parser.to_linecol(error.lo);
        format!("{} at line {}", error.desc, line + 1)
    }).collect::<Vec<_>>().join("\n    ");

    let plural = if errors.len() == 1 {""} else {"s"};
    return format!("TOML parsing error{}: {}", plural, errors);
}


text:
@implementation UIImage (DIImageWithSize)
- (UIImage *)imageWithSize:(CGSize)newSize {
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}
@end


text:
var bs = module.exports = {}
var Component = require('./component')
var inherits = require('inherits')
var Manager = require('./manager')
var Entity = require('./entity')

bs.Entity = Entity

bs.manager = Manager
bs.component = Component

bs.define = function() {
  return Entity.extend()
}


text: A [ko-grid](https://github.com/benschulz/ko-grid) extension to select rows.


text:
@interface AppDelegate : NSObject <UIApplicationDelegate> {

}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;

@end


text:
import Ember from 'ember';

export default Ember.Component.extend({
  classNames: ['ember-countup'],
  tagName: 'span',

  didInsertElement() {
    this._insertAndStartCountUp();
  },

  changed: Ember.observer('startVal', 'endVal', 'decimals', 'duration', 'useEasing', 'easingFn', 'useGrouping', 'separator', 'decimal', 'prefix', 'suffix', 'formattingFn', 'onComplete', function() {
    this._insertAndStartCountUp();
  }),

  _insertAndStartCountUp() {
    Ember.run.next(() => {
      var countup = new CountUp(
        this.get('elementId'),
        this.get('startVal') || 0,
        this.get('endVal') || 0,
        this.get('decimals') || 0,
        this.get('duration') || 2,
        {
          useEasing: this.get('useEasing'),
          easingFn: this.get('easingFn'),
          useGrouping: this.get('useGrouping'),
          separator: this.get('separator') || ',',
          decimal: this.get('decimal') || '.',
          prefix: this.get('prefix') || '',
          suffix: this.get('suffix') || '',
          formattingFn: this.get('formattingFn')
        }
      );

      if (this.attrs.onComplete) {
        countup.start(this.attrs.onComplete);
      } else {
        countup.start();
      }
    });
  }
});


text:
'use strict';

// MAIN //

/**
* Returns the index of a search value in a strided array-like object.
*
* @private
* @param {NonNegativeInteger} N - number of elements to search
* @param {ArrayLike} arr - array to search
* @param {integer} stride - index stride
* @param {NonNegativeInteger} offset - index offset
* @param {*} value - search value
* @returns {integer} search value index
*
* @example
* var arr = [ 1, 2, 3 ];
*
* var bool = indexOf( arr.length, arr, 1, 0, 2 );
* // returns 1
*
* bool = indexOf( arr.length, arr, 1, 0, 4 );
* // returns -1
*/
function indexOf( N, arr, stride, offset, value ) {
	var idx;
	var i;

	idx = offset;
	for ( i = 0; i < N; i++ ) {
		if ( arr[ idx ] === value ) {
			return idx;
		}
		idx += stride;
	}
	return -1;
}

// EXPORTS //

module.exports = indexOf;


text:
package org.apache.lucene.index;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.BinaryDocValuesField;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.DoubleDocValuesField;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.FloatDocValuesField;
import org.apache.lucene.document.IntField;
import org.apache.lucene.document.LongField;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.SortedDocValuesField;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.FieldInfo.IndexOptions;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.BaseDirectoryWrapper;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.NIOFSDirectory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.store.SimpleFSDirectory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.Constants;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.util.StringHelper;
import org.apache.lucene.util._TestUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;

/*
  Verify we can read the pre-5.0 file format, do searches
  against it, and add documents to it.
*/
// note: add this if we make a 4.x impersonator
// TODO: don't use 4.x codec, its unrealistic since it means
// we won't even be running the actual code, only the impostor
// @SuppressCodecs("Lucene4x")
// Sep codec cannot yet handle the offsets in our 4.x index!
@SuppressCodecs({"MockFixedIntBlock", "MockVariableIntBlock", "MockSep", "MockRandom", "Lucene40", "Lucene41", "Lucene42", "Lucene45"})
public class TestBackwardsCompatibility extends LuceneTestCase {

  // Uncomment these cases & run them on an older Lucene version,
  // to generate indexes to test backwards compatibility.  These
  // indexes will be created under directory /tmp/idx/.
  //
  // However, you must first disable the Lucene TestSecurityManager,
  // which will otherwise disallow writing outside of the build/
  // directory - to do this, comment out the "java.security.manager"
  // <sysproperty> under the "test-macro" <macrodef>.
  //
  // Be sure to create the indexes with the actual format:
  //  ant test -Dtestcase=TestBackwardsCompatibility -Dversion=x.y.z
  //      -Dtests.codec=LuceneXY -Dtests.postingsformat=LuceneXY -Dtests.docvaluesformat=LuceneXY
  //
  // Zip up the generated indexes:
  //
  //    cd /tmp/idx/index.cfs   ; zip index.<VERSION>.cfs.zip *
  //    cd /tmp/idx/index.nocfs ; zip index.<VERSION>.nocfs.zip *
  //
  // Then move those 2 zip files to your trunk checkout and add them
  // to the oldNames array.

  /*
  public void testCreateCFS() throws IOException {
    createIndex("index.cfs", true, false);
  }

  public void testCreateNoCFS() throws IOException {
    createIndex("index.nocfs", false, false);
  }
  */

/*
  // These are only needed for the special upgrade test to verify
  // that also single-segment indexes are correctly upgraded by IndexUpgrader.
  // You don't need them to be build for non-4.0 (the test is happy with just one
  // "old" segment format, version is unimportant:

  public void testCreateSingleSegmentCFS() throws IOException {
    createIndex("index.singlesegment.cfs", true, true);
  }

  public void testCreateSingleSegmentNoCFS() throws IOException {
    createIndex("index.singlesegment.nocfs", false, true);
  }

*/

  /*
  public void testCreateMoreTermsIndex() throws Exception {
    // we use a real directory name that is not cleaned up,
    // because this method is only used to create backwards
    // indexes:
    File indexDir = new File("moreterms");
    _TestUtil.rmDir(indexDir);
    Directory dir = newFSDirectory(indexDir);

    LogByteSizeMergePolicy mp = new LogByteSizeMergePolicy();
    mp.setUseCompoundFile(false);
    mp.setNoCFSRatio(1.0);
    mp.setMaxCFSSegmentSizeMB(Double.POSITIVE_INFINITY);
    // TODO: remove randomness
    IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()))
      .setMergePolicy(mp);
    conf.setCodec(Codec.forName("Lucene40"));
    IndexWriter writer = new IndexWriter(dir, conf);
    LineFileDocs docs = new LineFileDocs(null, true);
    for(int i=0;i<50;i++) {
      writer.addDocument(docs.nextDoc());
    }
    writer.close();
    dir.close();

    // Gives you time to copy the index out!: (there is also
    // a test option to not remove temp dir...):
    Thread.sleep(100000);
  }
  */

  final static String[] oldNames = {"40.cfs",
                                    "40.nocfs",
                                    "41.cfs",
                                    "41.nocfs",
                                    "42.cfs",
                                    "42.nocfs"
  };

  final String[] unsupportedNames = {"19.cfs",
                                     "19.nocfs",
                                     "20.cfs",
                                     "20.nocfs",
                                     "21.cfs",
                                     "21.nocfs",
                                     "22.cfs",
                                     "22.nocfs",
                                     "23.cfs",
                                     "23.nocfs",
                                     "24.cfs",
                                     "24.nocfs",
                                     "29.cfs",
                                     "29.nocfs",
                                     "30.cfs",
                                     "30.nocfs",
                                     "31.cfs",
                                     "31.nocfs",
                                     "32.cfs",
                                     "32.nocfs",
                                     "34.cfs",
                                     "34.nocfs"
  };

  final static String[] oldSingleSegmentNames = {"40.optimized.cfs",
                                                 "40.optimized.nocfs",
  };

  static Map<String,Directory> oldIndexDirs;

  /**
   * Randomizes the use of some of hte constructor variations
   */
  private static IndexUpgrader newIndexUpgrader(Directory dir) {
    final boolean streamType = random().nextBoolean();
    final int choice = _TestUtil.nextInt(random(), 0, 2);
    switch (choice) {
      case 0: return new IndexUpgrader(dir, TEST_VERSION_CURRENT);
      case 1: return new IndexUpgrader(dir, TEST_VERSION_CURRENT,
                                       streamType ? null : System.err, false);
      case 2: return new IndexUpgrader(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, null), false);
      default: fail("case statement didn't get updated when random bounds changed");
    }
    return null; // never get here
  }

  @BeforeClass
  public static void beforeClass() throws Exception {
    assertFalse("test infra is broken!", LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE);
    List<String> names = new ArrayList<String>(oldNames.length + oldSingleSegmentNames.length);
    names.addAll(Arrays.asList(oldNames));
    names.addAll(Arrays.asList(oldSingleSegmentNames));
    oldIndexDirs = new HashMap<String,Directory>();
    for (String name : names) {
      File dir = _TestUtil.getTempDir(name);
      File dataFile = new File(TestBackwardsCompatibility.class.getResource("index." + name + ".zip").toURI());
      _TestUtil.unzip(dataFile, dir);
      oldIndexDirs.put(name, newFSDirectory(dir));
    }
  }

  @AfterClass
  public static void afterClass() throws Exception {
    for (Directory d : oldIndexDirs.values()) {
      d.close();
    }
    oldIndexDirs = null;
  }

  /** This test checks that *only* IndexFormatTooOldExceptions are thrown when you open and operate on too old indexes! */
  public void testUnsupportedOldIndexes() throws Exception {
    for(int i=0;i<unsupportedNames.length;i++) {
      if (VERBOSE) {
        System.out.println("TEST: index " + unsupportedNames[i]);
      }
      File oldIndxeDir = _TestUtil.getTempDir(unsupportedNames[i]);
      _TestUtil.unzip(getDataFile("unsupported." + unsupportedNames[i] + ".zip"), oldIndxeDir);
      BaseDirectoryWrapper dir = newFSDirectory(oldIndxeDir);
      // don't checkindex, these are intentionally not supported
      dir.setCheckIndexOnClose(false);

      IndexReader reader = null;
      IndexWriter writer = null;
      try {
        reader = DirectoryReader.open(dir);
        fail("DirectoryReader.open should not pass for "+unsupportedNames[i]);
      } catch (IndexFormatTooOldException e) {
        // pass
      } finally {
        if (reader != null) reader.close();
        reader = null;
      }

      try {
        writer = new IndexWriter(dir, newIndexWriterConfig(
          TEST_VERSION_CURRENT, new MockAnalyzer(random())));
        fail("IndexWriter creation should not pass for "+unsupportedNames[i]);
      } catch (IndexFormatTooOldException e) {
        // pass
        if (VERBOSE) {
          System.out.println("TEST: got expected exc:");
          e.printStackTrace(System.out);
        }
        // Make sure exc message includes a path=
        assertTrue("got exc message: " + e.getMessage(), e.getMessage().indexOf("path=\"") != -1);
      } finally {
        // we should fail to open IW, and so it should be null when we get here.
        // However, if the test fails (i.e., IW did not fail on open), we need
        // to close IW. However, if merges are run, IW may throw
        // IndexFormatTooOldException, and we don't want to mask the fail()
        // above, so close without waiting for merges.
        if (writer != null) {
          writer.close(false);
        }
        writer = null;
      }

      ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
      CheckIndex checker = new CheckIndex(dir);
      checker.setInfoStream(new PrintStream(bos, false, "UTF-8"));
      CheckIndex.Status indexStatus = checker.checkIndex();
      assertFalse(indexStatus.clean);
      assertTrue(bos.toString("UTF-8").contains(IndexFormatTooOldException.class.getName()));

      dir.close();
      _TestUtil.rmDir(oldIndxeDir);
    }
  }

  public void testFullyMergeOldIndex() throws Exception {
    for (String name : oldNames) {
      if (VERBOSE) {
        System.out.println("\nTEST: index=" + name);
      }
      Directory dir = newDirectory(oldIndexDirs.get(name));
      IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(
          TEST_VERSION_CURRENT, new MockAnalyzer(random())));
      w.forceMerge(1);
      w.close();

      dir.close();
    }
  }

  public void testAddOldIndexes() throws IOException {
    for (String name : oldNames) {
      if (VERBOSE) {
        System.out.println("\nTEST: old index " + name);
      }
      Directory targetDir = newDirectory();
      IndexWriter w = new IndexWriter(targetDir, newIndexWriterConfig(
          TEST_VERSION_CURRENT, new MockAnalyzer(random())));
      w.addIndexes(oldIndexDirs.get(name));
      if (VERBOSE) {
        System.out.println("\nTEST: done adding indices; now close");
      }
      w.close();

      targetDir.close();
    }
  }

  public void testAddOldIndexesReader() throws IOException {
    for (String name : oldNames) {
      IndexReader reader = DirectoryReader.open(oldIndexDirs.get(name));

      Directory targetDir = newDirectory();
      IndexWriter w = new IndexWriter(targetDir, newIndexWriterConfig(
          TEST_VERSION_CURRENT, new MockAnalyzer(random())));
      w.addIndexes(reader);
      w.close();
      reader.close();

      targetDir.close();
    }
  }

  public void testSearchOldIndex() throws IOException {
    for (String name : oldNames) {
      searchIndex(oldIndexDirs.get(name), name);
    }
  }

  public void testIndexOldIndexNoAdds() throws IOException {
    for (String name : oldNames) {
      Directory dir = newDirectory(oldIndexDirs.get(name));
      changeIndexNoAdds(random(), dir);
      dir.close();
    }
  }

  public void testIndexOldIndex() throws IOException {
    for (String name : oldNames) {
      if (VERBOSE) {
        System.out.println("TEST: oldName=" + name);
      }
      Directory dir = newDirectory(oldIndexDirs.get(name));
      changeIndexWithAdds(random(), dir, name);
      dir.close();
    }
  }

  private void doTestHits(ScoreDoc[] hits, int expectedCount, IndexReader reader) throws IOException {
    final int hitCount = hits.length;
    assertEquals("wrong number of hits", expectedCount, hitCount);
    for(int i=0;i<hitCount;i++) {
      reader.document(hits[i].doc);
      reader.getTermVectors(hits[i].doc);
    }
  }

  public void searchIndex(Directory dir, String oldName) throws IOException {
    //QueryParser parser = new QueryParser("contents", new MockAnalyzer(random));
    //Query query = parser.parse("handle:1");

    IndexReader reader = DirectoryReader.open(dir);
    IndexSearcher searcher = newSearcher(reader);

    _TestUtil.checkIndex(dir);

    // true if this is a 4.0+ index
    final boolean is40Index = MultiFields.getMergedFieldInfos(reader).fieldInfo("content5") != null;
    // true if this is a 4.2+ index
    final boolean is42Index = MultiFields.getMergedFieldInfos(reader).fieldInfo("dvSortedSet") != null;

    assert is40Index; // NOTE: currently we can only do this on trunk!

    final Bits liveDocs = MultiFields.getLiveDocs(reader);

    for(int i=0;i<35;i++) {
      if (liveDocs.get(i)) {
        StoredDocument d = reader.document(i);
        List<StorableField> fields = d.getFields();
        boolean isProxDoc = d.getField("content3") == null;
        if (isProxDoc) {
          final int numFields = is40Index ? 7 : 5;
          assertEquals(numFields, fields.size());
          StorableField f =  d.getField("id");
          assertEquals(""+i, f.stringValue());

          f = d.getField("utf8");
          assertEquals("Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", f.stringValue());

          f =  d.getField("autf8");
          assertEquals("Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", f.stringValue());

          f = d.getField("content2");
          assertEquals("here is more content with aaa aaa aaa", f.stringValue());

          f = d.getField("fie\u2C77ld");
          assertEquals("field with non-ascii name", f.stringValue());
        }

        Fields tfvFields = reader.getTermVectors(i);
        assertNotNull("i=" + i, tfvFields);
        Terms tfv = tfvFields.terms("utf8");
        assertNotNull("docID=" + i + " index=" + oldName, tfv);
      } else {
        // Only ID 7 is deleted
        assertEquals(7, i);
      }
    }

    if (is40Index) {
      // check docvalues fields
      NumericDocValues dvByte = MultiDocValues.getNumericValues(reader, "dvByte");
      BinaryDocValues dvBytesDerefFixed = MultiDocValues.getBinaryValues(reader, "dvBytesDerefFixed");
      BinaryDocValues dvBytesDerefVar = MultiDocValues.getBinaryValues(reader, "dvBytesDerefVar");
      SortedDocValues dvBytesSortedFixed = MultiDocValues.getSortedValues(reader, "dvBytesSortedFixed");
      SortedDocValues dvBytesSortedVar = MultiDocValues.getSortedValues(reader, "dvBytesSortedVar");
      BinaryDocValues dvBytesStraightFixed = MultiDocValues.getBinaryValues(reader, "dvBytesStraightFixed");
      BinaryDocValues dvBytesStraightVar = MultiDocValues.getBinaryValues(reader, "dvBytesStraightVar");
      NumericDocValues dvDouble = MultiDocValues.getNumericValues(reader, "dvDouble");
      NumericDocValues dvFloat = MultiDocValues.getNumericValues(reader, "dvFloat");
      NumericDocValues dvInt = MultiDocValues.getNumericValues(reader, "dvInt");
      NumericDocValues dvLong = MultiDocValues.getNumericValues(reader, "dvLong");
      NumericDocValues dvPacked = MultiDocValues.getNumericValues(reader, "dvPacked");
      NumericDocValues dvShort = MultiDocValues.getNumericValues(reader, "dvShort");
      SortedSetDocValues dvSortedSet = null;
      if (is42Index) {
        dvSortedSet = MultiDocValues.getSortedSetValues(reader, "dvSortedSet");
      }

      for (int i=0;i<35;i++) {
        int id = Integer.parseInt(reader.document(i).get("id"));
        assertEquals(id, dvByte.get(i));

        byte bytes[] = new byte[] {
            (byte)(id >>> 24), (byte)(id >>> 16),(byte)(id >>> 8),(byte)id
        };
        BytesRef expectedRef = new BytesRef(bytes);
        BytesRef scratch = new BytesRef();

        dvBytesDerefFixed.get(i, scratch);
        assertEquals(expectedRef, scratch);
        dvBytesDerefVar.get(i, scratch);
        assertEquals(expectedRef, scratch);
        dvBytesSortedFixed.get(i, scratch);
        assertEquals(expectedRef, scratch);
        dvBytesSortedVar.get(i, scratch);
        assertEquals(expectedRef, scratch);
        dvBytesStraightFixed.get(i, scratch);
        assertEquals(expectedRef, scratch);
        dvBytesStraightVar.get(i, scratch);
        assertEquals(expectedRef, scratch);

        assertEquals((double)id, Double.longBitsToDouble(dvDouble.get(i)), 0D);
        assertEquals((float)id, Float.intBitsToFloat((int)dvFloat.get(i)), 0F);
        assertEquals(id, dvInt.get(i));
        assertEquals(id, dvLong.get(i));
        assertEquals(id, dvPacked.get(i));
        assertEquals(id, dvShort.get(i));
        if (is42Index) {
          dvSortedSet.setDocument(i);
          long ord = dvSortedSet.nextOrd();
          assertEquals(SortedSetDocValues.NO_MORE_ORDS, dvSortedSet.nextOrd());
          dvSortedSet.lookupOrd(ord, scratch);
          assertEquals(expectedRef, scratch);
        }
      }
    }

    ScoreDoc[] hits = searcher.search(new TermQuery(new Term(new String("content"), "aaa")), null, 1000).scoreDocs;

    // First document should be #0
    StoredDocument d = searcher.getIndexReader().document(hits[0].doc);
    assertEquals("didn't get the right document first", "0", d.get("id"));

    doTestHits(hits, 34, searcher.getIndexReader());

    if (is40Index) {
      hits = searcher.search(new TermQuery(new Term(new String("content5"), "aaa")), null, 1000).scoreDocs;

      doTestHits(hits, 34, searcher.getIndexReader());

      hits = searcher.search(new TermQuery(new Term(new String("content6"), "aaa")), null, 1000).scoreDocs;

      doTestHits(hits, 34, searcher.getIndexReader());
    }

    hits = searcher.search(new TermQuery(new Term("utf8", "\u0000")), null, 1000).scoreDocs;
    assertEquals(34, hits.length);
    hits = searcher.search(new TermQuery(new Term(new String("utf8"), "lu\uD834\uDD1Ece\uD834\uDD60ne")), null, 1000).scoreDocs;
    assertEquals(34, hits.length);
    hits = searcher.search(new TermQuery(new Term("utf8", "ab\ud917\udc17cd")), null, 1000).scoreDocs;
    assertEquals(34, hits.length);

    reader.close();
  }

  private int compare(String name, String v) {
    int v0 = Integer.parseInt(name.substring(0, 2));
    int v1 = Integer.parseInt(v);
    return v0 - v1;
  }

  public void changeIndexWithAdds(Random random, Directory dir, String origOldName) throws IOException {
    // open writer
    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.APPEND).setMergePolicy(newLogMergePolicy()));
    // add 10 docs
    for(int i=0;i<10;i++) {
      addDoc(writer, 35+i);
    }

    // make sure writer sees right total -- writer seems not to know about deletes in .del?
    final int expected;
    if (compare(origOldName, "24") < 0) {
      expected = 44;
    } else {
      expected = 45;
    }
    assertEquals("wrong doc count", expected, writer.numDocs());
    writer.close();

    // make sure searching sees right # hits
    IndexReader reader = DirectoryReader.open(dir);
    IndexSearcher searcher = newSearcher(reader);
    ScoreDoc[] hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
    StoredDocument d = searcher.getIndexReader().document(hits[0].doc);
    assertEquals("wrong first document", "0", d.get("id"));
    doTestHits(hits, 44, searcher.getIndexReader());
    reader.close();

    // fully merge
    writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.APPEND).setMergePolicy(newLogMergePolicy()));
    writer.forceMerge(1);
    writer.close();

    reader = DirectoryReader.open(dir);
    searcher = newSearcher(reader);
    hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
    assertEquals("wrong number of hits", 44, hits.length);
    d = searcher.doc(hits[0].doc);
    doTestHits(hits, 44, searcher.getIndexReader());
    assertEquals("wrong first document", "0", d.get("id"));
    reader.close();
  }

  public void changeIndexNoAdds(Random random, Directory dir) throws IOException {
    // make sure searching sees right # hits
    DirectoryReader reader = DirectoryReader.open(dir);
    IndexSearcher searcher = newSearcher(reader);
    ScoreDoc[] hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
    assertEquals("wrong number of hits", 34, hits.length);
    StoredDocument d = searcher.doc(hits[0].doc);
    assertEquals("wrong first document", "0", d.get("id"));
    reader.close();

    // fully merge
    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.APPEND));
    writer.forceMerge(1);
    writer.close();

    reader = DirectoryReader.open(dir);
    searcher = newSearcher(reader);
    hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
    assertEquals("wrong number of hits", 34, hits.length);
    doTestHits(hits, 34, searcher.getIndexReader());
    reader.close();
  }

  public File createIndex(String dirName, boolean doCFS, boolean fullyMerged) throws IOException {
    // we use a real directory name that is not cleaned up, because this method is only used to create backwards indexes:
    File indexDir = new File("/tmp/idx", dirName);
    _TestUtil.rmDir(indexDir);
    Directory dir = newFSDirectory(indexDir);
    LogByteSizeMergePolicy mp = new LogByteSizeMergePolicy();
    mp.setNoCFSRatio(doCFS ? 1.0 : 0.0);
    mp.setMaxCFSSegmentSizeMB(Double.POSITIVE_INFINITY);
    // TODO: remove randomness
    IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()))
      .setMaxBufferedDocs(10).setMergePolicy(mp);
    IndexWriter writer = new IndexWriter(dir, conf);

    for(int i=0;i<35;i++) {
      addDoc(writer, i);
    }
    assertEquals("wrong doc count", 35, writer.maxDoc());
    if (fullyMerged) {
      writer.forceMerge(1);
    }
    writer.close();

    if (!fullyMerged) {
      // open fresh writer so we get no prx file in the added segment
      mp = new LogByteSizeMergePolicy();
      mp.setNoCFSRatio(doCFS ? 1.0 : 0.0);
      // TODO: remove randomness
      conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()))
        .setMaxBufferedDocs(10).setMergePolicy(mp);
      writer = new IndexWriter(dir, conf);
      addNoProxDoc(writer);
      writer.close();

      writer = new IndexWriter(dir,
        conf.setMergePolicy(doCFS ? NoMergePolicy.COMPOUND_FILES : NoMergePolicy.NO_COMPOUND_FILES)
      );
      Term searchTerm = new Term("id", "7");
      writer.deleteDocuments(searchTerm);
      writer.close();
    }

    dir.close();

    return indexDir;
  }

  /* Verifies that the expected file names were produced */

  public void testExactFileNames() throws IOException {

    String outputDirName = "lucene.backwardscompat0.index";
    File outputDir = _TestUtil.getTempDir(outputDirName);
    _TestUtil.rmDir(outputDir);

    try {
      Directory dir = newFSDirectory(outputDir);

      MergePolicy mergePolicy = newLogMergePolicy(true, 10);

      // This test expects all of its segments to be in CFS:
      mergePolicy.setNoCFSRatio(1.0);
      mergePolicy.setMaxCFSSegmentSizeMB(Double.POSITIVE_INFINITY);

      IndexWriter writer = new IndexWriter(
          dir,
          newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).
              setMaxBufferedDocs(-1).
              setRAMBufferSizeMB(16.0).
              setMergePolicy(mergePolicy).setUseCompoundFile(true)
      );
      for(int i=0;i<35;i++) {
        addDoc(writer, i);
      }
      assertEquals("wrong doc count", 35, writer.maxDoc());
      writer.close();

      // Delete one doc so we get a .del file:
      writer = new IndexWriter(
          dir,
          newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()))
            .setMergePolicy(NoMergePolicy.NO_COMPOUND_FILES).setUseCompoundFile(true)
      );
      Term searchTerm = new Term("id", "7");
      writer.deleteDocuments(searchTerm);
      writer.close();

      // Now verify file names... TODO: fix this test better, we could populate from
      // separateFiles() or something.
      String[] expected = new String[] {"_0.cfs", "_0.cfe",
                                        "_0_1.del",
                                        "_0.si",
                                        "segments_2",
                                        "segments.gen"};

      String[] expectedSimpleText = new String[] {"_0.cfs", "_0.cfe",
                                                  "_0_1.liv",
                                                  "_0.si",
                                                  "segments_2",
                                                  "segments.gen"};

      String[] actual = dir.listAll();
      Arrays.sort(expected);
      Arrays.sort(expectedSimpleText);
      Arrays.sort(actual);
      if (!Arrays.equals(expected, actual) && !Arrays.equals(expectedSimpleText, actual)) {
        fail("incorrect filenames in index: expected:\n    " + asString(expected)
            + "\n or " + asString(expectedSimpleText) + "\n actual:\n    " + asString(actual));
      }
      dir.close();
    } finally {
      _TestUtil.rmDir(outputDir);
    }
  }

  private String asString(String[] l) {
    String s = "";
    for(int i=0;i<l.length;i++) {
      if (i > 0) {
        s += "\n    ";
      }
      s += l[i];
    }
    return s;
  }

  private void addDoc(IndexWriter writer, int id) throws IOException
  {
    Document doc = new Document();
    doc.add(new TextField("content", "aaa", Field.Store.NO));
    doc.add(new StringField("id", Integer.toString(id), Field.Store.YES));
    FieldType customType2 = new FieldType(TextField.TYPE_STORED);
    customType2.setStoreTermVectors(true);
    customType2.setStoreTermVectorPositions(true);
    customType2.setStoreTermVectorOffsets(true);
    doc.add(new Field("autf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
    doc.add(new Field("utf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
    doc.add(new Field("content2", "here is more content with aaa aaa aaa", customType2));
    doc.add(new Field("fie\u2C77ld", "field with non-ascii name", customType2));
    // add numeric fields, to test if flex preserves encoding
    doc.add(new IntField("trieInt", id, Field.Store.NO));
    doc.add(new LongField("trieLong", (long) id, Field.Store.NO));
    // add docvalues fields
    doc.add(new NumericDocValuesField("dvByte", (byte) id));
    byte bytes[] = new byte[] {
      (byte)(id >>> 24), (byte)(id >>> 16),(byte)(id >>> 8),(byte)id
    };
    BytesRef ref = new BytesRef(bytes);
    doc.add(new BinaryDocValuesField("dvBytesDerefFixed", ref));
    doc.add(new BinaryDocValuesField("dvBytesDerefVar", ref));
    doc.add(new SortedDocValuesField("dvBytesSortedFixed", ref));
    doc.add(new SortedDocValuesField("dvBytesSortedVar", ref));
    doc.add(new BinaryDocValuesField("dvBytesStraightFixed", ref));
    doc.add(new BinaryDocValuesField("dvBytesStraightVar", ref));
    doc.add(new DoubleDocValuesField("dvDouble", (double)id));
    doc.add(new FloatDocValuesField("dvFloat", (float)id));
    doc.add(new NumericDocValuesField("dvInt", id));
    doc.add(new NumericDocValuesField("dvLong", id));
    doc.add(new NumericDocValuesField("dvPacked", id));
    doc.add(new NumericDocValuesField("dvShort", (short)id));
    doc.add(new SortedSetDocValuesField("dvSortedSet", ref));
    // a field with both offsets and term vectors for a cross-check
    FieldType customType3 = new FieldType(TextField.TYPE_STORED);
    customType3.setStoreTermVectors(true);
    customType3.setStoreTermVectorPositions(true);
    customType3.setStoreTermVectorOffsets(true);
    customType3.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
    doc.add(new Field("content5", "here is more content with aaa aaa aaa", customType3));
    // a field that omits only positions
    FieldType customType4 = new FieldType(TextField.TYPE_STORED);
    customType4.setStoreTermVectors(true);
    customType4.setStoreTermVectorPositions(false);
    customType4.setStoreTermVectorOffsets(true);
    customType4.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
    doc.add(new Field("content6", "here is more content with aaa aaa aaa", customType4));
    // TODO:
    //   index different norms types via similarity (we use a random one currently?!)
    //   remove any analyzer randomness, explicitly add payloads for certain fields.
    writer.addDocument(doc);
  }

  private void addNoProxDoc(IndexWriter writer) throws IOException {
    Document doc = new Document();
    FieldType customType = new FieldType(TextField.TYPE_STORED);
    customType.setIndexOptions(IndexOptions.DOCS_ONLY);
    Field f = new Field("content3", "aaa", customType);
    doc.add(f);
    FieldType customType2 = new FieldType();
    customType2.setStored(true);
    customType2.setIndexOptions(IndexOptions.DOCS_ONLY);
    f = new Field("content4", "aaa", customType2);
    doc.add(f);
    writer.addDocument(doc);
  }

  private int countDocs(DocsEnum docs) throws IOException {
    int count = 0;
    while((docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
      count ++;
    }
    return count;
  }

  // flex: test basics of TermsEnum api on non-flex index
  public void testNextIntoWrongField() throws Exception {
    for (String name : oldNames) {
      Directory dir = oldIndexDirs.get(name);
      IndexReader r = DirectoryReader.open(dir);
      TermsEnum terms = MultiFields.getFields(r).terms("content").iterator(null);
      BytesRef t = terms.next();
      assertNotNull(t);

      // content field only has term aaa:
      assertEquals("aaa", t.utf8ToString());
      assertNull(terms.next());

      BytesRef aaaTerm = new BytesRef("aaa");

      // should be found exactly
      assertEquals(TermsEnum.SeekStatus.FOUND,
                   terms.seekCeil(aaaTerm));
      assertEquals(35, countDocs(_TestUtil.docs(random(), terms, null, null, DocsEnum.FLAG_NONE)));
      assertNull(terms.next());

      // should hit end of field
      assertEquals(TermsEnum.SeekStatus.END,
                   terms.seekCeil(new BytesRef("bbb")));
      assertNull(terms.next());

      // should seek to aaa
      assertEquals(TermsEnum.SeekStatus.NOT_FOUND,
                   terms.seekCeil(new BytesRef("a")));
      assertTrue(terms.term().bytesEquals(aaaTerm));
      assertEquals(35, countDocs(_TestUtil.docs(random(), terms, null, null, DocsEnum.FLAG_NONE)));
      assertNull(terms.next());

      assertEquals(TermsEnum.SeekStatus.FOUND,
                   terms.seekCeil(aaaTerm));
      assertEquals(35, countDocs(_TestUtil.docs(random(), terms,null, null, DocsEnum.FLAG_NONE)));
      assertNull(terms.next());

      r.close();
    }
  }

  /**
   * Test that we didn't forget to bump the current Constants.LUCENE_MAIN_VERSION.
   * This is important so that we can determine which version of lucene wrote the segment.
   */
  public void testOldVersions() throws Exception {
    // first create a little index with the current code and get the version
    Directory currentDir = newDirectory();
    RandomIndexWriter riw = new RandomIndexWriter(random(), currentDir);
    riw.addDocument(new Document());
    riw.close();
    DirectoryReader ir = DirectoryReader.open(currentDir);
    SegmentReader air = (SegmentReader)ir.leaves().get(0).reader();
    String currentVersion = air.getSegmentInfo().info.getVersion();
    assertNotNull(currentVersion); // only 3.0 segments can have a null version
    ir.close();
    currentDir.close();

    Comparator<String> comparator = StringHelper.getVersionComparator();

    // now check all the old indexes, their version should be < the current version
    for (String name : oldNames) {
      Directory dir = oldIndexDirs.get(name);
      DirectoryReader r = DirectoryReader.open(dir);
      for (AtomicReaderContext context : r.leaves()) {
        air = (SegmentReader) context.reader();
        String oldVersion = air.getSegmentInfo().info.getVersion();
        assertNotNull(oldVersion); // only 3.0 segments can have a null version
        assertTrue("current Constants.LUCENE_MAIN_VERSION is <= an old index: did you forget to bump it?!",
            comparator.compare(oldVersion, currentVersion) < 0);
      }
      r.close();
    }
  }

  public void testNumericFields() throws Exception {
    for (String name : oldNames) {

      Directory dir = oldIndexDirs.get(name);
      IndexReader reader = DirectoryReader.open(dir);
      IndexSearcher searcher = newSearcher(reader);

      for (int id=10; id<15; id++) {
        ScoreDoc[] hits = searcher.search(NumericRangeQuery.newIntRange("trieInt", 4, Integer.valueOf(id), Integer.valueOf(id), true, true), 100).scoreDocs;
        assertEquals("wrong number of hits", 1, hits.length);
        StoredDocument d = searcher.doc(hits[0].doc);
        assertEquals(String.valueOf(id), d.get("id"));

        hits = searcher.search(NumericRangeQuery.newLongRange("trieLong", 4, Long.valueOf(id), Long.valueOf(id), true, true), 100).scoreDocs;
        assertEquals("wrong number of hits", 1, hits.length);
        d = searcher.doc(hits[0].doc);
        assertEquals(String.valueOf(id), d.get("id"));
      }

      // check that also lower-precision fields are ok
      ScoreDoc[] hits = searcher.search(NumericRangeQuery.newIntRange("trieInt", 4, Integer.MIN_VALUE, Integer.MAX_VALUE, false, false), 100).scoreDocs;
      assertEquals("wrong number of hits", 34, hits.length);

      hits = searcher.search(NumericRangeQuery.newLongRange("trieLong", 4, Long.MIN_VALUE, Long.MAX_VALUE, false, false), 100).scoreDocs;
      assertEquals("wrong number of hits", 34, hits.length);

      // check decoding into field cache
      FieldCache.Ints fci = FieldCache.DEFAULT.getInts(SlowCompositeReaderWrapper.wrap(searcher.getIndexReader()), "trieInt", false);
      int maxDoc = searcher.getIndexReader().maxDoc();
      for(int doc=0;doc<maxDoc;doc++) {
        int val = fci.get(doc);
        assertTrue("value in id bounds", val >= 0 && val < 35);
      }

      FieldCache.Longs fcl = FieldCache.DEFAULT.getLongs(SlowCompositeReaderWrapper.wrap(searcher.getIndexReader()), "trieLong", false);
      for(int doc=0;doc<maxDoc;doc++) {
        long val = fcl.get(doc);
        assertTrue("value in id bounds", val >= 0L && val < 35L);
      }

      reader.close();
    }
  }

  private int checkAllSegmentsUpgraded(Directory dir) throws IOException {
    final SegmentInfos infos = new SegmentInfos();
    infos.read(dir);
    if (VERBOSE) {
      System.out.println("checkAllSegmentsUpgraded: " + infos);
    }
    for (SegmentCommitInfo si : infos) {
      assertEquals(Constants.LUCENE_MAIN_VERSION, si.info.getVersion());
    }
    return infos.size();
  }

  private int getNumberOfSegments(Directory dir) throws IOException {
    final SegmentInfos infos = new SegmentInfos();
    infos.read(dir);
    return infos.size();
  }

  public void testUpgradeOldIndex() throws Exception {
    List<String> names = new ArrayList<String>(oldNames.length + oldSingleSegmentNames.length);
    names.addAll(Arrays.asList(oldNames));
    names.addAll(Arrays.asList(oldSingleSegmentNames));
    for(String name : names) {
      if (VERBOSE) {
        System.out.println("testUpgradeOldIndex: index=" +name);
      }
      Directory dir = newDirectory(oldIndexDirs.get(name));

      newIndexUpgrader(dir).upgrade();

      checkAllSegmentsUpgraded(dir);

      dir.close();
    }
  }

  public void testCommandLineArgs() throws Exception {

    for (String name : oldIndexDirs.keySet()) {
      File dir = _TestUtil.getTempDir(name);
      File dataFile = new File(TestBackwardsCompatibility.class.getResource("index." + name + ".zip").toURI());
      _TestUtil.unzip(dataFile, dir);

      String path = dir.getAbsolutePath();

      List<String> args = new ArrayList<String>();
      if (random().nextBoolean()) {
        args.add("-verbose");
      }
      if (random().nextBoolean()) {
        args.add("-delete-prior-commits");
      }
      if (random().nextBoolean()) {
        // TODO: need to better randomize this, but ...
        //  - LuceneTestCase.FS_DIRECTORIES is private
        //  - newFSDirectory returns BaseDirectoryWrapper
        //  - BaseDirectoryWrapper doesn't expose delegate
        Class<? extends FSDirectory> dirImpl = random().nextBoolean() ?
          SimpleFSDirectory.class : NIOFSDirectory.class;

        args.add("-dir-impl");
        args.add(dirImpl.getName());
      }
      args.add(path);

      IndexUpgrader upgrader = null;
      try {
        upgrader = IndexUpgrader.parseArgs(args.toArray(new String[0]));
      } catch (Exception e) {
        throw new AssertionError("unable to parse args: " + args, e);
      }
      upgrader.upgrade();

      Directory upgradedDir = newFSDirectory(dir);
      try {
        checkAllSegmentsUpgraded(upgradedDir);
      } finally {
        upgradedDir.close();
      }
    }
  }

  public void testUpgradeOldSingleSegmentIndexWithAdditions() throws Exception {
    for (String name : oldSingleSegmentNames) {
      if (VERBOSE) {
        System.out.println("testUpgradeOldSingleSegmentIndexWithAdditions: index=" +name);
      }
      Directory dir = newDirectory(oldIndexDirs.get(name));

      assertEquals("Original index must be single segment", 1, getNumberOfSegments(dir));

      // create a bunch of dummy segments
      int id = 40;
      RAMDirectory ramDir = new RAMDirectory();
      for (int i = 0; i < 3; i++) {
        // only use Log- or TieredMergePolicy, to make document addition predictable and not suddenly merge:
        MergePolicy mp = random().nextBoolean() ? newLogMergePolicy() : newTieredMergePolicy();
        IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()))
          .setMergePolicy(mp);
        IndexWriter w = new IndexWriter(ramDir, iwc);
        // add few more docs:
        for(int j = 0; j < RANDOM_MULTIPLIER * random().nextInt(30); j++) {
          addDoc(w, id++);
        }
        w.close(false);
      }

      // add dummy segments (which are all in current
      // version) to single segment index
      MergePolicy mp = random().nextBoolean() ? newLogMergePolicy() : newTieredMergePolicy();
      IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, null)
        .setMergePolicy(mp);
      IndexWriter w = new IndexWriter(dir, iwc);
      w.addIndexes(ramDir);
      w.close(false);

      // determine count of segments in modified index
      final int origSegCount = getNumberOfSegments(dir);

      newIndexUpgrader(dir).upgrade();

      final int segCount = checkAllSegmentsUpgraded(dir);
      assertEquals("Index must still contain the same number of segments, as only one segment was upgraded and nothing else merged",
        origSegCount, segCount);

      dir.close();
    }
  }

  public static final String moreTermsIndex = "moreterms.40.zip";

  public void testMoreTerms() throws Exception {
    File oldIndexDir = _TestUtil.getTempDir("moreterms");
    _TestUtil.unzip(getDataFile(moreTermsIndex), oldIndexDir);
    Directory dir = newFSDirectory(oldIndexDir);
    // TODO: more tests
    _TestUtil.checkIndex(dir);
    dir.close();
  }
}


text:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;

namespace NMF.Collections.ObjectModel
{
    public class ObservableCollectionExtended<T> : ObservableCollection<T>, INotifyCollectionChanging
    {
        public event EventHandler<NotifyCollectionChangingEventArgs> CollectionChanging;

        protected Action beforeCollectionChangedAction;

        private NotifyCollectionChangedEventArgs collectionChangedArgs;

        protected virtual void OnCollectionChanging(NotifyCollectionChangingEventArgs e)
        {
            CollectionChanging?.Invoke(this, e);
        }

        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            if (collectionChangedArgs == null)
                collectionChangedArgs = e;
            else
            {
                collectionChangedArgs = null;
                base.OnCollectionChanged(e);
            }
        }

        protected override void ClearItems()
        {
            OnCollectionChanging(new NotifyCollectionChangingEventArgs(NotifyCollectionChangedAction.Reset));
            base.ClearItems();
            BeforeCollectionChanged();
        }

        protected override void InsertItem(int index, T item)
        {
            OnCollectionChanging(new NotifyCollectionChangingEventArgs(NotifyCollectionChangedAction.Add));
            base.InsertItem(index, item);
            BeforeCollectionChanged();
        }

        protected override void MoveItem(int oldIndex, int newIndex)
        {
            OnCollectionChanging(new NotifyCollectionChangingEventArgs(NotifyCollectionChangedAction.Move));
            base.MoveItem(oldIndex, newIndex);
            BeforeCollectionChanged();
        }

        protected override void RemoveItem(int index)
        {
            OnCollectionChanging(new NotifyCollectionChangingEventArgs(NotifyCollectionChangedAction.Remove));
            base.RemoveItem(index);
            BeforeCollectionChanged();
        }

        protected override void SetItem(int index, T item)
        {
            OnCollectionChanging(new NotifyCollectionChangingEventArgs(NotifyCollectionChangedAction.Replace));
            base.SetItem(index, item);
            BeforeCollectionChanged();
        }

        private void BeforeCollectionChanged()
        {
            if (beforeCollectionChangedAction != null)
            {
                beforeCollectionChangedAction();
                beforeCollectionChangedAction = null;
            }
            OnCollectionChanged(collectionChangedArgs);
        }
    }
}


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

namespace VideoLibrary.Debug
{
    class MyYouTube : YouTube
    {
        protected override HttpClient MakeClient(HttpMessageHandler handler)
        {
            return base.MakeClient(handler);
        }

        protected override HttpMessageHandler MakeHandler()
        {
            return base.MakeHandler();
        }
    }
}


text:
package cloudapi

//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//
// Code generated by Alibaba Cloud SDK Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

// FunctionComputeConfig is a nested struct in cloudapi response
type FunctionComputeConfig struct {
	FcType              string `json:"FcType" xml:"FcType"`
	Path                string `json:"Path" xml:"Path"`
	Qualifier           string `json:"Qualifier" xml:"Qualifier"`
	ContentTypeCatagory string `json:"ContentTypeCatagory" xml:"ContentTypeCatagory"`
	OnlyBusinessPath    bool   `json:"OnlyBusinessPath" xml:"OnlyBusinessPath"`
	RegionId            string `json:"RegionId" xml:"RegionId"`
	ContentTypeValue    string `json:"ContentTypeValue" xml:"ContentTypeValue"`
	Method              string `json:"Method" xml:"Method"`
	FcBaseUrl           string `json:"FcBaseUrl" xml:"FcBaseUrl"`
	FcRegionId          string `json:"FcRegionId" xml:"FcRegionId"`
	ServiceName         string `json:"ServiceName" xml:"ServiceName"`
	RoleArn             string `json:"RoleArn" xml:"RoleArn"`
	FunctionName        string `json:"FunctionName" xml:"FunctionName"`
}


text:
package org.elasticsearch.xpack.security.action.filter;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.admin.indices.close.CloseIndexAction;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction;
import org.elasticsearch.action.admin.indices.open.OpenIndexAction;
import org.elasticsearch.action.support.ActionFilter;
import org.elasticsearch.action.support.ActionFilterChain;
import org.elasticsearch.action.support.ContextPreservingActionListener;
import org.elasticsearch.action.support.DestructiveOperations;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.license.XPackLicenseState.Feature;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.XPackField;
import org.elasticsearch.xpack.core.security.SecurityContext;
import org.elasticsearch.xpack.core.security.authc.Authentication;
import org.elasticsearch.xpack.core.security.authz.privilege.HealthAndStatsPrivilege;
import org.elasticsearch.xpack.core.security.support.Automatons;
import org.elasticsearch.xpack.core.security.user.SystemUser;
import org.elasticsearch.xpack.security.action.SecurityActionMapper;
import org.elasticsearch.xpack.security.authc.AuthenticationService;
import org.elasticsearch.xpack.security.authz.AuthorizationService;
import org.elasticsearch.xpack.security.authz.AuthorizationUtils;

import java.io.IOException;
import java.util.function.Predicate;

public class SecurityActionFilter implements ActionFilter {

    private static final Predicate<String> LICENSE_EXPIRATION_ACTION_MATCHER = HealthAndStatsPrivilege.INSTANCE.predicate();
    private static final Predicate<String> SECURITY_ACTION_MATCHER = Automatons.predicate("cluster:admin/xpack/security*");
    private static final Logger logger = LogManager.getLogger(SecurityActionFilter.class);

    private final AuthenticationService authcService;
    private final AuthorizationService authzService;
    private final SecurityActionMapper actionMapper = new SecurityActionMapper();
    private final XPackLicenseState licenseState;
    private final ThreadContext threadContext;
    private final SecurityContext securityContext;
    private final DestructiveOperations destructiveOperations;

    public SecurityActionFilter(AuthenticationService authcService, AuthorizationService authzService,
                                XPackLicenseState licenseState, ThreadPool threadPool,
                                SecurityContext securityContext, DestructiveOperations destructiveOperations) {
        this.authcService = authcService;
        this.authzService = authzService;
        this.licenseState = licenseState;
        this.threadContext = threadPool.getThreadContext();
        this.securityContext = securityContext;
        this.destructiveOperations = destructiveOperations;
    }

    @Override
    public <Request extends ActionRequest, Response extends ActionResponse> void apply(Task task, String action, Request request,
                                                                                ActionListener<Response> listener,
                                                                                ActionFilterChain<Request, Response> chain) {
        /*
         A functional requirement - when the license of security is disabled (invalid/expires), security will continue
         to operate normally, except all read operations will be blocked.
         */
        if (licenseState.checkFeature(Feature.SECURITY_STATS_AND_HEALTH) == false && LICENSE_EXPIRATION_ACTION_MATCHER.test(action)) {
            logger.error("blocking [{}] operation due to expired license. Cluster health, cluster stats and indices stats \n" +
                    "operations are blocked on license expiration. All data operations (read and write) continue to work. \n" +
                    "If you have a new license, please update it. Otherwise, please reach out to your support contact.", action);
            throw LicenseUtils.newComplianceException(XPackField.SECURITY);
        }

        if (licenseState.isSecurityEnabled()) {
            final ActionListener<Response> contextPreservingListener =
                    ContextPreservingActionListener.wrapPreservingContext(listener, threadContext);
            ActionListener<Void> authenticatedListener = ActionListener.wrap(
                    (aVoid) -> chain.proceed(task, action, request, contextPreservingListener), contextPreservingListener::onFailure);
            final boolean useSystemUser = AuthorizationUtils.shouldReplaceUserWithSystem(threadContext, action);
            try {
                if (useSystemUser) {
                    securityContext.executeAsUser(SystemUser.INSTANCE, (original) -> {
                        try {
                            applyInternal(action, request, authenticatedListener);
                        } catch (IOException e) {
                            listener.onFailure(e);
                        }
                    }, Version.CURRENT);
                } else if (AuthorizationUtils.shouldSetUserBasedOnActionOrigin(threadContext)) {
                    AuthorizationUtils.switchUserBasedOnActionOriginAndExecute(threadContext, securityContext, (original) -> {
                        try {
                            applyInternal(action, request, authenticatedListener);
                        } catch (IOException e) {
                            listener.onFailure(e);
                        }
                    });
                } else {
                    try (ThreadContext.StoredContext ignore = threadContext.newStoredContext(true)) {
                        applyInternal(action, request, authenticatedListener);
                    }
                }
            } catch (Exception e) {
                listener.onFailure(e);
            }
        } else if (SECURITY_ACTION_MATCHER.test(action)) {
            if (licenseState.isSecurityEnabled() == false) {
                listener.onFailure(new ElasticsearchException("Security must be explicitly enabled when using a [" +
                        licenseState.getOperationMode().description() + "] license. " +
                        "Enable security by setting [xpack.security.enabled] to [true] in the elasticsearch.yml file " +
                        "and restart the node."));
            } else {
                listener.onFailure(LicenseUtils.newComplianceException(XPackField.SECURITY));
            }
        } else {
            chain.proceed(task, action, request, listener);
        }
    }

    @Override
    public int order() {
        return Integer.MIN_VALUE;
    }

    private <Request extends ActionRequest> void applyInternal(String action, Request request,
                                                               ActionListener<Void> listener) throws IOException {
        if (CloseIndexAction.NAME.equals(action) || OpenIndexAction.NAME.equals(action) || DeleteIndexAction.NAME.equals(action)) {
            IndicesRequest indicesRequest = (IndicesRequest) request;
            try {
                destructiveOperations.failDestructive(indicesRequest.indices());
            } catch(IllegalArgumentException e) {
                listener.onFailure(e);
                return;
            }
        }

        /*
         here we fallback on the system user. Internal system requests are requests that are triggered by
         the system itself (e.g. pings, update mappings, share relocation, etc...) and were not originated
         by user interaction. Since these requests are triggered by es core modules, they are security
         agnostic and therefore not associated with any user. When these requests execute locally, they
         are executed directly on their relevant action. Since there is no other way a request can make
         it to the action without an associated user (not via REST or transport - this is taken care of by
         the {@link Rest} filter and the {@link ServerTransport} filter respectively), it's safe to assume a system user
         here if a request is not associated with any other user.
         */
        final String securityAction = actionMapper.action(action, request);
        authcService.authenticate(securityAction, request, SystemUser.INSTANCE,
                ActionListener.wrap((authc) -> {
                    if (authc != null) {
                        authorizeRequest(authc, securityAction, request, listener);
                    } else if (licenseState.isSecurityEnabled() == false) {
                        listener.onResponse(null);
                    } else {
                        listener.onFailure(new IllegalStateException("no authentication present but auth is allowed"));
                    }
                }, listener::onFailure));
    }

    private <Request extends ActionRequest> void authorizeRequest(Authentication authentication, String securityAction, Request request,
                                                          ActionListener<Void> listener) {
        if (authentication == null) {
            listener.onFailure(new IllegalArgumentException("authentication must be non null for authorization"));
        } else {
            authzService.authorize(authentication, securityAction, request, ActionListener.wrap(ignore -> listener.onResponse(null),
                listener::onFailure));
        }
    }
}


text:
$(function(){

	$("#frmsec-acordion").accordion({
		autoHeight: false
	});
	$("#dvencimiento_licencia_a").datepicker({
		 dateFormat: 'yy-mm-dd', //formato de la fecha - dd,mm,yy=dia,mes,año numericos  DD,MM=dia,mes en texto
		 //minDate: '-2Y', maxDate: '+1M +10D', //restringen a un rango el calendario - ej. +10D,-2M,+1Y,-3W(W=semanas) o alguna fecha
		 changeMonth: true, //permite modificar los meses (true o false)
		 changeYear: true, //permite modificar los años (true o false)
		 //yearRange: (fecha_hoy.getFullYear()-70)+':'+fecha_hoy.getFullYear(),
		 numberOfMonths: 1 //muestra mas de un mes en el calendario, depende del numero
	});
	$("#dvencimiento_licencia_v").datepicker({
		 dateFormat: 'yy-mm-dd', //formato de la fecha - dd,mm,yy=dia,mes,año numericos  DD,MM=dia,mes en texto
		 //minDate: '-2Y', maxDate: '+1M +10D', //restringen a un rango el calendario - ej. +10D,-2M,+1Y,-3W(W=semanas) o alguna fecha
		 changeMonth: true, //permite modificar los meses (true o false)
		 changeYear: true, //permite modificar los años (true o false)
		 //yearRange: (fecha_hoy.getFullYear()-70)+':'+fecha_hoy.getFullYear(),
		 numberOfMonths: 1 //muestra mas de un mes en el calendario, depende del numero
	});
	$("#dfecha_vence_seguro").datepicker({
		 dateFormat: 'yy-mm-dd', //formato de la fecha - dd,mm,yy=dia,mes,año numericos  DD,MM=dia,mes en texto
		 //minDate: '-2Y', maxDate: '+1M +10D', //restringen a un rango el calendario - ej. +10D,-2M,+1Y,-3W(W=semanas) o alguna fecha
		 changeMonth: true, //permite modificar los meses (true o false)
		 changeYear: true, //permite modificar los años (true o false)
		 //yearRange: (fecha_hoy.getFullYear()-70)+':'+fecha_hoy.getFullYear(),
		 numberOfMonths: 1 //muestra mas de un mes en el calendario, depende del numero
	});
	$("#dfecha_nacimiento").datepicker({
		 dateFormat: 'yy-mm-dd', //formato de la fecha - dd,mm,yy=dia,mes,año numericos  DD,MM=dia,mes en texto
		 //minDate: '-2Y', maxDate: '+1M +10D', //restringen a un rango el calendario - ej. +10D,-2M,+1Y,-3W(W=semanas) o alguna fecha
		 changeMonth: true, //permite modificar los meses (true o false)
		 changeYear: true, //permite modificar los años (true o false)
		 //yearRange: (fecha_hoy.getFullYear()-70)+':'+fecha_hoy.getFullYear(),
		 numberOfMonths: 1 //muestra mas de un mes en el calendario, depende del numero
	});

	//dateFormat: 'yy-mm-dd'
});

var contador_contacto = 0;
/**
 * Agrega un row form para registrar un nuevo contacto
 * @param id_tbl
 * @param obj
 */
function addContacto(id_tbl, obj){
	if(contador_contacto == 0){
		//creo un row form para agregar contacto
		$("#"+id_tbl).append(
			'
'+
			'	<input type="text" name="dcnombre" value="" size="25">	'+
			'	<input type="text" name="dcdomicilio" value="" size="25">	'+
			'	<input type="text" name="dcmunicipio" value="" size="9">	'+
			'	<input type="text" name="dcestado" value="" size="9">	'+
			'	<input type="text" name="dctelefono" value="" size="9">	'+
			'	<input type="text" name="dccelular" value="" size="9">	'+
			'	'+
			'		 Agregar	'+
			'
');
		$("#tr_addcontacto"+contador_contacto+" input[name=dcnombre]").focus();
	}
	contador_contacto++;
}
/**
 * Permite enviar la peticion por Ajax para agregar el contacto
 * @param id_tr
 * @param obj
 */
function agregarContacto(id_tr, obj){
	var data = "";
	$("#"+id_tr+" input").each(function(){
		data += this.name+"="+this.value+"&";
	});

	loader.create();
	$.post(obj.href, data, function(resp){
		create("withIcon", {
			title: resp.msg.title,
			text: resp.msg.msg,
			icon: base_url+'application/images/alertas/'+resp.msg.ico+'.png' });
		if(resp.msg.ico == 'ok'){
			//si es OK se elimina el row form
			$("#"+id_tr).remove();
			contador_contacto = 0;
		}

		if(resp.info){
			//comprueba si tiene el permiso de eliminar contacto
			var priv_eliminar_contacto = '';
			if($("#priv_eliminar_contacto").length > 0)
				priv_eliminar_contacto = ''+
					' Eliminar contacto';

			//Agrego el tr con la informacion del contacto agregado
			$("#tbl_contactos tr.header:last").after(
			'
'+
			'	'+resp.info.nombre+'	'+
			'	'+resp.info.domicilio+'	'+
			'	'+resp.info.municipio+'	'+
			'	'+resp.info.estado+'	'+
			'	'+resp.info.telefono+'	'+
			'	'+resp.info.celular+'	'+
			'	'+
			'		'+
			'
'+
			'
'+
						priv_eliminar_contacto+
			'
'+
			'
'+
			'		'+
			'
');
		}
	}, "json").complete(function(){
    	loader.close();
    });
}

function eliminaContacto(obj){
	loader.create();
	$.post(obj.href, "", function(resp){
		create("withIcon", {
			title: resp.msg.title,
			text: resp.msg.msg,
			icon: base_url+'application/images/alertas/'+resp.msg.ico+'.png' });
		if(resp.msg.ico == 'ok'){
			//si es OK se elimina el row form
			$(obj).parents("tr").remove();
		}
	}, "json").complete(function(){
    	loader.close();
    });
}


text:
@interface ARArtistBiographyViewController : UIViewController

- (instancetype)initWithArtist:(Artist *)artist;

@property (nonatomic, strong, readonly) Artist *artist;

@end


text: module.exports = require('./lib/wildland-styles-generator');


text:
Key concepts in django CMS
##########################

This section doesn't explain how to do anything, but explains and analyses some key concepts in django CMS.

.. toctree::
    :maxdepth: 2

    menu_system
    publishing
    multiple_languages


text:
var http = require('../lib/http-promise/main');
var key = require('./apikey').key;
var path = '/api/'+key;
// request sample http://api.wunderground.com/api/3714a34f3207b9a2/conditions/q/TX/ROUND_ROCK.json

function makeRequest(url) {
  var future = http.request({
    hostname: 'api.wunderground.com',
    port: 80,
    path: url,
    method: 'GET'
  });
  return future;
}

function makeDecimalAudible(data) {
  return ('' + data).replace(/\./, ' point ');
}

var defolt = function(place) {
  var url = path + '/conditions/q/'+place+'.json';

  var future = makeRequest(url);

  future.then(function(d) {
    var string = '';
    if(d && d.current_observation) {
      string += 'Current temperature in celcius: ' + makeDecimalAudible(d.current_observation.temp_c) + ' degrees.';
      string += 'Current temperature in fahrenheit: '+ makeDecimalAudible(d.current_observation.temp_f) + ' degrees.';
      string += 'Feels like temperature in fahrenheit: ' + makeDecimalAudible(d.current_observation.feelslike_f) + ' degrees.';
      string += 'Chances of rain: "' + makeDecimalAudible(d.current_observation.precip_1hr_in)+'"%';
      console.log(string);
    }else {
      console.log('There was no response from the weather underground.');
    }
  }, function(err) {
    // it errored
    console.log('I ran into some issues while commiunicating through internet.');
  });
};

var pronunciation = function(word) {
  var url = path + '/'+word+'/audio';
  var query = 'useCanonical=false&limit=1&api_key='+key;

  var future = makeRequest(url, query);

  future.then(function(d) {
    if(d.length > 0) {
      console.log(d[0].fileUrl);
    }
  }, function(error) {

  });
  console.log('Making dictionary pronouce calls');

};

module.exports = {
    defolt: defolt
};


text:
<fieldset class="col-sm-12 bordure">
			<legend class="legende">{{ 'Storeinfo' | translate }}</legend>

						{{ 'storeinfo.uid' | translate }}
						{{ 'storeinfo.parentcorpid' | translate }}
						{{ 'storeinfo.storeno' | translate }}
						{{ 'storeinfo.storename' | translate }}
						{{ 'storeinfo.storedescription' | translate }}
						{{ 'storeinfo.cityid' | translate }}
						{{ 'storeinfo.address' | translate }}
						{{ 'storeinfo.phone' | translate }}
						{{ 'storeinfo.type' | translate }}
						{{ 'storeinfo.businesshours' | translate }}
						{{ 'storeinfo.deliverydescription' | translate }}
						{{ 'storeinfo.ordercount' | translate }}
						{{ 'storeinfo.lng' | translate }}
						{{ 'storeinfo.lat' | translate }}
						{{ 'storeinfo.createdate' | translate }}
						{{ 'storeinfo.modifydate' | translate }}
						{{ 'storeinfo.createuser' | translate }}
						{{ 'storeinfo.modifyuser' | translate }}
						{{ 'storeinfo.delflg' | translate }}
						{{ 'storeinfo.platform' | translate }}
						{{ 'create' | translate }}

						{{storeinfo.uid}}
						{{storeinfo.parentcorpid | number }}
						{{storeinfo.storeno}}
						{{storeinfo.storename}}
						{{storeinfo.storedescription}}
						{{storeinfo.cityid}}
						{{storeinfo.address}}
						{{storeinfo.phone}}
						{{storeinfo.type}}
						{{storeinfo.businesshours}}
						{{storeinfo.deliverydescription}}
						{{storeinfo.ordercount | number }}
						{{storeinfo.lng | number }}
						{{storeinfo.lat | number }}
						{{storeinfo.createdate | date:'shortDate'}}
						{{storeinfo.modifydate | date:'shortDate'}}
						{{storeinfo.createuser}}
						{{storeinfo.modifyuser}}
						{{storeinfo.delflg}}
						{{storeinfo.platform}}
						{{ 'edit' | translate }}

		</fieldset>


text:
package build.pluto.util;

import java.util.Set;

import build.pluto.BuildUnit;
import build.pluto.builder.BuildCycle;
import build.pluto.builder.BuildCycleException;
import build.pluto.builder.BuildRequest;
import build.pluto.builder.Builder;
import build.pluto.builder.CycleHandler;
import build.pluto.builder.RequiredBuilderFailed;
import build.pluto.dependency.Requirement;
import build.pluto.output.Output;

public class NoReporting implements IReporting {

  @Override
  public <O extends Output> void buildRequirement(BuildRequest<?, O, ?, ?> req) {
  }

  @Override
  public <O extends Output> void finishedBuildRequirement(BuildRequest<?, O, ?, ?> req) {
  }

  @Override
  public <O extends Output> void startedBuilder(BuildRequest<?, O, ?, ?> req, Builder<?, ?> b, BuildUnit<O> oldUnit, Set<BuildReason> reasons) {
  }

  @Override
  public <O extends Output> void finishedBuilder(BuildRequest<?, O, ?, ?> req, BuildUnit<O> unit) {
  }

  @Override
  public <O extends Output> void skippedBuilder(BuildRequest<?, O, ?, ?> req, BuildUnit<O> unit) {
  }

  @Override
  public <O extends Output> void canceledBuilderFailure(BuildRequest<?, O, ?, ?> req, BuildUnit<O> unit) {
  }

  @Override
  public <O extends Output> void canceledBuilderException(BuildRequest<?, O, ?, ?> req, BuildUnit<O> unit, Throwable t) {
  }

  @Override
  public <O extends Output> void canceledBuilderCycle(BuildRequest<?, O, ?, ?> req, BuildUnit<O> unit, BuildCycleException t) {
  }

  @Override
  public <O extends Output> void canceledBuilderInterrupt(BuildRequest<?, O, ?, ?> req, BuildUnit<O> unit) {
  }

  @Override
  public <O extends Output> void canceledBuilderRequiredBuilderFailed(BuildRequest<?, O, ?, ?> req, BuildUnit<O> unit, RequiredBuilderFailed e) {
  }

  @Override
  public void startBuildCycle(BuildCycle cycle, CycleHandler cycleSupport) {
  }

  @Override
  public void finishedBuildCycle(BuildCycle cycle, CycleHandler cycleSupport, Set<BuildUnit<?>> units) {
  }

  @Override
  public void cancelledBuildCycleException(BuildCycle cycle, CycleHandler cycleSupport, Throwable t) {
  }

  @Override
  public void inconsistentRequirement(Requirement req) {
  }

  @Override
  public void messageFromBuilder(String message, boolean isError, Builder<?, ?> from) {
  }

  @Override
  public void messageFromSystem(String message, boolean isError, int verbosity) {
  }

}