text:
"""Unit tests for scripts/linters/js_ts_linter.py."""

from __future__ import absolute_import  # pylint: disable=import-only-modules
from __future__ import unicode_literals  # pylint: disable=import-only-modules

import multiprocessing
import os

from core.tests import test_utils

from . import general_purpose_linter
from . import pre_commit_linter

NAME_SPACE = multiprocessing.Manager().Namespace()
NAME_SPACE.files = pre_commit_linter.FileCache()
FILE_CACHE = NAME_SPACE.files

LINTER_TESTS_DIR = os.path.join(os.getcwd(), 'scripts', 'linters', 'test_files')

# HTML filepaths.
INVALID_NG_TEMPLATE_HTML_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_ng_template.html')
INVALID_TRAILING_WHITESPACE_HTML_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_trailing_whitespace.html')
INVALID_PARENT_HTML_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_parent.html')
INVALID_GLYPHICON_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_glyphicon.html')
INVALID_STYLE_TAG_HTML_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_style_tag.html')

# CSS filepaths.
INVALID_CSS_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid.css')

# Js and Ts filepaths.
FILE_IN_EXCLUDED_PATH = os.path.join(
    'core', 'tests', 'build_sources', 'assets', 'constants.js')
INVALID_EXPLORE_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_explore.js')
INVALID_PAUSE_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_pause.js')
INVALID_SLEEP_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_sleep.js')
INVALID_WAIT_FOR_ANGULAR_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_wait_for_angular.js')
INVALID_FDESCRIBE_DDESCRIBE_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_ddescribe_fdescribe.ts')
INVALID_IIT_FIT_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_iit_fit.ts')
INVALID_INJECT_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_inject.ts')
INVALID_INNER_HTML_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_innerhtml.ts')
INVALID_RELATIVE_IMPORT_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_relative_import.js')
INVALID_PARENT_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_parent.ts')
INVALID_TEMPLATE_URL_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_templateurl.ts')
INVALID_FILEOVERVIEW_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_fileoverview.ts')
INVALID_TO_THROW_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_toThrow.ts')
INVALID_THROW_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_throw.ts')
INVALID_THROW_WITH_STRING_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_throw_with_string.ts')
INVALID_ESLINT_CAMELCASE_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_eslint_camelcase.ts')
INVALID_ESLINT_ANY_TYPE_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_eslint_any_type.ts')
INVALID_BROADCAST_USE_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_broadcast_use.ts')
INVALID_LODASH_IMPORT_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_lodash_import.ts')

# PY filepaths.
INVALID_ITERKEY_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_iterkeys.py')
INVALID_ITERVALUES_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_itervalues.py')
INVALID_ITERITEMS_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_iteritems.py')
INVALID_METACLASS_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_metaclass.py')
INVALID_BASESTRING_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_basestring.py')
INVALID_ZIP_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_zip.py')
INVALID_STR_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_str.py')
INVALID_ROUND_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_round.py')
INVALID_RANGE_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_range.py')
INVALID_OBJECT_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_object.py')
INVALID_NEXT_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_next.py')
INVALID_MAP_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_map.py')
INVALID_INPUT_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_input.py')
INVALID_REQUEST_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_request.py')
INVALID_URLJOIN_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_urljoin.py')
INVALID_UNQUOTE_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_unquote.py')
INVALID_NO_NEWLINE_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_no_newline.py')
INVALID_PARSE_QS_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_parse_qs.py')
INVALID_URL_UNSPLIT_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_urlunsplit.py')
INVALID_URLPARSE_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_urlparse.py')
INVALID_URLSPLIT_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_urlsplit.py')
INVALID_URLOPEN_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_urlopen.py')
INVALID_URLRETRIEVE_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_urlretrieve.py')
INVALID_AUTHOR_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_author.py')
INVALID_DATETIME_NOW_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_datetime_now.py')
INVALID_PRINT_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_print.py')
INVALID_PYLINT_ID_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_pylint_id.py')
INVALID_ASSERT_EQUALS_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_assert_equals.py')
INVALID_OPEN_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_open.py')
INVALID_STRINGIO_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_stringio.py')
INVALID_QUOTE_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_quote.py')
INVALID_UNQUOTE_PLUS_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_urlunquote_plus.py')
INVALID_URLENCODE_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_urlencode.py')
INVALID_TABS_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_tabs.py')
INVALID_MERGE_CONFLICT_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_merge_conflict.py')
INVALID_TODO_FILEPATH = os.path.join(LINTER_TESTS_DIR, 'invalid_todo.py')
INVALID_COPYRIGHT_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_copyright.py')
INVALID_UNICODE_LITERAL_FILEPATH = os.path.join(
    LINTER_TESTS_DIR, 'invalid_unicode_literal.py')
INVALID_DEV_MODE_IN_CONSTANT_FILEPATH = 'constants.ts'

class HTMLLintTests(test_utils.LinterTestBase):
    """Test the HTML lint functions."""

    def test_invalid_use_of_ng_template(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_NG_TEMPLATE_HTML_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 9: The directives must be directly referenced.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_trailing_whitespace(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_TRAILING_WHITESPACE_HTML_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 9: There should not be any trailing whitespaces.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_parent(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_PARENT_HTML_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 13: Please do not access parent properties using '
            '$parent. Use the scope object for this purpose.'
            ], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_style(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_STYLE_TAG_HTML_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 2: Please do not use inline styling.'
            ], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

class JsTsLintTests(test_utils.LinterTestBase):
    """Test the JsTs lint functions."""

    def test_invalid_use_of_browser_explore(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_EXPLORE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 30: In tests, please do not use browser.explore().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_browser_pause(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_PAUSE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 30: In tests, please do not use browser.pause().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_browser_sleep(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_SLEEP_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 30: In tests, please do not use browser.sleep().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_browser_wait_for_angular(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_WAIT_FOR_ANGULAR_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 30: In tests, please do not use '
            'browser.waitForAngular().'], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_fdescribe_ddescribe(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_FDESCRIBE_DDESCRIBE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 24: In tests, please use \'describe\' instead of '
            '\'ddescribe\'or \'fdescribe\''], lint_task_report.trimmed_messages)
        self.assert_same_list_elements([
            'Line 28: In tests, please use \'describe\' instead of '
            '\'ddescribe\'or \'fdescribe\''], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_iit_fit(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_IIT_FIT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 40: In tests, please use \'it\' instead of \'iit\' or '
            '\'fit\''], lint_task_report.trimmed_messages)
        self.assert_same_list_elements([
            'Line 64: In tests, please use \'it\' instead of \'iit\' or '
            '\'fit\''], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_inject(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_INJECT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 26: In tests, please use \'angular.mock.inject\' '
            'instead of \'inject\''], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_template_url(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_TEMPLATE_URL_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 24: The directives must be directly referenced.'
            ], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_parent(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_PARENT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 25: Please do not access parent properties using '
            '$parent. Use the scope objectfor this purpose.'
            ], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_relative_import(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_RELATIVE_IMPORT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 20: Please, don\'t use relative imports in require().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_inner_html(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_INNER_HTML_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 27: Please do not use innerHTML property.'
            ], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_to_throw(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_TO_THROW_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 25: Please use \'toThrowError\' instead of \'toThrow\''],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_throw(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_THROW_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 27: Please use \'throw new\' instead of \'throw\''],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_throw_with_string(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_THROW_WITH_STRING_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 27: Please use \'throw new Error\' instead of '
            '\'throw\''], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_eslint_camelcase_comment(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_ESLINT_CAMELCASE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 24: Please do not use eslint disable for camelcase. If '
            'you are using this statement to define properties in an '
            'interface for a backend dict. Wrap the property name in '
            'single quotes instead.'], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_eslint_no_explicit_any_comment(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_ESLINT_ANY_TYPE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 21: Please do not define "any" types. You can refer '
             'https://github.com/oppia/oppia/wiki/Guide-on-defining-types '
             'if you\'re having trouble declaring types.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_broadcast(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_BROADCAST_USE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 26: Please do not use $broadcast/$on for propagating events. '
            'Use @Input/@Output instead.'], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_lodash_import(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_LODASH_IMPORT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            [
                'Line 20: Please do not use "import { someFunction } '
                'from \'lodash\'". Use "import someFunction '
                'from \'lodash/someFunction\'" instead.',
            ],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

class PythonLintTests(test_utils.LinterTestBase):
    """Test the Python lint functions."""

    def test_invalid_use_of_author(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_AUTHOR_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 26: Please remove author tags from this file.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_datetime_now(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_DATETIME_NOW_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 42: Please use datetime.datetime.utcnow() instead '
            'of datetime.datetime.now().'], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_print(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_PRINT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 42: Please use python_utils.PRINT().'
            ], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_pylint_id(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_PYLINT_ID_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 43: Please remove pylint exclusion if it is unnecessary,'
            ' or make it human readable with a sentence instead of an id. '
            'The id-to-message list can be seen '
            'here->http://pylint-messages.wikidot.com/all-codes'
            ], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_assert_equals(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_ASSERT_EQUALS_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 43: Please do not use self.assertEquals method. This '
            'method has been deprecated. Instead use self.assertEqual '
            'method.'], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_open(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_OPEN_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 42: Please use python_utils.open_file() instead '
            'of open().'], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_stringio(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_STRINGIO_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 44: Please use python_utils.string_io() instead of '
            'import StringIO.'], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_quote(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_QUOTE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 44: Please use python_utils.url_quote().'
            ], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_unquote_plus(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_UNQUOTE_PLUS_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 45: Please use python_utils.url_unquote_plus().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_urlencode(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_URLENCODE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 46: Please use python_utils.url_encode().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_urlretrieve(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_URLRETRIEVE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 46: Please use python_utils.url_retrieve().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_urlopen(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_URLOPEN_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 45: Please use python_utils.url_open().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_urlsplit(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_URLSPLIT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 46: Please use python_utils.url_split().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_urlparse(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_URLPARSE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 46: Please use python_utils.url_parse().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_url_unsplit(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_URL_UNSPLIT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 46: Please use python_utils.url_unsplit().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_parse_qs(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_PARSE_QS_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 45: Please use python_utils.parse_query_string().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_unquote(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_UNQUOTE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 44: Please use python_utils.urllib_unquote().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_urljoin(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_URLJOIN_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 46: Please use python_utils.url_join().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_request(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_REQUEST_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 47: Please use python_utils.url_request().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_input(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_INPUT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 42: Please use python_utils.INPUT.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_map(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_MAP_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 42: Please use python_utils.MAP.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_next(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_NEXT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 43: Please use python_utils.NEXT.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_object(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_OBJECT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 25: Please use python_utils.OBJECT.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_range(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_RANGE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 42: Please use python_utils.RANGE.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_round(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_ROUND_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 42: Please use python_utils.ROUND.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_str(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_STR_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 42: Please try to use python_utils.convert_to_bytes() '
            'for the strings used in webapp2\'s built-in methods or for '
            'strings used directly in NDB datastore models. If you need to'
            ' cast ints/floats to strings, please use '
            'python_utils.UNICODE() instead.'
            ], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_zip(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_ZIP_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 44: Please use python_utils.ZIP.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_basestring(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_BASESTRING_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 42: Please use python_utils.BASESTRING.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_metaclass(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_METACLASS_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 46: Please use python_utils.with_metaclass().'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_iteritems(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_ITERITEMS_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 43: Please use items() instead.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_itervalues(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_ITERVALUES_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 43: Please use values() instead.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_iterkeys(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_ITERKEY_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Line 43: Please use keys() instead.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

class GeneralLintTests(test_utils.LinterTestBase):
    """Test all other general lint functions."""

    def test_invalid_use_of_tabs(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_TABS_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Please use spaces instead of tabs.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_merge_conflict_present(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_MERGE_CONFLICT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Please fully resolve existing merge conflicts.',
            'Please fully resolve existing merge conflicts.'
            ], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_glyphicon(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_GLYPHICON_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements(
            ['Please use equivalent material-icons instead of glyphicons.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_use_of_todo(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_TODO_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Line 33: Please assign TODO comments to a user in the format'
            ' TODO(username): XXX.'], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_missing_copyright(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_COPYRIGHT_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_mandatory_patterns()
        self.assert_same_list_elements([
            'Please ensure this file should contain a proper copyright '
            'notice.'], lint_task_report.trimmed_messages)
        self.assertEqual('Mandatory pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_missing_unicode_literal(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_UNICODE_LITERAL_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_mandatory_patterns()
        self.assert_same_list_elements([
            'Please ensure this file should contain unicode_literals '
            'future import.'], lint_task_report.trimmed_messages)
        self.assertEqual('Mandatory pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_missing_fileoverview(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_FILEOVERVIEW_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_mandatory_patterns()
        self.assert_same_list_elements([
            'Please ensure this file should contain a file overview i.e. '
            'a short description of the file.'
            ], lint_task_report.trimmed_messages)
        self.assertEqual('Mandatory pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_invalid_dev_mode_in_constant_ts(self):
        def mock_readlines(unused_self, unused_filepath):
            return (
                'Copyright 2020 The Oppia Authors. All Rights Reserved.',
                ' * @fileoverview Initializes constants for '
                'the Oppia codebase.',
                '"DEV_MODE": false\n',)

        readlines_swap = self.swap(
            pre_commit_linter.FileCache, 'readlines', mock_readlines)

        with readlines_swap:
            linter = general_purpose_linter.GeneralPurposeLinter(
                [INVALID_DEV_MODE_IN_CONSTANT_FILEPATH], FILE_CACHE)
            lint_task_report = linter.check_bad_patterns()
        self.assert_same_list_elements([
            'Please set the DEV_MODE variable in constants.ts'
            'to true before committing.'], lint_task_report.trimmed_messages)
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_linter_with_no_files(self):
        lint_task_report = general_purpose_linter.GeneralPurposeLinter(
            [], FILE_CACHE).perform_all_lint_checks()
        self.assertEqual(
            [
                'There are no files to be checked.',
                'SUCCESS  General purpose lint check passed'],
            lint_task_report[0].get_report())
        self.assertEqual('General purpose lint', lint_task_report[0].name)
        self.assertFalse(lint_task_report[0].failed)

    def test_file_with_no_newline_at_eof(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_NO_NEWLINE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.check_newline_at_eof()
        self.assert_same_list_elements(
            ['There should be a single newline at the end of file.'],
            lint_task_report.trimmed_messages)
        self.assertEqual('Newline at EOF', lint_task_report.name)
        self.assertTrue(lint_task_report.failed)

    def test_with_excluded_filepath(self):
        def mock_is_filepath_excluded_for_bad_patterns_check(
                unused_pattern, unused_filepath):
            return True

        filepath_excluded_swap = self.swap(
            general_purpose_linter,
            'is_filepath_excluded_for_bad_patterns_check',
            mock_is_filepath_excluded_for_bad_patterns_check)

        with filepath_excluded_swap:
            linter = general_purpose_linter.GeneralPurposeLinter(
                [INVALID_NO_NEWLINE_FILEPATH], FILE_CACHE)
            lint_task_report = linter.check_bad_patterns()
        self.assertEqual(
            ['SUCCESS  Bad pattern check passed'],
            lint_task_report.get_report())
        self.assertEqual('Bad pattern', lint_task_report.name)
        self.assertFalse(lint_task_report.failed)

    def test_perform_all_lint_checks_with_success(self):
        linter = general_purpose_linter.GeneralPurposeLinter(
            [INVALID_NO_NEWLINE_FILEPATH], FILE_CACHE)
        lint_task_report = linter.perform_all_lint_checks()
        self.assertTrue(isinstance(lint_task_report, list))

    def test_get_linters_with_success(self):
        custom_linter, third_party_linter = general_purpose_linter.get_linters(
            [INVALID_AUTHOR_FILEPATH], FILE_CACHE)
        self.assertTrue(
            isinstance(
                custom_linter, general_purpose_linter.GeneralPurposeLinter))
        self.assertEqual(third_party_linter, None)


text:
package com.liuyf.demos.java8.common.pattern.callback;

public class CallbackImpl implements Callback {

	@Override
	public void methodToCallback() {
		System.out.println(" ==== callback method ==== ");
	}

}

redpajama_set_name: RedPajamaGithub


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aubergine.Interfaces;

namespace Aubergine.Interfaces
{
    public interface IExtractor
    {
        bool ParseLine(string line);
    }

    public interface IDSLExtractor : IExtractor
    {
        Dictionary<string, IDSLDefinition> DSLs { get; }
    }

    public interface IStoryExtractor : IExtractor
    {
        IEnumerable<IStoryContainer> Stories { get; }
    }
}


text:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<servico xsi:schemaLocation="http://servicos.gov.br/v3/schema.../servico.xsd" xmlns="http://servicos.gov.br/v3/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <id>obter-informacoes-sobre-as-plantas-do-jardim-botanico-do-rio-de-janeiro-colecoes-vivas</id>
    <dbId>2571</dbId>
    <nome>Obter informações sobre as plantas do Jardim Botânico do Rio de Janeiro (Coleções Vivas)</nome>
    <sigla></sigla>
    <nomes-populares>
        <item id="2070">Jardim Botânico</item>
    </nomes-populares>
    <descricao>A Coordenação de Coleções Vivas fornece informações botânicas sobre os espécimes da coleção viva, tombados no Arboreto do JBRJ, incluindo: Arboreto Geral, Bromeliário, Orquidário, Plantas Medicinais, Cactário e Plantas Insetívoras. As informações podem ser obtidas por solicitação do usuário à Coordenação das Coleções Vivas ou por consulta ao sistema Jabot, disponível na internet.</descricao>
    <contato></contato>
    <gratuito>true</gratuito>
    <porcentagem-manual>false</porcentagem-manual>
    <servico-digital>true</servico-digital>
    <link-servico-digital>http://jabot.jbrj.gov.br/v2/consulta.php</link-servico-digital>
    <solicitantes>
        <solicitante id="3144">
            <tipo>Qualquer pessoa pode utilizar este serviço</tipo>
            <requisitos></requisitos>
        </solicitante>
    </solicitantes>
    <tempo-total-estimado>
        <entre min="2" max="7" unidade="dias-corridos"/>
        <descricao></descricao>
    </tempo-total-estimado>
    <validade-documento>
        <descricao></descricao>
    </validade-documento>
    <etapas>
        <etapa id="6104">
            <titulo>Solicitar informação</titulo>
            <descricao></descricao>
            <documentos>
                <default/>
            </documentos>
            <custos>
                <default/>
            </custos>
            <canais-de-prestacao>
                <default>
                    <canal-de-prestacao id="6016" tipo="web">
                        <descricao>http://jabot.jbrj.gov.br/v2/consulta.php</descricao>
                    </canal-de-prestacao>
                    <canal-de-prestacao id="6017" tipo="presencial">
                        <descricao>** Coordenação das Coleções Vivas** - Rua Jardim Botânico, 1008 - Jardim Botânico - CEP 22470-180</descricao>
                    </canal-de-prestacao>
                    <canal-de-prestacao id="6018" tipo="postal">
                        <descricao>** Coordenação das Coleções Vivas** - Rua Jardim Botânico, 1008 - Jardim Botânico - CEP 22470-180</descricao>
                    </canal-de-prestacao>
                </default>
            </canais-de-prestacao>
        </etapa>
    </etapas>
    <orgao id="http://estruturaorganizacional.dados.gov.br/id/unidade-organizacional/1913" dbId="37021">
        <nomeOrgao>Instituto de Pesquisas Jardim Botânico do Rio de Janeiro (JBRJ)</nomeOrgao>
    </orgao>
    <segmentos-da-sociedade>
        <item idSegmento="1" idServicoSegmento="6038">Cidadãos</item>
    </segmentos-da-sociedade>
    <areas-de-interesse>
        <item>Meio ambiente</item>
        <item>Pesquisa e Desenvolvimento</item>
        <item>Biodiversidade</item>
        <item>Educação</item>
        <item>Pesquisa, Ciência, Inovação e Tecnologia</item>
    </areas-de-interesse>
    <palavras-chave>
        <item id="11485">informações</item>
        <item id="11486">plantas</item>
        <item id="11487">taxons</item>
    </palavras-chave>
</servico>


text:
import urllib2
import smtplib
import StringIO

class URLChecker:
    """Basic checks for website in url
       cgitb should be disabled in the cgi script, or it won't work
    """
    def __init__(self):
        return

    url = "http://enzyme.ucd.ie/cgi-bin/titration_db/main.cgi"

    def check(self):
        try:
            stream = urllib2.urlopen(self.url)
            info = stream.info()
            print info
            status = info.status
            print status
            if status is not "":
                stream = None
                error = 'Error status %s' % str(status)
                print error
            else:
                lines = stream.readlines()
                string = "".join(lines)
                print string
                #stream = StringIO.StringIO(string)
                #print stream
        except urllib2.HTTPError, e:
            print e.code
            self.sendMail(e.code)
        return

    def sendMail(self, errcode=None):
        """send a mail"""
        to = 'damien.farrell@ucd.ie'
        mail_user = 'damienfa'
        sender = 'Titration_DB admin'
        smtpserver = smtplib.SMTP("mail.ucd.ie")
        smtpserver.ehlo()
        smtpserver.starttls()
        smtpserver.ehlo
        header = 'To:' + to + '\n' + 'From: ' + sender + '\n' + 'Subject: titdb problem \n'
        print header
        msg = header + '\n There is a problem with the titration_db website.. \n\n'
        smtpserver.sendmail(mail_user, to, msg)
        print 'done!'
        smtpserver.close()
        return

C=URLChecker()
C.check()
#C.sendMail()


text:
import { backgroundColor, border, color, margin, padding, width } from "@juniper-lib/dom/css";
import { onContextMenu } from "@juniper-lib/dom/evts";
import { Div, elementApply, HR, Span } from "@juniper-lib/dom/tags";
import { isDefined } from "@juniper-lib/tslib/typeChecks";
import { ContextMenu } from "@juniper-lib/widgets/ContextMenu";

type Options =
    | "red"
    | "green"
    | "blue"
    | "cancel";

const displayValues = new Map<Options, string>([
    ["red", "Red Color"],
    ["green", "Green Color"],
    ["blue", "Blue Color"],
    ["cancel", "Cancel Selection"]
]);

const menu = new ContextMenu();

const target = Div(
    padding("3em"),
    margin("auto", "3em"),
    width("max-content"),
    backgroundColor("yellow"),
    border("solid 1px black"),

    Span(
        color("white"),
        "Right-click Me!"
    ),

    onContextMenu(async (evt) => {
        evt.preventDefault();
        target.style.backgroundColor = "grey";

        const selection = await menu.show(
            displayValues,
            "red",
            "green",
            "blue",
            HR(),
            "cancel"
        );

        if (!isDefined(selection)) {
            target.style.backgroundColor = "yellow";
        }
        else if (selection === "cancel") {
            target.style.backgroundColor = "orange";
        }
        else {
            target.style.backgroundColor = selection;
        }
    })
);

elementApply("main", menu, target);


text:
<?xml version="1.0" encoding="UTF-8" ?>
<webTalkData  fileName='usage_statistics_ext_xsim.xml'  majorVersion='1' minorVersion='0' timeStamp='Fri Feb  6 15:59:00 2015'>

  <keyValuePair key="beta" value="FALSE" description="" />
  <keyValuePair key="build_version" value="1071353" description="" />
  <keyValuePair key="date_generated" value="Fri Feb  6 15:59:00 2015" description="" />
  <keyValuePair key="os_platform" value="LIN64" description="" />
  <keyValuePair key="product_version" value="XSIM v2014.4 (64-bit)" description="" />
  <keyValuePair key="project_id" value="c62e1743a58f43e5b10b0a4a8dc98cbb" description="" />
  <keyValuePair key="project_iteration" value="2" description="" />
  <keyValuePair key="random_id" value="b479b61f-b887-46af-b034-2be23a8f05b9" description="" />
  <keyValuePair key="registration_id" value="176283734_206273414_210559660_562" description="" />
  <keyValuePair key="route_design" value="FALSE" description="" />
  <keyValuePair key="target_device" value="not_applicable" description="" />
  <keyValuePair key="target_family" value="not_applicable" description="" />
  <keyValuePair key="target_package" value="not_applicable" description="" />
  <keyValuePair key="target_speed" value="not_applicable" description="" />
  <keyValuePair key="tool_flow" value="xsim_vivado" description="" />

  <keyValuePair key="cpu_name" value="Intel(R) Core(TM) i7-4930K CPU @ 3.40GHz" description="" />
  <keyValuePair key="cpu_speed" value="3399.867 MHz" description="" />
  <keyValuePair key="os_name" value="Fedora" description="" />
  <keyValuePair key="os_release" value="Fedora release 20 (Heisenbug)" description="" />
  <keyValuePair key="system_ram" value="67.000 GB" description="" />
  <keyValuePair key="total_processors" value="1" description="" />

   <keyValuePair key="command" value="xsim" description="" />
   <keyValuePair key="runall" value="false" description="" />

   <keyValuePair key="iteration" value="6" description="" />
   <keyValuePair key="runtime" value="51 us" description="" />
   <keyValuePair key="simulation_memory" value="295652_KB" description="" />
   <keyValuePair key="simulation_time" value="0.09_sec" description="" />
   <keyValuePair key="trace_waveform" value="true" description="" />

</webTalkData>


text:
package com.speedment.runtime.core.internal.stream.builder.action.longs;

import com.speedment.runtime.core.stream.action.Action;

import java.util.stream.LongStream;
import java.util.stream.Stream;

import static com.speedment.runtime.core.internal.stream.builder.action.StandardBasicAction.BOXED;

/**
 *
 * @author pemi
 */
public final class LongBoxedAction extends Action<LongStream, Stream<Long>> {

    public LongBoxedAction() {
        super(LongStream::boxed, Stream.class, BOXED);
    }

}


text:
declare namespace JQueryUI {
    interface UI {
        dynatree: DynatreeNamespace
    }
}

interface JQuery {
    dynatree(options?: DynatreeOptions): DynaTree;
    dynatree(option?: string, ...rest: any[]): any;
}

interface DynaTree {
    activateKey(key: string): DynaTreeNode;
    count(): number;
    enable(): void;
    disable(): void;
    enableUpdate(enable: boolean): void;
    getActiveNode(): DynaTreeNode;
    getNodeByKey(key: string): DynaTreeNode;
    getPersistData(): any;
    getRoot(): DynaTreeNode;
    getSelectedNodes(stopOnParents: boolean): DynaTreeNode[];
    initialize(): void;
    isInitializing(): boolean;
    isReloading(): boolean;
    isUserEvent(): boolean;
    loadKeyPath(keyPath: string, callback: (node: DynaTreeNode, status: string) =>void ): void;
    reactivate(setFocus: boolean): void;
    redraw(): void;
    reload(): void;
    renderInvisibleNodes(): void;
    selectKey(key: string, flag: string): DynaTreeNode;
    serializeArray(stopOnParents: boolean): any[];
    toDict(includeRoot?: boolean): any;
    visit(fn: (node: DynaTreeNode) =>boolean, includeRoot?: boolean): void;
}

interface DynaTreeNode {
    data: DynaTreeDataModel;
    activate(): void;
    activateSilently(): void;
    addChild(nodeData: DynaTreeDataModel, beforeNode?: DynaTreeNode): void;
    addChild(nodeData: DynaTreeDataModel[], beforeNode?: DynaTreeNode): void;
    appendAjax(ajaxOptions: JQueryAjaxSettings): void;
    countChildren(): number;
    deactivate(): void;
    expand(flag: boolean): void;
    focus(): void;
    getChildren(): DynaTreeNode[];
    getEventTargetType(event: Event): string;
    getLevel(): number;
    getNextSibling(): DynaTreeNode;
    getParent(): DynaTreeNode;
    getPrevSibling(): DynaTreeNode;
    hasChildren(): boolean;
    isActive(): boolean;
    isChildOf(otherNode: DynaTreeNode): boolean;
    isDescendantOf(otherNode: DynaTreeNode): boolean;
    isExpanded(): boolean;
    isFirstSibling(): boolean;
    isFocused(): boolean;
    isLastSibling(): boolean;
    isLazy(): boolean;
    isLoading(): boolean;
    isSelected(): boolean;
    isStatusNode(): boolean;
    isVisible(): boolean;
    makeVisible(): boolean;
    move(targetNode: DynaTreeNode, mode: string): boolean;
    reload(force: boolean): void;
    reloadChildren(callback?: (node: DynaTreeNode, isOk: boolean) => any): void;
    remove(): void;
    removeChildren(): void;
    render(useEffects: boolean, includeInvisible: boolean): void;
    resetLazy(): void;
    scheduleAction(mode: string, ms: number): void;
    select(flag: boolean): void;
    setLazyNodeStatus(status: number): void;
    setTitle(title: string): void;
    sortChildren(cmp?: (a: DynaTreeNode, b: DynaTreeNode) =>number, deep?: boolean): void;
    toDict(recursive: boolean, callback?: (node: any) =>any): any;
    toggleExpand(): void;
    toggleSelect(): void;
    visit(fn: (node: DynaTreeNode) =>boolean, includeSelf: boolean): void;
    visitParents(fn: (node: DynaTreeNode) =>boolean, includeSelf: boolean): void;
}

interface DynatreeOptions {
    title?: string | undefined; // Tree's name (only used for debug outpu)
    minExpandLevel?: number | undefined; // 1: root node is not collapsible
    imagePath?: string | undefined; // Path to a folder containing icons. Defaults to 'skin/' subdirectory.
    children?: DynaTreeDataModel[] | undefined; // Init tree structure from this object array.
    initId?: string | undefined; // Init tree structure from a
 element with this ID.
    initAjax?: JQueryAjaxSettings | undefined; // Ajax options used to initialize the tree strucuture.
    autoFocus?: boolean | undefined; // Set focus to first child, when expanding or lazy-loading.
    keyboard?: boolean | undefined; // Support keyboard navigation.
    persist?: boolean | undefined; // Persist expand-status to a cookie
    autoCollapse?: boolean | undefined; // Automatically collapse all siblings, when a node is expanded.
    clickFolderMode?: number | undefined; // 1:activate, 2:expand, 3:activate and expand
    activeVisible?: boolean | undefined; // Make sure, active nodes are visible (expanded).
    checkbox?: boolean | undefined; // Show checkboxes.
    selectMode?: number | undefined; // 1:single, 2:multi, 3:multi-hier
    fx?: any; // Animations, e.g. null or { height: "toggle", duration: 200 }
    noLink?: boolean | undefined; // Use  instead of  tags for all nodes
    debugLevel?: number | undefined; // 0:quiet, 1:normal, 2:debug
    generateIds?: boolean | undefined; // Generate id attributes like
    idPrefix?: string | undefined; // Used to generate node id's like <span id="dynatree-id-<key>">.
    keyPathSeparator?: string | undefined; // Used by node.getKeyPath() and tree.loadKeyPath().
    cookieId?: string | undefined; // Choose a more unique name, to allow multiple trees.

    dnd?: DynaTreeDNDOptions | undefined;  // Drag'n'drop support
    ajaxDefaults?: DynaTreeAjaxOptions | undefined;// Used by initAjax option
    strings?: DynaTreeStringsOptions | undefined;
    cookie?: DynaTreeCookieOptions | undefined;
    // Class names used, when rendering the HTML markup.
    // Note: if only single entries are passed for options.classNames, all other
    // values are still set to default.
    classNames?: DynatreeClassNamesOptions | undefined;

    // Low level event handlers: onEvent(dtnode, event): return false, to stop default processing
    onClick?: ((dtnode: DynaTreeNode, event: Event) =>boolean) | undefined; // null: generate focus, expand, activate, select events.
    onDblClick?: ((dtnode: DynaTreeNode, event: Event) =>boolean) | undefined; // (No default actions.)
    onKeydown?: ((dtnode: DynaTreeNode, event: Event) =>boolean) | undefined; // null: generate keyboard navigation (focus, expand, activate).
    onKeypress?: ((dtnode: DynaTreeNode, event: Event) =>boolean) | undefined; // (No default actions.)
    onFocus?: ((dtnode: DynaTreeNode, event: Event) =>boolean) | undefined; // null: set focus to node.
    onBlur?: ((dtnode: DynaTreeNode, event: Event) =>boolean) | undefined; // null: remove focus from node.

    // Pre-event handlers onQueryEvent(flag, dtnode): return false, to stop processing
    onQueryActivate?: ((flag: string, dtnode: DynaTreeNode) =>void) | undefined; // Callback(flag, dtnode) before a node is (de)activated.
    onQuerySelect?: ((flag: string, dtnode: DynaTreeNode) =>void) | undefined;// Callback(flag, dtnode) before a node is (de)selected.
    onQueryExpand?: ((flag: string, dtnode: DynaTreeNode) =>void) | undefined;// Callback(flag, dtnode) before a node is expanded/collpsed.

    // High level event handlers
    onPostInit?: ((isReloading: boolean, isError: boolean) =>void) | undefined;// Callback(isReloading, isError) when tree was (re)loaded.
    onActivate?: ((dtnode: DynaTreeNode) =>void) | undefined; // Callback(dtnode) when a node is activated.
    onDeactivate?: ((dtnode: DynaTreeNode) =>void) | undefined; // Callback(dtnode) when a node is deactivated.
    onSelect?: ((flag: string, dtnode: DynaTreeNode) =>void) | undefined; // Callback(flag, dtnode) when a node is (de)selected.
    onExpand?: ((flag: string, dtnode: DynaTreeNode) =>void) | undefined; // Callback(flag, dtnode) when a node is expanded/collapsed.
    onLazyRead?: ((dtnode: DynaTreeNode) =>void) | undefined; // Callback(dtnode) when a lazy node is expanded for the first time.
    onCustomRender?: ((dtnode: DynaTreeNode) =>void) | undefined; // Callback(dtnode) before a node is rendered. Return a HTML string to override.
    onCreate?: ((dtnode: DynaTreeNode, nodeSpan: any) =>void) | undefined; // Callback(dtnode, nodeSpan) after a node was rendered for the first time.
    onRender?: ((dtnode: DynaTreeNode, nodeSpan: any) =>void) | undefined; // Callback(dtnode, nodeSpan) after a node was rendered.
    postProcess?: ((data: any, dataType: any) =>void) | undefined; // Callback(data, dataType) before an Ajax result is passed to dynatree.
}

interface DynaTreeDataModel {
    title: string; // (required) Displayed name of the node (html is allowed here)
    key?: string | undefined; // May be used with activate(), select(), find(), ...
    isFolder?: boolean | undefined; // Use a folder icon. Also the node is expandable but not selectable.
    isLazy?: boolean | undefined; // Call onLazyRead(), when the node is expanded for the first time to allow for delayed creation of children.
    tooltip?: string | undefined; // Show this popup text.
    href?: string | undefined; // Added to the generated  tag.
    icon?: string | undefined; // Use a custom image (filename relative to tree.options.imagePath). 'null' for default icon, 'false' for no icon.
    addClass?: string | undefined; // Class name added to the node's span tag.
    noLink?: boolean | undefined; // Use  instead of  tag for this node
    activate?: boolean | undefined; // Initial active status.
    focus?: boolean | undefined; // Initial focused status.
    expand?: boolean | undefined; // Initial expanded status.
    select?: boolean | undefined; // Initial selected status.
    hideCheckbox?: boolean | undefined; // Suppress checkbox display for this node.
    unselectable?: boolean | undefined; // Prevent selection.
    // The following attributes are only valid if passed to some functions:
    children?: DynaTreeDataModel[] | undefined; // Array of child nodes.
    // NOTE: we can also add custom attributes here.
    // This may then also be used in the onActivate(), onSelect() or onLazyTree() callbacks.
}

interface DynaTreeDNDOptions {
    autoExpandMS?: number | undefined; // Expand nodes after n milliseconds of hovering.
    preventVoidMoves?: boolean | undefined; // Prevent dropping nodes 'before self', etc.
    revert: boolean; // true: slide helper back to source if drop is rejected

    // Make tree nodes draggable:
    onDragStart?: ((sourceNode: any) =>void) | undefined; // Callback(sourceNode), return true, to enable dnd
    onDragStop?: ((sourceNode: any) =>void) | undefined; // Callback(sourceNode)
    // Make tree nodes accept draggables

    onDragEnter?: ((targetNode: any, sourceNode: any) =>void) | undefined; // Callback(targetNode, sourceNode)
    onDragOver?: ((targetNode: any, sourceNode: any, hitMode: string) =>void) | undefined;  // Callback(targetNode, sourceNode, hitMode)
    onDrop?: ((targetNode: any, sourceNode: any, hitMode: string) =>void) | undefined; // Callback(targetNode, sourceNode, hitMode)
    onDragLeave?: ((targetNode: any, sourceNode: any) =>void) | undefined; // Callback(targetNode, sourceNode)
}

interface DynaTreeCookieOptions {
    expires: any;
}

interface DynaTreeStringsOptions {
    loading?: string | undefined;
    loadError?: string | undefined;
}

interface DynaTreeAjaxOptions {

    cache?: boolean | undefined; // false: Append random '_' argument to the request url to prevent caching.
    timeout?: number | undefined; // >0: Make sure we get an ajax error for invalid URLs
    dataType?: string | undefined; // Expect json format and pass json object to callbacks.
}

interface DynatreeClassNamesOptions {
    container?: string | undefined;
    node?: string | undefined;
    folder?: string | undefined;

    empty?: string | undefined;
    vline?: string | undefined;
    expander?: string | undefined;
    connector?: string | undefined;
    checkbox?: string | undefined;
    nodeIcon?: string | undefined;
    title?: string | undefined;
    noConnector?: string | undefined;

    nodeError?: string | undefined;
    nodeWait?: string | undefined;
    hidden?: string | undefined;
    combinedExpanderPrefix?: string | undefined;
    combinedIconPrefix?: string | undefined;
    hasChildren?: string | undefined;
    active?: string | undefined;
    selected?: string | undefined;
    expanded?: string | undefined;
    lazy?: string | undefined;
    focused?: string | undefined;
    partsel?: string | undefined;
    lastsib?: string | undefined;
}

interface DynatreeNamespace {
    getNode(element: HTMLElement): DynaTreeNode;
    getPersistData(cookieId: string, cookieOpts: DynaTreeCookieOptions): any;
    version: number;
}


text:
package se.kodapan.lucene.query;

import org.apache.lucene.search.Query;

/**
 * Constructs an envelope from a centroid and radius
 * by creating a circle and putting an envelope around it.
 *
 * @author kalle
 * @since 2014-09-09 14:40
 */
public class CoordinateCircleEnvelopeQueryFactory {

  private String latitudeField;
  private String longitudeField;

  private int circumferenceResolution = 8;

  private double radiusKilometers;

  private double centroidLatitude;
  private double centroidLongitude;

  public CoordinateCircleEnvelopeQueryFactory setCircumferenceResolution(int circumferenceResolution) {
    this.circumferenceResolution = circumferenceResolution;
    return this;
  }

  public CoordinateCircleEnvelopeQueryFactory setLatitudeField(String latitudeField) {
    this.latitudeField = latitudeField;
    return this;
  }

  public CoordinateCircleEnvelopeQueryFactory setLongitudeField(String longitudeField) {
    this.longitudeField = longitudeField;
    return this;
  }

  public CoordinateCircleEnvelopeQueryFactory setRadiusKilometers(double radiusKilometers) {
    this.radiusKilometers = radiusKilometers;
    return this;
  }

  public CoordinateCircleEnvelopeQueryFactory setCentroidLatitude(double centroidLatitude) {
    this.centroidLatitude = centroidLatitude;
    return this;
  }

  public CoordinateCircleEnvelopeQueryFactory setCentroidLongitude(double centroidLongitude) {
    this.centroidLongitude = centroidLongitude;
    return this;
  }

  public String getLatitudeField() {
    return latitudeField;
  }

  public String getLongitudeField() {
    return longitudeField;
  }

  public int getCircumferenceResolution() {
    return circumferenceResolution;
  }

  public double getRadiusKilometers() {
    return radiusKilometers;
  }

  public double getCentroidLatitude() {
    return centroidLatitude;
  }

  public double getCentroidLongitude() {
    return centroidLongitude;
  }

  public Query build() {

    double south = Double.MAX_VALUE;
    double west = Double.MAX_VALUE;
    double east = Double.MIN_VALUE;
    double north = Double.MIN_VALUE;

    double radiusLatitude = (radiusKilometers / 6378.8d) * (180 / Math.PI);
    double radiusLongitude = radiusLatitude / Math.cos(centroidLatitude * (Math.PI / 180));

    int step = (int) (360d / (double) circumferenceResolution);
//    for (int i = 0; i <= 361; i+= step) {
    for (int i = 0; i < 360; i += step) {
      double a = i * (Math.PI / 180);
      double latitude = centroidLatitude + (radiusLatitude * Math.sin(a));
      double longitude = centroidLongitude + (radiusLongitude * Math.cos(a));

      if (latitude < south) {
        south = latitude;
      }
      if (latitude > north) {
        north = latitude;
      }
      if (longitude < west) {
        west = longitude;
      }
      if (longitude > east) {
        east = longitude;
      }

    }

    return new CoordinateEnvelopeQueryFactory()
        .setLatitudeField(latitudeField)
        .setLongitudeField(longitudeField)
        .setSouth(south)
        .setWest(west)
        .setNorth(north)
        .setEast(east)
        .build();

  }

}


text:
-include ../tools.mk

# FIXME: ignore freebsd/windows
# on windows `rustc --dep-info` produces Makefile dependency with
# windows native paths (e.g. `c:\path\to\libfoo.a`)
# but msys make seems to fail to recognize such paths, so test fails.
ifneq ($(shell uname),FreeBSD)
ifndef IS_WINDOWS
all:
	$(RUSTC) --dep-info --crate-type=lib lib.rs
	sleep 2
	touch foo.rs
	-rm -f $(TMPDIR)/done
	$(MAKE) -drf Makefile.foo
	sleep 2
	rm $(TMPDIR)/done
	pwd
	$(MAKE) -drf Makefile.foo
	rm $(TMPDIR)/done && exit 1 || exit 0
else
all:

endif

else
all:

endif


text:
#region License

#endregion

using System;

namespace Spring.Context.Attributes
{
    /// <summary>
    /// Indicates whether a object is to be lazily initialized.
    ///
    /// <para>If this attribute is not present on a Component or object definition, eager
    /// initialization will occur. If present and set to true, the
    /// object/Component will not be initialized until referenced by another object or
    /// explicitly retrieved from the enclosing <see cref="Spring.Objects.Factory.IObjectFactory"/>.
    /// If present and set to false, the object will be instantiated on startup by object factories
    /// that perform eager initialization of singletons.
    /// </para>
    /// <para>
    /// If Lazy is present on a <see cref="ConfigurationAttribute"/> class, this indicates that all
    /// <see cref="ObjectDefAttribute"/> methods within that <see cref="ConfigurationAttribute"/> should be lazily
    /// initialized. If Lazy is present and false on a object method within a
    /// Lazy-annotated Configuration class, this indicates overriding the 'default
    /// lazy' behavior and that the object should be eagerly initialized.
    /// </para>
    /// </summary>
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
    public class LazyAttribute : Attribute
    {
        private bool _lazyInitialize = true;

        /// <summary>
        /// Initializes a new instance of the LazyAttribute class.
        /// </summary>
        /// <param name="lazyInitialize"></param>
        public LazyAttribute(bool lazyInitialize)
        {
            _lazyInitialize = lazyInitialize;
        }

        /// <summary>
        /// Initializes a new instance of the LazyAttribute class.
        /// </summary>
        public LazyAttribute()
        {

        }

        /// <summary>
        /// Whether lazy initialization should occur.
        /// </summary>
        /// <value><c>true</c> if [lazy initialize]; otherwise, <c>false</c>.</value>
        public bool LazyInitialize
        {
            get { return _lazyInitialize; }
            set
            {
                _lazyInitialize = value;
            }
        }

    }
}


text:
package org.ode4j.ode.internal.gimpact;

import static org.ode4j.ode.internal.gimpact.GimGeometry.AABBCOLLISION;
import static org.ode4j.ode.internal.gimpact.GimGeometry.AABB_COPY;
import static org.ode4j.ode.internal.gimpact.GimGeometry.BOXINTERSECTION;
import static org.ode4j.ode.internal.gimpact.GimGeometry.MERGEBOXES;
import static org.ode4j.ode.internal.gimpact.GimMath.CLAMP;

import org.ode4j.ode.internal.cpp4j.java.RefBoolean;
import org.ode4j.ode.internal.cpp4j.java.RefFloat;
import org.ode4j.ode.internal.gimpact.GimGeometry.aabb3f;
import org.ode4j.ode.internal.gimpact.GimGeometry.vec3f;
import org.ode4j.ode.internal.gimpact.GimRadixSort.GIM_RSORT_TOKEN;

/**
 * Tools for find overlapping objects on a scenery.
 * These functions sort boxes for faster collision queries, using radix
 * sort or quick sort as convenience. See \ref SORTING .
 * <ul>
 * <li> For using these collision routines, you must create a \ref GIM_AABB_SET
 *      by using this function : \ref gim_aabbset_alloc.
 * <li> The  GIM_AABB_SET objects must be updated on their boxes on each query,
 *      and they must be update by calling \ref gim_aabbset_update
 * <li> Before calling collision functions, you must create a pair set with \ref GIM_CREATE_PAIR_SET
 * <li> For finding collision pairs on a scene (common space for objects),
 *      call \ref gim_aabbset_self_intersections
 * <li> For finding collision pairs between two box sets , call \ref gim_aabbset_box_collision
 * <li> After using collision routines, you must destroy the pairset with \ref GIM_DESTROY_PAIR_SET
 * <li> When the box set is no longer used, you must destroy it by calling \ref gim_aabbset_destroy
 * </ul>
 * Ported to Java by Tilmann Zaeschke
 * @author Francisco Leon
 *
 */
public class GimAABBSet { //Formerly GimBoxPruning

	//! @{
	/** Overlapping pair. */
	static class GIM_PAIR
	{
		int m_index1;
		int m_index2;
	};
	//typedef struct _GIM_PAIR GIM_PAIR;

	/** Box container */
	//	static class GIM_AABB_SET
	//	{
	//	    GUINT32 m_count;
	//	    aabb3f m_global_bound;//!< Global calculated bound of all boxes
	//	    aabb3f * m_boxes;
	//	    GUINT32 * m_maxcoords;//!<Upper corners of the boxes, in integer representation
	//	    GIM_RSORT_TOKEN * m_sorted_mincoords;//!< sorted min coords (lower corners), with their coord value as the m_key and m_value as the box index
	//	    char m_shared;//!< if m_shared == 0 then the memory is allocated and the set must be destroyed, else the pointers are shared and the set should't be destroyed
	int m_count;
	aabb3f m_global_bound = new aabb3f();//!< Global calculated bound of all boxes
	private final aabb3f[] m_boxes;// = new aabb3f[0];  //TZ Why init
	long[] m_maxcoords;//!<Upper corners of the boxes, in integer representation
	GIM_RSORT_TOKEN[] m_sorted_mincoords;//!< sorted min coords (lower corners), with their coord value as the m_key and m_value as the box index
	char m_shared;//!< if m_shared == 0 then the memory is allocated and the set must be destroyed, else the pointers are shared and the set should't be destroyed
	//	};
	//typedef  struct _GIM_AABB_SET GIM_AABB_SET;

	public aabb3f getGlobalBound() {
		return m_global_bound;
	}

	/** Function for creating  an overlapping pair set. */
	//#define GIM_CREATE_PAIR_SET(dynarray) GIM_DYNARRAY_CREATE(GIM_PAIR,dynarray,G_ARRAY_GROW_SIZE)
	static GimDynArray<GIM_PAIR> GIM_CREATE_PAIR_SET() {
		return GimDynArray.GIM_DYNARRAY_CREATE(GimDynArray.G_ARRAY_GROW_SIZE);  //GIM_PAIR !! TZ TODO ?
	}

//	/**
//	 * Function for destroying an overlapping pair set.
//	 * @param dynarray
//	 */
//	//#define GIM_DESTROY_PAIR_SET(dynarray) GIM_DYNARRAY_DESTROY(dynarray)
//	void GIM_DESTROY_PAIR_SET(GimDynArray<GIM_PAIR> dynarray) { dynarray.GIM_DYNARRAY_DESTROY(); }
//
//	//! Allocate memory for all aabb set.
//	//	void gim_aabbset_alloc(GIM_AABB_SET aabbset, GUINT32 count);

	/*
	                Brute-Force Vs Sorted pruning
	Different approaches must be applied when colliding sets with different number of
	elements. When sets have less of 100 boxes, is often better to apply force brute
	approach instead of sorted methods, because at lowlevel bruteforce routines gives
	better perormance and consumes less resources, due of their simplicity.
	But when sets are larger, the complexiity of bruteforce increases exponencially.
	In the case of large sets, sorted approach is applied. So GIMPACT has the following
	strategies:

	On Sorting sets:
	!) When sets have more of 140 boxes, the boxes are sorted by its coded min coord
	and the global box is calculated. But when sets are smaller (less of 140 boxes),
	Is convenient to apply brute force approach.

	 *******************************************************************************/

	//! Constant for apply approaches between brute force and sorted pruning on bipartite queries
	private static final int GIM_MIN_SORTED_BIPARTITE_PRUNING_BOXES = 600;
	//! Constant for apply approaches between brute force and sorted pruning for box collision
	//(TZ)private static final int GIM_MIN_SORTED_PRUNING_BOXES = 140;

	///Function for create Box collision result set

//	//#define GIM_CREATE_BOXQUERY_LIST(dynarray) GIM_DYNARRAY_CREATE(GUINT32,dynarray,G_ARRAY_GROW_SIZE)
//	static GimDynArrayInt GIM_CREATE_BOXQUERY_LIST() {
//		return GimDynArrayInt.GIM_DYNARRAY_CREATE(GimDynArray.G_ARRAY_GROW_SIZE);
//	}

	/*
	For sorting, each box corner must be discretized to a 32 bit integer.
	For this, we take the x and z coordinates from the box corner (a vector vec3f)
	Then convert the (x,z) pair to an integer. For convenience, we choose an error
	constant for converting the coordinates (0.05).
	 *******************************************************************************/

	/**
	 * For fitting the coordinate to an integer, we need to constraint the
	 * range of its values. So each coord component (x, z) must lie between 0 and 65536.
	 * 20 give us a 0.05 floating point error
	 */
	private static final float ERROR_AABB = 20.0f;

	/**
	 * An error of 0.05 allows to make coordinates up to 1638.0f and no less of -1638.0f.
	 * So the maximum size of a room should be about 3276x3276 . Its dimensions must lie between  [-1638,1638.0f]
	 */
	private static final float MAX_AABB_SIZE = 1638.0f; //TZ ??? TODO ??

	/**
	 * Converts a vector coordinate to an integer for box sorting.
	 * @param vx X component
	 * @param vz Z component
	 * @param uint_key a GUINT
	 */
	//#define GIM_CONVERT_VEC3F_GUINT_XZ(vx,vz,uint_key)\
	long GIM_CONVERT_VEC3F_GUINT_XZ(float vx, float vz)
	{
		//	    int _z = ((GUINT32)(vz*ERROR_AABB))+32768;
		//	    uint_key = ((GUINT32)(vx*ERROR_AABB))+32768;
		//	    uint_key = (uint_key<<16) + _z;
		long _z = ((long)(vz*ERROR_AABB))+32768;
		long uint_key = ((long)(vx*ERROR_AABB))+32768;
		return (uint_key<<16) + _z;
	}

	/**
	 * Converts a vector coordinate to an integer for box sorting, rounding to the upper int.
	 * @param vx X component
	 * @param vz Z component
	 * @param uint_key a GUINT
	 */
	//#define GIM_CONVERT_VEC3F_GUINT_XZ_UPPER(vx,vz,uint_key)\
	long GIM_CONVERT_VEC3F_GUINT_XZ_UPPER(float vx, float vz)
	{
		//	    GUINT32 _z = ((GUINT32)ceilf(vz*ERROR_AABB))+32768;
		//	    uint_key = ((GUINT32)ceilf(vx*ERROR_AABB))+32768;
		//	    uint_key = (uint_key<<16) + _z;
		long _z = ((long)Math.ceil(vz*ERROR_AABB))+32768;
		long uint_key = ((long)Math.ceil(vx*ERROR_AABB))+32768;
		return (uint_key<<16) + _z;
	}

	/**
	 * Converts a vector coordinate to an integer for box sorting. Secure clamped.
	 * @param vx X component
	 * @param vz Z component
	 * @param uint_key a GUINT
	 */
	//#define GIM_CONVERT_VEC3F_GUINT_XZ_CLAMPED(vx,vz,uint_key)\
	long GIM_CONVERT_VEC3F_GUINT_XZ_CLAMPED(float vx, float vz)
	{
		//	    GREAL _cx = CLAMP(vx,-MAX_AABB_SIZE,MAX_AABB_SIZE);
		//	    GREAL _cz = CLAMP(vz,-MAX_AABB_SIZE,MAX_AABB_SIZE);
		//	    GUINT32 _z = ((GUINT32)(_cz*ERROR_AABB))+32768;
		//	    uint_key = ((GUINT32)(_cx*ERROR_AABB))+32768;
		//	    uint_key = (uint_key<<16) + _z;
		float _cx = CLAMP(vx,-MAX_AABB_SIZE,MAX_AABB_SIZE);
		float _cz = CLAMP(vz,-MAX_AABB_SIZE,MAX_AABB_SIZE);
		long _z = ((long)(_cz*ERROR_AABB))+32768;  //TZ should work, because is always positive!
		long uint_key = ((long)(_cx*ERROR_AABB))+32768;
		return (uint_key<<16) + _z;
	}

	/**
	 * Converts a vector coordinate to an integer for box sorting. Secure clamped, rounded.
	 * @param vx X component
	 * @param vz Z component
	 * @param uint_key a GUINT
	 */
	//#define GIM_CONVERT_VEC3F_GUINT_XZ_UPPER_CLAMPED(vx,vz,uint_key)\
	long GIM_CONVERT_VEC3F_GUINT_XZ_UPPER_CLAMPED(float vx, float vz)
	{
		//	    GREAL _cx = CLAMP(vx,-MAX_AABB_SIZE,MAX_AABB_SIZE);
		//	    GREAL _cz = CLAMP(vz,-MAX_AABB_SIZE,MAX_AABB_SIZE);
		//	    GUINT32 _z = ((GUINT32)ceilf(_cz*ERROR_AABB))+32768;
		//	    uint_key = ((GUINT32)ceilf(_cx*ERROR_AABB))+32768;
		//	    uint_key = (uint_key<<16) + _z;
		float _cx = CLAMP(vx,-MAX_AABB_SIZE,MAX_AABB_SIZE);
		float _cz = CLAMP(vz,-MAX_AABB_SIZE,MAX_AABB_SIZE);
		long _z = ((long)Math.ceil(_cz*ERROR_AABB))+32768;
		long uint_key = ((long)Math.ceil(_cx*ERROR_AABB))+32768;
		return (uint_key<<16) + _z;
	}

	private GimAABBSet(int count) {
		//private!!
		m_boxes = new aabb3f[count];
	}

	/** Allocate memory for all aabb set. */
	//	void gim_aabbset_alloc(GIM_AABB_SET aabbset, GUINT32 count)
	static GimAABBSet gim_aabbset_alloc(int count)
	{
		GimAABBSet x = new GimAABBSet(count);

		//GimAABBSet aabbset = new GimAABBSet(); //TZ
		x.m_count = count;
		//x.m_boxes = new aabb3f[count];//(aabb3f *)gim_alloc(sizeof(aabb3f)*count);
		for (int i = 0; i < count; i++) x.m_boxes[i] = new aabb3f(); //TZ

		if(count<GIM_MIN_SORTED_BIPARTITE_PRUNING_BOXES)
		{
			x.m_maxcoords = null;
			x.m_sorted_mincoords = null;
		}
		else
		{
			x.m_maxcoords = new long[x.m_count];//(GUINT32 *)gim_alloc(sizeof(GUINT32)*aabbset.m_count );
			//m_sorted_mincoords = (GIM_RSORT_TOKEN *)gim_alloc(sizeof(GIM_RSORT_TOKEN)*aabbset.m_count);
			x.m_sorted_mincoords = new GIM_RSORT_TOKEN[x.m_count];
			for (int i = 0; i < x.m_count; i++) x.m_sorted_mincoords[i] = new GIM_RSORT_TOKEN();
		}
		x.m_shared = 0;
		GimGeometry.INVALIDATE_AABB(x.m_global_bound);
		return x;
	}

	/** Destroys the aabb set. */
	void gim_aabbset_destroy()
	{
		m_count = 0;
		//TZ just set to null, will be gc'd if not shared
		//	    if(m_shared==0)
		//	    {
		//	        gim_free(m_boxes,0);
		//	        gim_free(m_maxcoords,0);
		//	        gim_free(m_sorted_mincoords,0);
		//	    }
		//m_boxes = null;
		m_sorted_mincoords = null;
		m_maxcoords = null;
	}

	/**
	 * Calcs the global bound only.
	 * @pre aabbset must be allocated. And the boxes must be already set.
	 */
	//void gim_aabbset_calc_global_bound(GIM_AABB_SET * aabbset);
	void gim_aabbset_calc_global_bound()
	{
//		aabb3f[] paabb = m_boxes;
//		int paabbPos = 0;//TZ
//		aabb3f globalbox = m_global_bound;
//		AABB_COPY(globalbox,paabb[paabbPos]);

//		int count = m_count-1;
//		paabbPos++;
//		while(count!=0)
//		{
//			MERGEBOXES(globalbox,paabb[paabbPos]);
//			paabbPos++;
//			count--;
//		}

		AABB_COPY(m_global_bound, m_boxes[0]);
		//check the first one again, but whatever.
		for (aabb3f aabb: m_boxes) {
			MERGEBOXES(m_global_bound, aabb);
		}
	}

	/**
	 * Sorts the boxes for box prunning.
	 * 1) find the integer representation of the aabb coords
	 * 2) Sorts the min coords
	 * 3) Calcs the global bound
	 * @pre aabbset must be allocated. And the boxes must be already set.
	 * @param aabbset
	 * @param calc_global_bound If 1 , calcs the global bound
	 * @post If aabbset.m_sorted_mincoords == 0, then it allocs the sorted coordinates
	 */
	void gim_aabbset_sort(final boolean calc_global_bound)
	{
		if(m_sorted_mincoords == null)
		{//allocate
			m_maxcoords = new long[m_count];//(GUINT32 *)gim_alloc(sizeof(GUINT32)*aabbset.m_count );
			m_sorted_mincoords = new GIM_RSORT_TOKEN[m_count];//(GIM_RSORT_TOKEN *)gim_alloc(sizeof(GIM_RSORT_TOKEN)*aabbset.m_count);
		}

		int i, count = m_count;
		aabb3f[] paabb = m_boxes;
		long[] maxcoords = m_maxcoords;
		GIM_RSORT_TOKEN[] sorted_tokens = m_sorted_mincoords;

		if(count<860)//Calibrated on a Pentium IV //TODO TZ verify !?!?!?!
		{
			//Sort by quick sort
			//Calculate keys
			for(i=0;i<count;i++)
			{
				maxcoords[i] = GIM_CONVERT_VEC3F_GUINT_XZ_UPPER(paabb[i].maxX,paabb[i].maxZ);
				sorted_tokens[i].m_key = GIM_CONVERT_VEC3F_GUINT_XZ(paabb[i].minX,paabb[i].minZ);
				sorted_tokens[i].m_value = i;
			}
			//GIM_QUICK_SORT_ARRAY(GIM_RSORT_TOKEN , sorted_tokens, count, RSORT_TOKEN_COMPARATOR,GIM_DEF_EXCHANGE_MACRO);
			GimRadixSort.GIM_QUICK_SORT_ARRAY(sorted_tokens, count,
					GimRadixSort.RSORT_TOKEN_COMPARATOR, GimRadixSort.GIM_DEF_EXCHANGE_MACRO);
		}
		else
		{
			//Sort by radix sort
			//GIM_RSORT_TOKEN[] unsorted = gim_alloc(count, GIM_RSORT_TOKEN.class);//(GIM_RSORT_TOKEN *)gim_alloc(sizeof(GIM_RSORT_TOKEN )*count);
			GIM_RSORT_TOKEN[] unsorted = new GIM_RSORT_TOKEN[count]; //TZ TODO clean up
			//Calculate keys
			for(i=0;i<count;i++)
			{
				unsorted[i] = new GIM_RSORT_TOKEN(); //TODO optimize! E.g. use two arrays?
				maxcoords[i] = GIM_CONVERT_VEC3F_GUINT_XZ_UPPER(paabb[i].maxX,paabb[i].maxZ);
				unsorted[i].m_key = GIM_CONVERT_VEC3F_GUINT_XZ(paabb[i].minX,paabb[i].minZ);
				unsorted[i].m_value = i;
			}
			GimRadixSort.GIM_RADIX_SORT_RTOKENS(unsorted,sorted_tokens,count);
			//gim_free(unsorted,0); //TODO remove TZ

		}

		//Arrays.sort(sorted_tokens, COMPARATOT_TZ); //TODO TZ remove

		if(calc_global_bound) gim_aabbset_calc_global_bound();
	}

//    private static final ComparatorTZ COMPARATOT_TZ = new ComparatorTZ();
//    private static final class ComparatorTZ implements Comparator<GIM_RSORT_TOKEN> {
////      private static int RSORT_TOKEN_COMPARATOR(GIM_RSORT_TOKEN x, GIM_RSORT_TOKEN y) { return x.m_key - y.m_key; }
////      interface GimRSortTokenComparator {
////          int run(GIM_RSORT_TOKEN x, GIM_RSORT_TOKEN y);
////      }
////      static final GimRSortTokenComparator RSORT_TOKEN_COMPARATOR = new GimRSortTokenComparator() {
////          @Override public int run(GIM_RSORT_TOKEN x, GIM_RSORT_TOKEN y) {
////              return RSORT_TOKEN_COMPARATOR(x, y);
////          }
////      };
//
//        @Override
//        public int compare(GIM_RSORT_TOKEN o1, GIM_RSORT_TOKEN o2) {
//            return (int) -(o1.m_key - o2.m_key);
//        }
//    };

	//utility macros

	/*#define PUSH_PAIR(i,j,pairset)\
	{\
	    GIM_PAIR _pair={i,j};\
	    GIM_DYNARRAY_PUSH_ITEM(GIM_PAIR,pairset,_pair);\
	}*/

	private interface PushPairMacro {
		void run(final int i, final int j, GimDynArray<GIM_PAIR> pairset);
	}
	private static final PushPairMacro PUSH_PAIR = new PushPairMacro() {
		@Override public void run(int i, int j, GimDynArray<GIM_PAIR> pairset) {
			PUSH_PAIR(i, j, pairset);
		}
	};
	private static final PushPairMacro PUSH_PAIR_INV = new PushPairMacro() {
		@Override public void run(int i, int j, GimDynArray<GIM_PAIR> pairset) {
			PUSH_PAIR_INV(i, j, pairset);
		}
	};

	//#define PUSH_PAIR(i,j,pairset)\
	static void PUSH_PAIR(final int i, final int j, GimDynArray<GIM_PAIR> pairset)
	{
		//		pairset.GIM_DYNARRAY_PUSH_EMPTY();
		//	    GIM_PAIR[] _pair = pairset.GIM_DYNARRAY_POINTER() + (pairset).m_size - 1;
		GIM_PAIR _pair = new GIM_PAIR();
		_pair.m_index1 = i;
		_pair.m_index2 = j;
		pairset.GIM_DYNARRAY_PUSH_ITEM_TZ(_pair);
	}

	//#define PUSH_PAIR_INV(i,j,pairset)\
	static void PUSH_PAIR_INV(final int i, final int j, GimDynArray<GIM_PAIR> pairset)
	{
		//		pairset.GIM_DYNARRAY_PUSH_EMPTY();
		//	    GIM_PAIR[] _pair = GIM_DYNARRAY_POINTER(GIM_PAIR,pairset) + (pairset).m_size - 1;
		GIM_PAIR _pair = new GIM_PAIR();
		_pair.m_index1 = j;
		_pair.m_index2 = i;
		pairset.GIM_DYNARRAY_PUSH_ITEM_TZ(_pair);
	}

	//	#define FIND_OVERLAPPING_FOWARD(\
	//	 curr_index,\
	//	 test_count,\
	//	 test_aabb,\
	//	 max_coord_uint,\
	//	 sorted_tokens,\
	//	 aabbarray,\
	//	 pairset,\
	//	 push_pair_macro)\
	static void FIND_OVERLAPPING_FOWARD(
			final int curr_index,
			final int test_count,
			final aabb3f test_aabb,
			final long max_coord_uint,
			final GIM_RSORT_TOKEN[] sorted_tokensA,
			final int sorted_tokensP,
			final aabb3f[] aabbarray,
			final GimDynArray<GIM_PAIR> pairset,
			final PushPairMacro push_pair_macro)
	{
		int _i = test_count;
		boolean _intersected;
		GIM_RSORT_TOKEN[] _psorted_tokensA = sorted_tokensA;
		int _psorted_tokensP = sorted_tokensP;
		while(_i>0 && max_coord_uint >= _psorted_tokensA[_psorted_tokensP].m_key)
		{
			_intersected = AABBCOLLISION(test_aabb,aabbarray[_psorted_tokensA[_psorted_tokensP].m_value]);
			if(_intersected)
			{
				push_pair_macro.run(curr_index, _psorted_tokensA[_psorted_tokensP].m_value,pairset);
			}
			_psorted_tokensP++;
			_i--;
		}
	}

	/**
	 * log(N) Bipartite box pruning. Returns a list of overlapping pairs of
	 * boxes, each box of the pair belongs to a different set.
	 * @pre aabbset1 and aabbset2 must be allocated and sorted, the boxes must be already set.
	 * @param aabbset1 Must be sorted, Global bound is required.
	 * @param aabbset2 Must be sorted, Global bound is required.
	 * @param collision_pairs Array of GIM_PAIR elements. Must be initialized before (Reserve size ~ 100)
	 */
	//void gim_aabbset_bipartite_intersections_sorted(GIM_AABB_SET * aabbset1,
	//GIM_AABB_SET * aabbset2, GDYNAMIC_ARRAY * collision_pairs)
	static void gim_aabbset_bipartite_intersections_sorted(
			final GimAABBSet aabbset1, final GimAABBSet aabbset2,
			final GimDynArray<GIM_PAIR> collision_pairs)
	{
		boolean intersected;
		collision_pairs.m_size = 0;

		intersected = AABBCOLLISION(aabbset1.m_global_bound,aabbset2.m_global_bound);
		if(intersected == false) return;

		int count1 = aabbset1.m_count;
		aabb3f[] paabb1 = aabbset1.m_boxes;
		long[] maxcoords1 = aabbset1.m_maxcoords;
		GIM_RSORT_TOKEN[] sorted_tokens1 = aabbset1.m_sorted_mincoords;

		int count2 = aabbset2.m_count;
		aabb3f[] paabb2 = aabbset2.m_boxes;
		long[] maxcoords2 = aabbset2.m_maxcoords;
		GIM_RSORT_TOKEN[] sorted_tokens2 = aabbset2.m_sorted_mincoords;

		int  curr_index;

		long max_coord_uint;
		aabb3f test_aabb = new aabb3f();

		//Classify boxes
		//Find  Set intersection
		aabb3f int_abbb = new aabb3f();
		BOXINTERSECTION(aabbset1.m_global_bound,aabbset2.m_global_bound, int_abbb);

		//Clasify set 1
		GIM_RSORT_TOKEN[] classified_tokens1 = new GIM_RSORT_TOKEN[count1];//(GIM_RSORT_TOKEN *) gim_alloc(sizeof(GIM_RSORT_TOKEN)*count1);
		int i,classified_count1 = 0,classified_count2 = 0;

		for (i=0;i<count1;i++ )
		{
			curr_index = sorted_tokens1[i].m_value;
			intersected = AABBCOLLISION(paabb1[curr_index],int_abbb);
			if(intersected)
			{
				classified_tokens1[classified_count1] = sorted_tokens1[i];
				classified_count1++;
			}
		}

		if(classified_count1==0)
		{
			//TODO remove TZ gim_free(classified_tokens1 ,0);
			return; // no pairs
		}

		//Clasify set 2
		//GIM_RSORT_TOKEN * classified_tokens2 = (GIM_RSORT_TOKEN *) gim_alloc(sizeof(GIM_RSORT_TOKEN)*count2);
		GIM_RSORT_TOKEN[] classified_tokens2 = new GIM_RSORT_TOKEN[count2];

		for (i=0;i<count2;i++ )
		{
			curr_index = sorted_tokens2[i].m_value;
			intersected = AABBCOLLISION(paabb2[curr_index],int_abbb);
			if(intersected)
			{
				classified_tokens2[classified_count2] = sorted_tokens2[i];
				classified_count2++;
			}
		}

		if(classified_count2==0)
		{
			//TODO remove TZ
			//	        gim_free(classified_tokens1 ,0);
			//	        gim_free(classified_tokens2 ,0);
			return; // no pairs
		}

		sorted_tokens1 = classified_tokens1;
		sorted_tokens2 = classified_tokens2;
		int pos1 = 0, pos2 = 0;

		while(classified_count1>0&&classified_count2>0)
		{
			if(sorted_tokens1[pos1].m_key <= sorted_tokens2[pos2].m_key)
			{
				///current cache variables
				curr_index = sorted_tokens1[pos1].m_value;
				max_coord_uint = maxcoords1[curr_index];
				AABB_COPY(test_aabb,paabb1[curr_index]);
				///next pairs
				pos1++;//sorted_tokens1++;
				classified_count1--;
				FIND_OVERLAPPING_FOWARD( curr_index, classified_count2, test_aabb,
						max_coord_uint, sorted_tokens2, 0 , paabb2, collision_pairs, PUSH_PAIR);
			}
			else ///Switch test
			{
				///current cache variables
				curr_index = sorted_tokens2[pos2].m_value;
				max_coord_uint = maxcoords2[curr_index];
				AABB_COPY(test_aabb,paabb2[curr_index]);
				///next pairs
				pos2++;//sorted_tokens2++;
				classified_count2--;
				FIND_OVERLAPPING_FOWARD( curr_index, classified_count1, test_aabb,
						max_coord_uint, sorted_tokens1, 0 , paabb1, collision_pairs, PUSH_PAIR_INV );
			}
		}
		//TODO TZ remove
		//	    gim_free(classified_tokens1 ,0);
		//	    gim_free(classified_tokens2 ,0);
	}

	/**
	 * NxM Bipartite box pruning. Returns a list of overlapping pairs of boxes,
	 * each box of the pair belongs to a different set.
	 * @pre aabbset1 and aabbset2 must be allocated and sorted, the boxes must be already set.
	 * @param aabbset1 Must be sorted, Global bound is required.
	 * @param aabbset2 Must be sorted, Global bound is required.
	 * @param collision_pairs Array of GIM_PAIR elements. Must be initialized before (Reserve size ~ 100)
	 */
	//void gim_aabbset_bipartite_intersections_brute_force(GIM_AABB_SET * aabbset1,GIM_AABB_SET * aabbset2, GDYNAMIC_ARRAY * collision_pairs)
	static void gim_aabbset_bipartite_intersections_brute_force(GimAABBSet aabbset1, GimAABBSet aabbset2,
			GimDynArray<GIM_PAIR> collision_pairs)
	{
		boolean intersected;
		collision_pairs.m_size = 0;
		intersected = AABBCOLLISION(aabbset1.m_global_bound,aabbset2.m_global_bound);
		if(intersected == false) return;

		aabb3f int_abbb = new aabb3f();
		//Find  Set intersection
		BOXINTERSECTION(aabbset1.m_global_bound,aabbset2.m_global_bound, int_abbb);
		//Clasify set 1
		int i,j;
		int classified_count = 0;

		int count = aabbset1.m_count;
		aabb3f[] paabb1 = aabbset1.m_boxes;
		aabb3f[] paabb2 = aabbset2.m_boxes;

		//GUINT32 * classified = (GUINT32 *) gim_alloc(sizeof(GUINT32)*count);
		int[] classified = new int[count];//(GUINT32 *) gim_alloc(sizeof(GUINT32)*count);

		for (i=0;i<count;i++ )
		{
			intersected = AABBCOLLISION(paabb1[i],int_abbb);
			if(intersected)
			{
				classified[classified_count] = i;
				classified_count++;
			}
		}

		if(classified_count==0)
		{
			//gim_free(classified,0); TODO TZ remove
			return; // no pairs
		}

		//intesect set2
		count = aabbset2.m_count;
		for (i=0;i<count;i++)
		{
			intersected = AABBCOLLISION(paabb2[i],int_abbb);
			if(intersected)
			{
				for (j=0;j<classified_count;j++)
				{
					intersected = AABBCOLLISION(paabb2[i],paabb1[classified[j]]);
					if(intersected)
					{
						PUSH_PAIR(classified[j],i,collision_pairs);
					}
				}
			}
		}
		//gim_free(classified,0); TODO TZ remove
	}

	//Use these functions for general initialization

	/**
	 * Initalizes the set. Sort Boxes if needed.
	 * @pre aabbset must be allocated. And the boxes must be already set.
	 * @post If the set has less of GIM_MIN_SORTED_BIPARTITE_PRUNING_BOXES boxes, only calcs the global box,
	 * else it Sorts the entire set( Only applicable for large sets)
	 */
	//void gim_aabbset_update(GIM_AABB_SET * aabbset)
	void gim_aabbset_update()
	{
		if(m_count < GIM_MIN_SORTED_BIPARTITE_PRUNING_BOXES)  //TODO TZ check this!!! Performance!
		{//Brute force approach
			gim_aabbset_calc_global_bound();
		}
		else
		{//Sorted force approach
			gim_aabbset_sort(true);
		}
	}

	///Use these functions for general collision

	/**
	 * Collides two sets. Returns a list of overlapping pairs of boxes, each box of the pair belongs to a different set.
	 * @pre aabbset1 and aabbset2 must be allocated and updated. See gim_aabbset_update.
	 * @param aabbset1 Must be sorted, Global bound is required.
	 * @param aabbset2 Must be sorted, Global bound is required.
	 * @param collision_pairs Array of GIM_PAIR elements. Must be initialized before (Reserve size ~ 100)
	 */
	//void gim_aabbset_bipartite_intersections(GIM_AABB_SET * aabbset1, GIM_AABB_SET * aabbset2, GDYNAMIC_ARRAY * collision_pairs)
	static void gim_aabbset_bipartite_intersections(GimAABBSet aabbset1,
			GimAABBSet aabbset2, GimDynArray<GIM_PAIR> collision_pairs)
	{
		if(aabbset1.m_sorted_mincoords == null||aabbset2.m_sorted_mincoords == null)
		{//Brute force approach
			gim_aabbset_bipartite_intersections_brute_force(aabbset1,aabbset2,collision_pairs);
		}
		else
		{//Sorted force approach
			gim_aabbset_bipartite_intersections_sorted(aabbset1,aabbset2,collision_pairs);
		}
//		System.out.println("IGNORED!");//TODO fix this!
	}

	/**
	 * Finds intersections between a box and a set. Return the colliding boxes of the set
	 * @pre aabbset must be allocated and initialized.
	 * @param test_aabb Box for collision query
	 * @param collided Array of GUINT elements, indices of boxes. Must be initialized before (Reserve size ~ 100)
	 */
	//* @param aabbset Set of boxes .Global bound is required.
	//void gim_aabbset_box_collision(aabb3f *test_aabb, GIM_AABB_SET * aabbset, GDYNAMIC_ARRAY * collided)
	public void gim_aabbset_box_collision(aabb3f test_aabb, GimDynArrayInt collided)
	{
		collided.m_size = 0;
		boolean intersected = GimGeometry.AABBCOLLISION(m_global_bound,test_aabb);
		if(intersected == false) return;

		int i;
		int count = m_count;
		aabb3f[] paabb = m_boxes;
		aabb3f _testaabb = new aabb3f();
		GimGeometry.AABB_COPY(_testaabb,test_aabb);

		for (i=0;i< count;i++ )
		{
			intersected = GimGeometry.AABBCOLLISION(paabb[i],_testaabb);
			if(intersected)
			{
				collided.GIM_DYNARRAY_PUSH_ITEM(i);
			}
		}
	}

	/**
	 * Finds intersections between a box and a set. Return the colliding boxes of the set
	 * @pre aabbset must be allocated and initialized.
	 * @param vorigin Origin point of ray.
	 * @param vdir Direction vector of ray.
	 * @param tmax Max distance param for ray.
	 * @param aabbset Set of boxes .Global bound is required.
	 * @param collided Array of GUINT elements, indices of boxes. Must be initialized before (Reserve size ~ 100)
	 */
	//void gim_aabbset_ray_collision(vec3f vorigin,vec3f vdir, GREAL tmax, GIM_AABB_SET * aabbset, GDYNAMIC_ARRAY * collided)
	void gim_aabbset_ray_collision(vec3f vorigin,vec3f vdir, float tmax,
			GimDynArrayInt collided)
	{
		collided.m_size = 0;
		RefBoolean intersected = new RefBoolean(false);
		RefFloat tparam = new RefFloat();
		GimGeometry.BOX_INTERSECTS_RAY(m_global_bound, vorigin, vdir, tparam, tmax,intersected);
		if(intersected.b==false) return;

		int i;
		int count = m_count;
		aabb3f[] paabb = m_boxes;

		for (i=0;i< count;i++ )
		{
			GimGeometry.BOX_INTERSECTS_RAY(paabb[i], vorigin, vdir, tparam, tmax,intersected);
			if(intersected.b)
			{
				collided.GIM_DYNARRAY_PUSH_ITEM(i);//GUINT32,(collided),i);
			}
		}
	}

	public aabb3f at(int i) {
		return m_boxes[i];
	}
}


text:
package org.deeplearning4j.iterator.bert;

import org.nd4j.linalg.primitives.Pair;

import java.util.List;

/**
 * Interface used to customize how masking should be performed with {@link org.deeplearning4j.iterator.BertIterator}
 * when doing unsupervised training
 *
 * @author Alex Black
 */
public interface BertSequenceMasker {

    /**
     *
     * @param input         Input sequence of tokens
     * @param maskToken     Token to use for masking - usually something like "[MASK]"
     * @param vocabWords    Vocabulary, as a list
     * @return Pair: The new input tokens (after masking out), along with a boolean[] for whether the token is
     * masked or not (same length as number of tokens). boolean[i] is true if token i was masked.
     */
    Pair<List<String>,boolean[]> maskSequence(List<String> input, String maskToken, List<String> vocabWords);

}


text:
#ifndef EVENTS_H
#define EVENTS_H

typedef void (feh_event_handler) (XEvent * ev);

extern feh_event_handler *ev_handler[];

void feh_event_init(void);

#endif