text:
import decimal
import io
from contextlib import redirect_stdout
from operator import and_, invert, lshift, neg, or_, rshift, xor

import numpy as np
import pandas as pd
import pytest
import toolz
from pytest import param

import ibis
import ibis.common.exceptions as com
from ibis import _
from ibis import literal as L

@pytest.mark.parametrize(
    ('expr', 'expected'),
    [
        param(
            ibis.NA.fillna(5), 5, marks=pytest.mark.notimpl(["mssql"]), id="na_fillna"
        ),
        param(
            L(5).fillna(10), 5, marks=pytest.mark.notimpl(["mssql"]), id="non_na_fillna"
        ),
        param(L(5).nullif(5), None, id="nullif_null"),
        param(L(10).nullif(5), 10, id="nullif_not_null"),
    ],
)
@pytest.mark.notimpl(["datafusion"])
def test_scalar_fillna_nullif(con, expr, expected):
    if expected is None:
        # The exact kind of null value used differs per backend (and version).
        # Example 1: Pandas returns np.nan while BigQuery returns None.
        # Example 2: PySpark returns np.nan if pyspark==3.0.0, but returns None
        # if pyspark <=3.0.0.
        # TODO: Make this behavior consistent (#2365)
        assert pd.isna(con.execute(expr))
    else:
        assert con.execute(expr) == expected

na_none_cols = pytest.mark.parametrize(
    "col",
    [
        param(
            "na_col",
            marks=pytest.mark.notimpl(["datafusion", "mysql", "sqlite"]),
            id="na_col",
        ),
        param(
            "none_col",
            marks=[
                pytest.mark.notimpl(
                    [
                        "clickhouse",
                        "datafusion",
                        "impala",
                        "mysql",
                        "postgres",
                        "sqlite",
                        "snowflake",
                        "polars",
                    ]
                ),
                pytest.mark.notyet(["duckdb"], reason="non-finite value support"),
            ],
            id="none_col",
        ),
    ],
)

@na_none_cols
@pytest.mark.notimpl(["mssql"])
def test_isna(backend, alltypes, col):
    table = alltypes.mutate(na_col=np.nan)
    table = table.mutate(none_col=None)
    table = table.mutate(none_col=table['none_col'].cast('float64'))
    table_pandas = table.execute()

    result = table[table[col].isnan()].execute().reset_index(drop=True)
    expected = table_pandas[table_pandas[col].isna()].reset_index(drop=True)

    backend.assert_frame_equal(result, expected)

@pytest.mark.parametrize(
    "value",
    [
        None,
        param(
            np.nan,
            marks=pytest.mark.notimpl(
                [
                    "clickhouse",
                    "duckdb",
                    "impala",
                    "postgres",
                    "mysql",
                    "snowflake",
                    "polars",
                ],
                reason="NaN != NULL for these backends",
            ),
        ),
    ],
)
@pytest.mark.notimpl(["datafusion", "mssql"])
def test_column_fillna(backend, alltypes, value):
    table = alltypes.mutate(missing=ibis.literal(value).cast("float64"))
    pd_table = table.execute()

    res = table.mutate(missing=table.missing.fillna(0.0)).execute()
    sol = pd_table.assign(missing=pd_table.missing.fillna(0.0))
    backend.assert_frame_equal(res.reset_index(drop=True), sol.reset_index(drop=True))

@pytest.mark.parametrize(
    ('expr', 'expected'),
    [
        param(ibis.coalesce(5, None, 4), 5, id="generic"),
        param(ibis.coalesce(ibis.NA, 4, ibis.NA), 4, id="null_start_end"),
        param(
            ibis.coalesce(ibis.NA, ibis.NA, 3.14),
            3.14,
            id="non_null_last",
            marks=pytest.mark.broken(
                "polars",
                reason="implementation error, cannot get ref Int8 from Float64",
            ),
        ),
    ],
)
@pytest.mark.notimpl(["datafusion"])
def test_coalesce(con, expr, expected):
    result = con.execute(expr)

    if isinstance(result, decimal.Decimal):
        # in case of Impala the result is decimal
        # >>> decimal.Decimal('5.56') == 5.56
        # False
        assert result == decimal.Decimal(str(expected))
    else:
        assert result == pytest.approx(expected)

# TODO(dask) - identicalTo - #2553
@pytest.mark.notimpl(["clickhouse", "datafusion", "polars", "dask", "pyspark", "mssql"])
def test_identical_to(backend, alltypes, sorted_df):
    sorted_alltypes = alltypes.order_by('id')
    df = sorted_df
    dt = df[['tinyint_col', 'double_col']]

    ident = sorted_alltypes.tinyint_col.identical_to(sorted_alltypes.double_col)
    expr = sorted_alltypes['id', ident.name('tmp')].order_by('id')
    result = expr.execute().tmp

    expected = (dt.tinyint_col.isnull() & dt.double_col.isnull()) | (
        dt.tinyint_col == dt.double_col
    )

    expected = backend.default_series_rename(expected)
    backend.assert_series_equal(result, expected)

@pytest.mark.parametrize(
    ('column', 'elements'),
    [
        ('int_col', [1, 2, 3]),
        ('int_col', (1, 2, 3)),
        ('string_col', ['1', '2', '3']),
        ('string_col', ('1', '2', '3')),
        ('int_col', {1}),
        ('int_col', frozenset({1})),
    ],
)
@pytest.mark.notimpl(["mssql"])
def test_isin(backend, alltypes, sorted_df, column, elements):
    sorted_alltypes = alltypes.order_by('id')
    expr = sorted_alltypes[
        'id', sorted_alltypes[column].isin(elements).name('tmp')
    ].order_by('id')
    result = expr.execute().tmp

    expected = sorted_df[column].isin(elements)
    expected = backend.default_series_rename(expected)
    backend.assert_series_equal(result, expected)

@pytest.mark.parametrize(
    ('column', 'elements'),
    [
        ('int_col', [1, 2, 3]),
        ('int_col', (1, 2, 3)),
        ('string_col', ['1', '2', '3']),
        ('string_col', ('1', '2', '3')),
        ('int_col', {1}),
        ('int_col', frozenset({1})),
    ],
)
@pytest.mark.notimpl(["mssql"])
def test_notin(backend, alltypes, sorted_df, column, elements):
    sorted_alltypes = alltypes.order_by('id')
    expr = sorted_alltypes[
        'id', sorted_alltypes[column].notin(elements).name('tmp')
    ].order_by('id')
    result = expr.execute().tmp

    expected = ~sorted_df[column].isin(elements)
    expected = backend.default_series_rename(expected)
    backend.assert_series_equal(result, expected)

@pytest.mark.parametrize(
    ('predicate_fn', 'expected_fn'),
    [
        param(
            lambda t: t['bool_col'],
            lambda df: df['bool_col'],
            id="no_op",
            marks=pytest.mark.min_version(datafusion="0.5.0"),
        ),
        param(lambda t: ~t['bool_col'], lambda df: ~df['bool_col'], id="negate"),
        param(
            lambda t: t.bool_col & t.bool_col,
            lambda df: df.bool_col & df.bool_col,
            id="and",
        ),
        param(
            lambda t: t.bool_col | t.bool_col,
            lambda df: df.bool_col | df.bool_col,
            id="or",
        ),
        param(
            lambda t: t.bool_col ^ t.bool_col,
            lambda df: df.bool_col ^ df.bool_col,
            id="xor",
            marks=pytest.mark.notimpl(["datafusion"]),
        ),
    ],
)
def test_filter(backend, alltypes, sorted_df, predicate_fn, expected_fn):
    sorted_alltypes = alltypes.order_by('id')
    table = sorted_alltypes[predicate_fn(sorted_alltypes)].order_by('id')
    result = table.execute()
    expected = sorted_df[expected_fn(sorted_df)]

    backend.assert_frame_equal(result, expected)

@pytest.mark.notimpl(
    [
        "clickhouse",
        "datafusion",
        "duckdb",
        "impala",
        "mysql",
        "postgres",
        "sqlite",
        "snowflake",
        "polars",
        "mssql",
    ]
)
def test_filter_with_window_op(backend, alltypes, sorted_df):
    sorted_alltypes = alltypes.order_by('id')
    table = sorted_alltypes
    window = ibis.window(group_by=table.id)
    table = table.filter(lambda t: t['id'].mean().over(window) > 3).order_by('id')
    result = table.execute()
    expected = (
        sorted_df.groupby(['id'])
        .filter(lambda t: t['id'].mean() > 3)
        .reset_index(drop=True)
    )
    backend.assert_frame_equal(result, expected)

@pytest.mark.notimpl(["datafusion"])
def test_case_where(backend, alltypes, df):
    table = alltypes
    table = table.mutate(
        new_col=(
            ibis.case()
            .when(table['int_col'] == 1, 20)
            .when(table['int_col'] == 0, 10)
            .else_(0)
            .end()
            .cast('int64')
        )
    )

    result = table.execute()

    expected = df.copy()
    mask_0 = expected['int_col'] == 1
    mask_1 = expected['int_col'] == 0

    expected['new_col'] = 0
    expected.loc[mask_0, 'new_col'] = 20
    expected.loc[mask_1, 'new_col'] = 10

    backend.assert_frame_equal(result, expected)

# TODO: some of these are notimpl (datafusion) others are probably never
@pytest.mark.notimpl(["datafusion", "mysql", "sqlite", "mssql"])
@pytest.mark.min_version(duckdb="0.3.3", reason="isnan/isinf unsupported")
def test_select_filter_mutate(backend, alltypes, df):
    """Test that select, filter and mutate are executed in right order.

    Before PR #2635, try_fusion in analysis.py would fuse these
    operations together in a way that the order of the operations were
    wrong. (mutate was executed before filter).
    """
    t = alltypes

    # Prepare the float_col so that filter must execute
    # before the cast to get the correct result.
    t = t.mutate(
        float_col=ibis.case().when(t['bool_col'], t['float_col']).else_(np.nan).end()
    )

    # Actual test
    t = t[t.columns]
    t = t[~t['float_col'].isnan()]
    t = t.mutate(float_col=t['float_col'].cast('float64'))
    result = t.execute()

    expected = df.copy()
    expected.loc[~df['bool_col'], 'float_col'] = None
    expected = expected[~expected['float_col'].isna()].reset_index(drop=True)
    expected = expected.assign(float_col=expected['float_col'].astype('float64'))

    backend.assert_series_equal(result.float_col, expected.float_col)

def test_table_fillna_invalid(alltypes):
    with pytest.raises(com.IbisTypeError, match=r"'invalid_col' is not a field in.*"):
        alltypes.fillna({'invalid_col': 0.0})

    with pytest.raises(
        com.IbisTypeError, match="Cannot fillna on column 'string_col' of type.*"
    ):
        alltypes[["int_col", "string_col"]].fillna(0)

    with pytest.raises(
        com.IbisTypeError, match="Cannot fillna on column 'int_col' of type.*"
    ):
        alltypes.fillna({"int_col": "oops"})

@pytest.mark.parametrize(
    "replacements",
    [
        {"int_col": 20},
        {"double_col": -1, "string_col": "missing"},
        {"double_col": -1.5, "string_col": "missing"},
    ],
)
@pytest.mark.notimpl(["datafusion", "mssql"])
def test_table_fillna_mapping(backend, alltypes, replacements):
    table = alltypes.mutate(
        int_col=alltypes.int_col.nullif(1),
        double_col=alltypes.double_col.nullif(3.0),
        string_col=alltypes.string_col.nullif("2"),
    ).select("id", "int_col", "double_col", "string_col")
    pd_table = table.execute()

    result = table.fillna(replacements).execute().reset_index(drop=True)
    expected = pd_table.fillna(replacements).reset_index(drop=True)

    backend.assert_frame_equal(result, expected, check_dtype=False)

@pytest.mark.notimpl(["datafusion", "mssql"])
def test_table_fillna_scalar(backend, alltypes):
    table = alltypes.mutate(
        int_col=alltypes.int_col.nullif(1),
        double_col=alltypes.double_col.nullif(3.0),
        string_col=alltypes.string_col.nullif("2"),
    ).select("id", "int_col", "double_col", "string_col")
    pd_table = table.execute()

    res = table[["int_col", "double_col"]].fillna(0).execute().reset_index(drop=True)
    sol = pd_table[["int_col", "double_col"]].fillna(0).reset_index(drop=True)
    backend.assert_frame_equal(res, sol, check_dtype=False)

    res = table[["string_col"]].fillna("missing").execute().reset_index(drop=True)
    sol = pd_table[["string_col"]].fillna("missing").reset_index(drop=True)
    backend.assert_frame_equal(res, sol, check_dtype=False)

def test_mutate_rename(alltypes):
    table = alltypes.select(["bool_col", "string_col"])
    table = table.mutate(dupe_col=table["bool_col"])
    result = table.execute()
    # check_dtype is False here because there are dtype diffs between
    # Pyspark and Pandas on Java 8 - filling the 'none_col' with an int
    # results in float in Pyspark, and int in Pandas. This diff does
    # not exist in Java 11.
    assert list(result.columns) == ["bool_col", "string_col", "dupe_col"]

def test_dropna_invalid(alltypes):
    with pytest.raises(com.IbisTypeError, match=r"'invalid_col' is not a field in.*"):
        alltypes.dropna(subset=['invalid_col'])

    with pytest.raises(ValueError, match=r".*is not in.*"):
        alltypes.dropna(how='invalid')

@pytest.mark.parametrize(
    'how', ['any', pytest.param('all', marks=pytest.mark.notyet("polars"))]
)
@pytest.mark.parametrize(
    'subset', [None, [], 'col_1', ['col_1', 'col_2'], ['col_1', 'col_3']]
)
@pytest.mark.notimpl(["datafusion"])
def test_dropna_table(backend, alltypes, how, subset):
    is_two = alltypes.int_col == 2
    is_four = alltypes.int_col == 4

    table = alltypes.mutate(
        col_1=is_two.ifelse(ibis.NA, alltypes.float_col),
        col_2=is_four.ifelse(ibis.NA, alltypes.float_col),
        col_3=(is_two | is_four).ifelse(ibis.NA, alltypes.float_col),
    ).select("col_1", "col_2", "col_3")

    table_pandas = table.execute()

    result = table.dropna(subset, how).execute().reset_index(drop=True)
    expected = table_pandas.dropna(how=how, subset=subset).reset_index(drop=True)

    backend.assert_frame_equal(result, expected)

def test_select_sort_sort(alltypes):
    query = alltypes[alltypes.year, alltypes.bool_col]
    query = query.order_by(query.year).order_by(query.bool_col)

@pytest.mark.parametrize(
    "key, df_kwargs",
    [
        param("id", {"by": "id"}),
        param(_.id, {"by": "id"}),
        param(lambda _: _.id, {"by": "id"}),
        param(
            ("id", False),
            {"by": "id", "ascending": False},
            marks=pytest.mark.notimpl(["dask"]),
        ),
        param(
            ibis.desc("id"),
            {"by": "id", "ascending": False},
            marks=pytest.mark.notimpl(["dask"]),
        ),
        param(
            ["id", "int_col"],
            {"by": ["id", "int_col"]},
            marks=pytest.mark.notimpl(["dask"]),
        ),
        param(
            ["id", ("int_col", False)],
            {"by": ["id", "int_col"], "ascending": [True, False]},
            marks=pytest.mark.notimpl(["dask"]),
        ),
    ],
)
def test_order_by(backend, alltypes, df, key, df_kwargs):
    result = alltypes.filter(_.id < 100).order_by(key).execute()
    expected = df.loc[df.id < 100].sort_values(**df_kwargs)
    backend.assert_frame_equal(result, expected)

@pytest.mark.notimpl(["dask", "datafusion", "impala", "pandas", "polars", "mssql"])
@pytest.mark.notyet(
    ["clickhouse"],
    reason="clickhouse doesn't have a [0.0, 1.0) random implementation",
)
def test_order_by_random(alltypes):
    expr = alltypes.filter(_.id < 100).order_by(ibis.random()).limit(5)
    r1 = expr.execute()
    r2 = expr.execute()
    assert len(r1) == 5
    assert len(r2) == 5
    # Ensure that multiple executions returns different results
    assert not r1.equals(r2)

def check_table_info(buf, schema):
    info_str = buf.getvalue()

    assert "Null" in info_str
    assert all(type.__class__.__name__ in info_str for type in schema.types)
    assert all(name in info_str for name in schema.names)

def test_table_info_buf(alltypes):
    buf = io.StringIO()
    alltypes.info(buf=buf)
    check_table_info(buf, alltypes.schema())

def test_table_info_no_buf(alltypes):
    buf = io.StringIO()
    with redirect_stdout(buf):
        alltypes.info()
    check_table_info(buf, alltypes.schema())

@pytest.mark.parametrize(
    ("ibis_op", "pandas_op"),
    [
        param(
            _.string_col.isin([]),
            lambda df: df.string_col.isin([]),
            id="isin",
        ),
        param(
            _.string_col.notin([]),
            lambda df: ~df.string_col.isin([]),
            id="notin",
        ),
        param(
            (_.string_col.length() * 1).isin([1]),
            lambda df: (df.string_col.str.len() * 1).isin([1]),
            id="isin_non_empty",
        ),
        param(
            (_.string_col.length() * 1).notin([1]),
            lambda df: ~(df.string_col.str.len() * 1).isin([1]),
            id="notin_non_empty",
        ),
    ],
)
def test_isin_notin(backend, alltypes, df, ibis_op, pandas_op):
    expr = alltypes[ibis_op]
    expected = df.loc[pandas_op(df)].sort_values(["id"]).reset_index(drop=True)
    result = expr.execute().sort_values(["id"]).reset_index(drop=True)
    backend.assert_frame_equal(result, expected)

@pytest.mark.notyet(
    ["dask"],
    reason="dask doesn't support Series as isin/notin argument",
    raises=NotImplementedError,
)
@pytest.mark.notimpl(["datafusion"])
@pytest.mark.parametrize(
    ("ibis_op", "pandas_op"),
    [
        param(
            _.string_col.isin(_.string_col),
            lambda df: df.string_col.isin(df.string_col),
            id="isin_col",
        ),
        param(
            (_.bigint_col + 1).isin(_.string_col.length() + 1),
            lambda df: df.bigint_col.add(1).isin(df.string_col.str.len().add(1)),
            id="isin_expr",
        ),
        param(
            _.string_col.notin(_.string_col),
            lambda df: ~df.string_col.isin(df.string_col),
            id="notin_col",
        ),
        param(
            (_.bigint_col + 1).notin(_.string_col.length() + 1),
            lambda df: ~(df.bigint_col.add(1)).isin(df.string_col.str.len().add(1)),
            id="notin_expr",
        ),
    ],
)
def test_isin_notin_column_expr(backend, alltypes, df, ibis_op, pandas_op):
    expr = alltypes[ibis_op].order_by("id")
    expected = df[pandas_op(df)].sort_values(["id"]).reset_index(drop=True)
    result = expr.execute()
    backend.assert_frame_equal(result, expected)

@pytest.mark.parametrize(
    ("expr", "expected", "op"),
    [
        param(True, True, toolz.identity, id="true_noop"),
        param(False, False, toolz.identity, id="false_noop"),
        param(
            True, False, invert, id="true_invert", marks=pytest.mark.notimpl(["mssql"])
        ),
        param(
            False, True, invert, id="false_invert", marks=pytest.mark.notimpl(["mssql"])
        ),
        param(True, False, neg, id="true_negate", marks=pytest.mark.notimpl(["mssql"])),
        param(
            False, True, neg, id="false_negate", marks=pytest.mark.notimpl(["mssql"])
        ),
    ],
)
def test_logical_negation_literal(con, expr, expected, op):
    assert con.execute(op(ibis.literal(expr))) == expected

@pytest.mark.parametrize(
    "op",
    [
        toolz.identity,
        param(invert, marks=pytest.mark.notimpl(["mssql"])),
        param(neg, marks=pytest.mark.notimpl(["mssql"])),
    ],
)
def test_logical_negation_column(backend, alltypes, df, op):
    result = op(alltypes["bool_col"]).execute()
    expected = op(df["bool_col"])
    backend.assert_series_equal(result, expected, check_names=False)

@pytest.mark.notimpl(["datafusion"])
@pytest.mark.parametrize(
    ("dtype", "zero", "expected"),
    [("int64", 0, 1), ("float64", 0.0, 1.0)],
)
def test_zeroifnull_literals(con, dtype, zero, expected):
    assert con.execute(ibis.NA.cast(dtype).zeroifnull()) == zero
    assert con.execute(ibis.literal(expected, type=dtype).zeroifnull()) == expected

@pytest.mark.notimpl(["datafusion"])
@pytest.mark.min_version(
    dask="2022.01.1",
    reason="unsupported operation with later versions of pandas",
)
def test_zeroifnull_column(backend, alltypes, df):
    expr = alltypes.int_col.nullif(1).zeroifnull().name('tmp')
    result = expr.execute().astype("int32")
    expected = df.int_col.replace(1, 0).rename("tmp").astype("int32")
    backend.assert_series_equal(result, expected)

@pytest.mark.notimpl(["datafusion"])
def test_where_select(backend, alltypes, df):
    table = alltypes
    table = table.select(
        [
            "int_col",
            (ibis.where(table["int_col"] == 0, 42, -1).cast("int64").name("where_col")),
        ]
    )

    result = table.execute()

    expected = df.loc[:, ["int_col"]].copy()

    expected['where_col'] = -1
    expected.loc[expected['int_col'] == 0, 'where_col'] = 42

    backend.assert_frame_equal(result, expected)

@pytest.mark.notimpl(["datafusion"])
def test_where_column(backend, alltypes, df):
    expr = ibis.where(alltypes["int_col"] == 0, 42, -1).cast("int64").name("where_col")
    result = expr.execute()

    expected = pd.Series(
        np.where(df.int_col == 0, 42, -1),
        name="where_col",
        dtype="int64",
    )

    backend.assert_series_equal(result, expected)

def test_select_filter(backend, alltypes, df):
    t = alltypes

    expr = t.select("int_col").filter(t.string_col == "4")
    result = expr.execute()

    expected = df.loc[df.string_col == "4", ["int_col"]].reset_index(drop=True)
    backend.assert_frame_equal(result, expected)

def test_select_filter_select(backend, alltypes, df):
    t = alltypes
    expr = t.select("int_col").filter(t.string_col == "4").int_col
    result = expr.execute().rename("int_col")

    expected = df.loc[df.string_col == "4", "int_col"].reset_index(drop=True)
    backend.assert_series_equal(result, expected)

pyspark_no_bitshift = pytest.mark.notyet(
    ["pyspark"], reason="pyspark doesn't implement bitshit operators"
)

@pytest.mark.parametrize("op", [and_, or_, xor])
@pytest.mark.parametrize(
    ("left_fn", "right_fn"),
    [
        param(lambda t: t.int_col, lambda t: t.int_col, id="col_col"),
        param(lambda _: 3, lambda t: t.int_col, id="scalar_col"),
        param(lambda t: t.int_col, lambda _: 3, id="col_scalar"),
    ],
)
@pytest.mark.notimpl(["dask", "datafusion", "pandas", "snowflake"])
def test_bitwise_columns(backend, con, alltypes, df, op, left_fn, right_fn):
    expr = op(left_fn(alltypes), right_fn(alltypes)).name("tmp")
    result = con.execute(expr)

    expected = op(left_fn(df), right_fn(df)).rename("tmp")
    backend.assert_series_equal(result, expected)

@pytest.mark.parametrize(
    ("op", "left_fn", "right_fn"),
    [
        param(
            lshift,
            lambda t: t.int_col,
            lambda t: t.int_col,
            id="lshift_col_col",
        ),
        param(
            lshift,
            lambda _: 3,
            lambda t: t.int_col,
            marks=pytest.mark.broken(
                ["impala"],
                reason="impala's behavior differs from every other backend",
            ),
            id="lshift_scalar_col",
        ),
        param(lshift, lambda t: t.int_col, lambda _: 3, id="lshift_col_scalar"),
        param(rshift, lambda t: t.int_col, lambda t: t.int_col, id="rshift_col_col"),
        param(rshift, lambda _: 3, lambda t: t.int_col, id="rshift_scalar_col"),
        param(rshift, lambda t: t.int_col, lambda _: 3, id="rshift_col_scalar"),
    ],
)
@pytest.mark.notimpl(["dask", "datafusion", "pandas"])
@pyspark_no_bitshift
def test_bitwise_shift(backend, alltypes, df, op, left_fn, right_fn):
    expr = op(left_fn(alltypes), right_fn(alltypes)).name("tmp")
    result = expr.execute()

    pandas_left = getattr(left := left_fn(df), "values", left)
    pandas_right = getattr(right := right_fn(df), "values", right)
    expected = pd.Series(
        op(pandas_left, pandas_right),
        name="tmp",
        dtype="int64",
    )
    backend.assert_series_equal(result, expected)

@pytest.mark.parametrize(
    "op",
    [
        param(and_, marks=[pytest.mark.notimpl(["snowflake"])]),
        param(or_, marks=[pytest.mark.notimpl(["snowflake"])]),
        param(xor, marks=[pytest.mark.notimpl(["snowflake"])]),
        param(lshift, marks=pyspark_no_bitshift),
        param(rshift, marks=pyspark_no_bitshift),
    ],
)
@pytest.mark.parametrize(
    ("left", "right"),
    [param(4, L(2), id="int_col"), param(L(4), 2, id="col_int")],
)
@pytest.mark.notimpl(["dask", "datafusion", "pandas"])
def test_bitwise_scalars(con, op, left, right):
    expr = op(left, right)
    result = con.execute(expr)
    expected = op(4, 2)
    assert result == expected

@pytest.mark.notimpl(["dask", "datafusion", "pandas", "snowflake"])
def test_bitwise_not_scalar(con):
    expr = ~L(2)
    result = con.execute(expr)
    expected = -3
    assert result == expected

@pytest.mark.notimpl(["dask", "datafusion", "pandas", "snowflake"])
def test_bitwise_not_col(backend, alltypes, df):
    expr = (~alltypes.int_col).name("tmp")
    result = expr.execute()
    expected = ~df.int_col
    backend.assert_series_equal(result, expected.rename("tmp"))

@pytest.mark.notimpl(
    ["snowflake"], reason="snowflake doesn't implement timestamp subtraction"
)
def test_interactive(alltypes):
    expr = alltypes.mutate(
        str_col=_.string_col.replace("1", "").nullif("2"),
        date_col=_.timestamp_col.date(),
        delta_col=lambda t: ibis.now() - t.timestamp_col,
    )

    orig = ibis.options.interactive
    ibis.options.interactive = True
    try:
        repr(expr)
    finally:
        ibis.options.interactive = orig

def test_correlated_subquery(alltypes):
    expr = alltypes[_.double_col > _.view().double_col]
    assert expr.compile() is not None


text:
[jQuery](http://jquery.com/) - New Wave JavaScript
==================================================

Contribution Guides
--------------------------------------

In the spirit of open source software development, jQuery always encourages community code contribution. To help you get started and before you jump into writing code, be sure to read these important contribution guidelines thoroughly:

1. [Getting Involved](http://docs.jquery.com/Getting_Involved)
2. [Core Style Guide](http://docs.jquery.com/JQuery_Core_Style_Guidelines)
3. [Tips For Bug Patching](http://docs.jquery.com/Tips_for_jQuery_Bug_Patching)

What you need to build your own jQuery
--------------------------------------

In order to build jQuery, you need to have GNU make 3.8 or later, Node.js/npm latest, and git 1.7 or later.
(Earlier versions might work OK, but are not tested.)

Windows users have two options:

1. Install [msysgit](https://code.google.com/p/msysgit/) (Full installer for official Git),
   [GNU make for Windows](http://gnuwin32.sourceforge.net/packages/make.htm), and a
   [binary version of Node.js](http://node-js.prcn.co.cc/). Make sure all three packages are installed to the same
   location (by default, this is C:\Program Files\Git).
2. Install [Cygwin](http://cygwin.com/) (make sure you install the git, make, and which packages), then either follow
   the [Node.js build instructions](https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-%28Windows%29) or install
   the [binary version of Node.js](http://node-js.prcn.co.cc/).

Mac OS users should install Xcode (comes on your Mac OS install DVD, or downloadable from
[Apple's Xcode site](http://developer.apple.com/technologies/xcode.html)) and
[http://mxcl.github.com/homebrew/](Homebrew). Once Homebrew is installed, run `brew install git` to install git,
and `brew install node` to install Node.js.

Linux/BSD users should use their appropriate package managers to install make, git, and node, or build from source
if you swing that way. Easy-peasy.

How to build your own jQuery
----------------------------

First, clone a copy of the main jQuery git repo by running:

```bash
git clone git://github.com/jquery/jquery.git
```

Enter the directory and install the node dependencies:

```bash
cd jquery && npm install
```

Make sure you have `grunt` installed by testing:

```bash
grunt -version
```

Then, to get a complete, minified (w/ Uglify.js), linted (w/ JSHint) version of jQuery, type the following:

```bash
grunt
```

The built version of jQuery will be put in the `dist/` subdirectory.

### Modules (new in 1.8)

Starting in jQuery 1.8, special builds can now be created that optionally exclude or include any of the following modules:

- ajax
- css
- dimensions
- effects
- offset

To create a custom build, use the following special `grunt` commands:

Exclude **ajax**:

```bash
grunt custom:-ajax
```

Exclude **css**:

```bash
grunt custom:-css
```

Exclude **dimensions**:

```bash
grunt custom:-dimensions
```

Exclude **effects**:

```bash
grunt custom:-effects
```

Exclude **offset**:

```bash
grunt custom:-offset
```

Exclude **all** optional modules:

```bash
grunt custom:-ajax,-css,-dimensions,-effects,-offset
```

Note: dependencies will be handled internally, by the build process.

Running the Unit Tests
--------------------------------------

Start grunt to auto-build jQuery as you work:

```bash
cd jquery && grunt watch
```

Run the unit tests with a local server that supports PHP. No database is required. Pre-configured php local servers are available for Windows and Mac. Here are some options:

- Windows: [WAMP download](http://www.wampserver.com/en/)
- Mac: [MAMP download](http://www.mamp.info/en/index.html)
- Linux: [Setting up LAMP](https://www.linux.com/learn/tutorials/288158-easy-lamp-server-installation)
- [Mongoose (most platforms)](http://code.google.com/p/mongoose/)

Building to a different directory
---------------------------------

If you want to build jQuery to a directory that is different from the default location:

```bash
grunt && grunt dist:/path/to/special/location/
```
With this example, the output files would be:

```bash
/path/to/special/location/jquery.js
/path/to/special/location/jquery.min.js
```

If you want to add a permanent copy destination, create a file in `dist/` called ".destination.json". Inside the file, paste and customize the following:

```json

{
  "/Absolute/path/to/other/destination": true
}
```

Additionally, both methods can be combined.

Updating Submodules
-------------------

Update the submodules to what is probably the latest upstream code.

```bash
grunt submodules
```

Note: This task will also be run any time the default `grunt` command is used.

Git for dummies
---------------

As the source code is handled by the version control system Git, it's useful to know some features used.

### Submodules ###

The repository uses submodules, which normally are handled directly by the Makefile, but sometimes you want to
be able to work with them manually.

Following are the steps to manually get the submodules:

```bash
git clone https://github.com/jquery/jquery.git
git submodule init
git submodule update
```

Or:

```bash
git clone https://github.com/jquery/jquery.git
git submodule update --init
```

Or:

```bash
git clone --recursive https://github.com/jquery/jquery.git
```

If you want to work inside a submodule, it is possible, but first you need to checkout a branch:

```bash
cd src/sizzle
git checkout master
```

After you've committed your changes to the submodule, you'll update the jquery project to point to the new commit,
but remember to push the submodule changes before pushing the new jquery commit:

```bash
cd src/sizzle
git push origin master
cd ..
git add src/sizzle
git commit
```

### cleaning ###

If you want to purge your working directory back to the status of upstream, following commands can be used (remember everything you've worked on is gone after these):

```bash
git reset --hard upstream/master
git clean -fdx
```

### rebasing ###

For feature/topic branches, you should always used the `--rebase` flag to `git pull`, or if you are usually handling many temporary "to be in a github pull request" branches, run following to automate this:

```bash
git config branch.autosetuprebase local
```
(see `man git-config` for more information)

### handling merge conflicts ###

If you're getting merge conflicts when merging, instead of editing the conflicted files manually, you can use the feature
`git mergetool`. Even though the default tool `xxdiff` looks awful/old, it's rather useful.

Following are some commands that can be used there:

* `Ctrl + Alt + M` - automerge as much as possible
* `b` - jump to next merge conflict
* `s` - change the order of the conflicted lines
* `u` - undo an merge
* `left mouse button` - mark a block to be the winner
* `middle mouse button` - mark a line to be the winner
* `Ctrl + S` - save
* `Ctrl + Q` - quit

[QUnit](http://docs.jquery.com/QUnit) Reference
-----------------

### Test methods ###

```js
expect( numAssertions );
stop();
start();
```

note: QUnit's eventual addition of an argument to stop/start is ignored in this test suite so that start and stop can be passed as callbacks without worrying about their parameters

### Test assertions ###

```js
ok( value, [message] );
equal( actual, expected, [message] );
notEqual( actual, expected, [message] );
deepEqual( actual, expected, [message] );
notDeepEqual( actual, expected, [message] );
strictEqual( actual, expected, [message] );
notStrictEqual( actual, expected, [message] );
raises( block, [expected], [message] );
```

Test Suite Convenience Methods Reference (See [test/data/testinit.js](https://github.com/jquery/jquery/blob/master/test/data/testinit.js))
------------------------------

### Returns an array of elements with the given IDs ###

```js
q( ... );
```

Example:

```js
q("main", "foo", "bar");

=> [ div#main, span#foo, input#bar ]
```

### Asserts that a selection matches the given IDs ###

```js
t( testName, selector, [ "array", "of", "ids" ] );
```

Example:

```js
t("Check for something", "//[a]", ["foo", "baar"]);
```

### Fires a native DOM event without going through jQuery ###

```js
fireNative( node, eventType )
```

Example:

```js
fireNative( jQuery("#elem")[0], "click" );
```

### Add random number to url to stop caching ###

```js
url( "some/url.php" );
```

Example:

```js
url("data/test.html");

=> "data/test.html?10538358428943"

url("data/test.php?foo=bar");

=> "data/test.php?foo=bar&10538358345554"
```

### Load tests in an iframe ###

Loads a given page constructing a url with fileName: `"./data/" + fileName + ".html"`
and fires the given callback on jQuery ready (using the jQuery loading from that page)
and passes the iFrame's jQuery to the callback.

```js
testIframe( fileName, testName, callback );
```

Callback arguments:

```js
callback( jQueryFromIFrame, iFrameWindow, iFrameDocument );
```

### Load tests in an iframe (window.iframeCallback) ###

Loads a given page constructing a url with fileName: `"./data/" + fileName + ".html"`
The given callback is fired when window.iframeCallback is called by the page
The arguments passed to the callback are the same as the
arguments passed to window.iframeCallback, whatever that may be

```js
testIframeWithCallback( testName, fileName, callback );
```

Questions?
----------

If you have any questions, please feel free to ask on the
[Developing jQuery Core forum](http://forum.jquery.com/developing-jquery-core) or in #jquery on irc.freenode.net.

redpajama_set_name: RedPajamaGithub


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>
Overview List (jackson-databind 2.1.0 API)
</TITLE>

<META NAME="date" CONTENT="2012-10-09">

<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">

All Classes

Packages

com.fasterxml.jackson.databind

com.fasterxml.jackson.databind.annotation

com.fasterxml.jackson.databind.cfg

com.fasterxml.jackson.databind.deser

com.fasterxml.jackson.databind.deser.impl

com.fasterxml.jackson.databind.deser.std

com.fasterxml.jackson.databind.exc

com.fasterxml.jackson.databind.ext

com.fasterxml.jackson.databind.introspect

com.fasterxml.jackson.databind.jsonFormatVisitors

com.fasterxml.jackson.databind.jsonschema

com.fasterxml.jackson.databind.jsontype

com.fasterxml.jackson.databind.jsontype.impl

com.fasterxml.jackson.databind.module

com.fasterxml.jackson.databind.node

com.fasterxml.jackson.databind.ser

com.fasterxml.jackson.databind.ser.impl

com.fasterxml.jackson.databind.ser.std

com.fasterxml.jackson.databind.type

com.fasterxml.jackson.databind.util


text:
package nl.nn.adapterframework.filesystem;

import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import nl.nn.adapterframework.configuration.ConfigurationException;
import nl.nn.adapterframework.core.HasPhysicalDestination;
import nl.nn.adapterframework.core.IDataIterator;
import nl.nn.adapterframework.core.PipeLineSession;
import nl.nn.adapterframework.core.PipeStartException;
import nl.nn.adapterframework.core.SenderException;
import nl.nn.adapterframework.doc.IbisDoc;
import nl.nn.adapterframework.pipes.IteratingPipe;
import nl.nn.adapterframework.stream.Message;
import nl.nn.adapterframework.util.Misc;
import nl.nn.adapterframework.util.SpringUtils;
import nl.nn.adapterframework.util.XmlBuilder;

public class ForEachAttachmentPipe<F, A, FS extends IWithAttachments<F,A>> extends IteratingPipe<A> {

	private Set<String> onlyProperties;
	private Set<String> excludeProperties;

	private FS fileSystem;

	@Override
	public void configure() throws ConfigurationException {
		super.configure();
		SpringUtils.autowireByName(getApplicationContext(), getFileSystem());
		getFileSystem().configure();
	}

	@Override
	public void start() throws PipeStartException {
		super.start();
		try {
			FS fileSystem=getFileSystem();
			fileSystem.open();
		} catch (FileSystemException e) {
			throw new PipeStartException("Cannot open fileSystem",e);
		}
	}

	@Override
	public void stop()  {
		try {
			getFileSystem().close();
		} catch (FileSystemException e) {
			log.warn("Cannot close fileSystem",e);
		}
		super.stop();
	}

	private class AttachmentIterator implements IDataIterator<A> {

		private Iterator<A> it;

		AttachmentIterator(Iterator<A> it) {
			this.it = it;
		}

		@Override
		public boolean hasNext() throws SenderException {
			return it.hasNext();
		}

		@Override
		public A next() throws SenderException {
			return it.next();
		}

		@Override
		public void close() throws SenderException {
			// no action required
		}
	}

	@Override
	protected IDataIterator<A> getIterator(Message message, PipeLineSession session, Map<String, Object> threadContext) throws SenderException {
		FS ifs = getFileSystem();

		try {
			F file = ifs.toFile(message.asString());
			Iterator<A> it = ifs.listAttachments(file);
			return new AttachmentIterator(it);
		} catch (Exception e) {
			throw new SenderException("unable to get file", e);
		}
	}

	@Override
	protected Message itemToMessage(A item) throws SenderException {
		FS ifs = getFileSystem();
		XmlBuilder result=new XmlBuilder("attachment");
		try {
			result.addAttribute("name", ifs.getAttachmentName(item));
			result.addAttribute("filename", ifs.getAttachmentFileName(item));
			result.addAttribute("contentType", ifs.getAttachmentContentType(item));
			result.addAttribute("size", ifs.getAttachmentSize(item));
			Map<String,Object> attachmentProperties = ifs.getAdditionalAttachmentProperties(item);
			if (attachmentProperties!=null) {
				XmlBuilder properties = new XmlBuilder("properties");
				Set<String> excludes=getExcludePropertiesSet();
				Set<String> includes=getOnlyPropertiesSet();
				if (excludes!=null || includes==null) {
					for(Entry<String,Object>entry:attachmentProperties.entrySet()) {
						if (excludes==null || !excludes.contains(entry.getKey())) {
							XmlBuilder property = new XmlBuilder("property");
							property.addAttribute("name", entry.getKey());
							if (entry.getValue()!=null) {
								property.setValue(entry.getValue().toString());
							}
							properties.addSubElement(property);
						}
					}
				} else {
					for(String key:includes) {
						XmlBuilder property = new XmlBuilder("property");
						property.addAttribute("name", key);
						Object value=attachmentProperties.get(key);
						if (value!=null) {
							property.setValue(value.toString());
						}
						properties.addSubElement(property);
					}
				}
				result.addSubElement(properties);
			}
		} catch (Exception e) {
			throw new SenderException("unable to read attachment attributes", e);
		}
		return new Message(result.toXML());
	}

	public String getPhysicalDestinationName() {
		if (getFileSystem() instanceof HasPhysicalDestination) {
			return ((HasPhysicalDestination)getFileSystem()).getPhysicalDestinationName();
		}
		return null;
	}

	public FS getFileSystem() {
		return fileSystem;
	}

	public void setFileSystem(FS fileSystem) {
		this.fileSystem = fileSystem;
	}

	@IbisDoc({"comma separated list of attachment properties to list", ""})
	public void setOnlyProperties(String onlyPropertiesList) {
		if (onlyProperties==null) {
			onlyProperties=new LinkedHashSet<String>();
		}
		Misc.addItemsToList(onlyProperties,onlyPropertiesList,"properties to list",false);
	}
	public Set<String> getOnlyPropertiesSet() {
		return onlyProperties;
	}

	@IbisDoc({"comma separated list of attachment properties not to list. When specified, 'onlyProperties' is ignored", ""})
	public void setExcludeProperties(String excludePropertiesList) {
		if (excludeProperties==null) {
			excludeProperties=new LinkedHashSet<String>();
		}
		Misc.addItemsToList(excludeProperties,excludePropertiesList,"properties not to list",false);
	}
	public Set<String> getExcludePropertiesSet() {
		return excludeProperties;
	}
}


text:
[Algorithmia][1] is an MLOps platform that includes capabilities for data
scientists, application developers, and IT operators to deploy, manage, govern,
and secure machine learning and other probabilistic models in production.

![Algorithmia Insights in Datadog][2]

Algorithmia Insights is a feature of Algorithmia Enterprise and provides a
metrics pipeline that can be used to instrument, measure, and monitor your
machine learning models. Use cases for monitoring inference-related metrics from
machine learning models include detecting model drift, data drift, model bias,
etc.

This integration allows you to stream operational metrics as well as
user-defined, inference-related metrics from Algorithmia to Kafka to the metrics
API in Datadog.

## Setup

1. From your Algorithmia instance, configure Algorithmia Insights to connect to
   a Kafka broker (external to Algorithmia).

2. See the [Algorithmia Integrations repository][3]
   to install, configure, and start the Datadog message forwarding service used
   in this integration, which forwards metrics from a Kafka topic to the
   metrics API in Datadog.

### Validation

1. From Algorithmia, query an algorithm that has Insights enabled.
2. In the Datadog interface, navigate to the **Metrics** summary page.
3. Verify that the metrics from Insights are present in Datadog by filtering for
   `algorithmia`.

### Streaming metrics

This integration streams metrics from Algorithmia when a model that has Insights
enabled is queried. Each log entry includes operational metrics and
inference-related metrics.

The `duration_milliseconds` metric is one of the operational metrics that is
included in the default payload from Algorithmia. To help you get started, this
integration also includes a dashboard and monitor for this default metric.

Additional metrics can include any user-defined, inference-related metrics that
are specified in Algorithmia by the algorithm developer. User-defined metrics
depend on your specific machine learning framework and use case, but might
include values such as prediction probabilities from a regression model in
scikit-learn, confidence scores from an image classifier in TensorFlow, or input
data from incoming API requests. **Note**: The message forwarding script
provided in this integration prefixes user-defined metrics with
`algorithmia.` in Datadog.

## Data Collected

### Metrics

See [metadata.csv][4] for a list of metrics provided by this integration.

### Service Checks

The Algorithmia check does not include any service checks.

### Events

The Algorithmia check does not include any events.

## Troubleshooting

Need help? Contact [Algorithmia support][5].

[1]: https://algorithmia.com/
[2]: https://raw.githubusercontent.com/DataDog/integrations-extras/master/algorithmia/images/algorithmia-insights-datadog.png
[3]: https://github.com/algorithmiaio/integrations
[4]: https://github.com/DataDog/integrations-extras/blob/master/algorithmia/metadata.csv
[5]: https://algorithmia.com/contact


text:
using System;

using bstrkr.core.spatial;

namespace bstrkr.mvvm.views
{
    public interface IMapView
    {
        event EventHandler<EventArgs> ZoomChanged;
        event EventHandler<CameraLocationChangedEventArgs> CameraLocationChanged;
        event EventHandler<MapMarkerClickEventArgs> MarkerClicked;
        event EventHandler<MapClickEventArgs> MapClicked;

        object MapObject { get; }

        float Zoom { get; }

        GeoRect VisibleRegion { get; }

        GeoPoint CameraLocation { get; }

        void SetCamera(GeoPoint location, float zoom);

        void AddMarker(IMapMarker marker);

        void RemoveMarker(IMapMarker marker);
    }
}


text:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
    <root>
        <appointment_date>2025-04-02</appointment_date>
        <doctor>thomas collins</doctor>
        <hospital>grand oak community hospital</hospital>
    </root>
</soapenv:Body>
</soapenv:Envelope>


text:
package org.apache.pulsar.client.kafka.compat.tests;

import static org.testng.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.clients.consumer.PulsarKafkaConsumer;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.apache.pulsar.broker.service.BrokerTestBase;
import org.apache.pulsar.client.api.Message;
import org.apache.pulsar.client.api.MessageBuilder;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.common.policies.data.PropertyAdmin;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class KafkaConsumerTest extends BrokerTestBase {

    @BeforeClass
    @Override
    protected void setup() throws Exception {
        isTcpLookup = true;
        super.baseSetup();
    }

    @AfterClass
    @Override
    protected void cleanup() throws Exception {
        super.internalCleanup();
    }

    @Test
    public void testSimpleConsumer() throws Exception {
        String topic = "persistent://sample/standalone/ns/testSimpleConsumer";

        Properties props = new Properties();
        props.put("bootstrap.servers", lookupUrl.toString());
        props.put("group.id", "my-subscription-name");
        props.put("enable.auto.commit", "false");
        props.put("key.deserializer", StringDeserializer.class.getName());
        props.put("value.deserializer", StringDeserializer.class.getName());

        Consumer<String, String> consumer = new PulsarKafkaConsumer<>(props);
        consumer.subscribe(Arrays.asList(topic));

        Producer<byte[]> pulsarProducer = pulsarClient.newProducer().topic(topic).create();

        for (int i = 0; i < 10; i++) {
            Message<byte[]> msg = MessageBuilder.create().setKey(Integer.toString(i))
                    .setContent(("hello-" + i).getBytes()).build();
            pulsarProducer.send(msg);
        }

        AtomicInteger received = new AtomicInteger();
        while (received.get() < 10) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            records.forEach(record -> {
                assertEquals(record.key(), Integer.toString(received.get()));
                assertEquals(record.value(), "hello-" + received.get());

                received.incrementAndGet();
            });

            consumer.commitSync();
        }

        consumer.close();
    }

    @Test
    public void testConsumerAutoCommit() throws Exception {
        String topic = "persistent://sample/standalone/ns/testConsumerAutoCommit";

        Properties props = new Properties();
        props.put("bootstrap.servers", lookupUrl.toString());
        props.put("group.id", "my-subscription-name");
        props.put("enable.auto.commit", "true");
        props.put("key.deserializer", StringDeserializer.class.getName());
        props.put("value.deserializer", StringDeserializer.class.getName());

        Consumer<String, String> consumer = new PulsarKafkaConsumer<>(props);
        consumer.subscribe(Arrays.asList(topic));

        Producer<byte[]> pulsarProducer = pulsarClient.newProducer().topic(topic).create();

        for (int i = 0; i < 10; i++) {
            Message<byte[]> msg = MessageBuilder.create().setKey(Integer.toString(i))
                    .setContent(("hello-" + i).getBytes()).build();
            pulsarProducer.send(msg);
        }

        AtomicInteger received = new AtomicInteger();
        while (received.get() < 10) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            records.forEach(record -> {
                assertEquals(record.key(), Integer.toString(received.get()));
                assertEquals(record.value(), "hello-" + received.get());
                received.incrementAndGet();
            });
        }

        consumer.close();

        // Re-open consumer and verify every message was acknowledged
        Consumer<String, String> consumer2 = new PulsarKafkaConsumer<>(props);
        consumer2.subscribe(Arrays.asList(topic));

        ConsumerRecords<String, String> records = consumer2.poll(100);
        assertEquals(records.count(), 0);
        consumer2.close();
    }

    @Test
    public void testConsumerManualOffsetCommit() throws Exception {
        String topic = "persistent://sample/standalone/ns/testConsumerManualOffsetCommit";

        Properties props = new Properties();
        props.put("bootstrap.servers", lookupUrl.toString());
        props.put("group.id", "my-subscription-name");
        props.put("enable.auto.commit", "false");
        props.put("key.deserializer", StringDeserializer.class.getName());
        props.put("value.deserializer", StringDeserializer.class.getName());

        Consumer<String, String> consumer = new PulsarKafkaConsumer<>(props);
        consumer.subscribe(Arrays.asList(topic));

        Producer<byte[]> pulsarProducer = pulsarClient.newProducer().topic(topic).create();

        for (int i = 0; i < 10; i++) {
            Message<byte[]> msg = MessageBuilder.create().setKey(Integer.toString(i))
                    .setContent(("hello-" + i).getBytes()).build();
            pulsarProducer.send(msg);
        }

        AtomicInteger received = new AtomicInteger();
        while (received.get() < 10) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            records.forEach(record -> {
                assertEquals(record.key(), Integer.toString(received.get()));
                assertEquals(record.value(), "hello-" + received.get());

                Map<TopicPartition, OffsetAndMetadata> offsets = new HashMap<>();
                offsets.put(new TopicPartition(record.topic(), record.partition()),
                        new OffsetAndMetadata(record.offset()));
                consumer.commitSync(offsets);

                received.incrementAndGet();
            });
        }

        consumer.close();

        // Re-open consumer and verify every message was acknowledged
        Consumer<String, String> consumer2 = new PulsarKafkaConsumer<>(props);
        consumer2.subscribe(Arrays.asList(topic));

        ConsumerRecords<String, String> records = consumer2.poll(100);
        assertEquals(records.count(), 0);
        consumer2.close();
    }

    @Test
    public void testPartitions() throws Exception {
        String topic = "persistent://sample/standalone/ns/testPartitions";

        // Create 8 partitions in topic
        admin.properties().createProperty("sample", new PropertyAdmin());
        admin.persistentTopics().createPartitionedTopic(topic, 8);

        Properties props = new Properties();
        props.put("bootstrap.servers", lookupUrl.toString());
        props.put("group.id", "my-subscription-name");
        props.put("enable.auto.commit", "true");
        props.put("key.deserializer", StringDeserializer.class.getName());
        props.put("value.deserializer", StringDeserializer.class.getName());

        Producer<byte[]> pulsarProducer = pulsarClient.newProducer().topic(topic)
                .messageRoutingMode(org.apache.pulsar.client.api.MessageRoutingMode.RoundRobinPartition).create();

        // Create 2 Kakfa consumer and verify each gets half of the messages
        List<Consumer<String, String>> consumers = new ArrayList<>();
        for (int c = 0; c < 2; c++) {
            Consumer<String, String> consumer = new PulsarKafkaConsumer<>(props);
            consumer.subscribe(Arrays.asList(topic));
            consumers.add(consumer);
        }

        int N = 8 * 3;

        for (int i = 0; i < N; i++) {
            Message<byte[]> msg = MessageBuilder.create().setKey(Integer.toString(i))
                    .setContent(("hello-" + i).getBytes()).build();
            pulsarProducer.send(msg);
        }

        consumers.forEach(consumer -> {
            int expectedMessaged = N / consumers.size();

            for (int i = 0; i < expectedMessaged;) {
                ConsumerRecords<String, String> records = consumer.poll(100);
                i += records.count();
            }

            // No more messages for this consumer
            ConsumerRecords<String, String> records = consumer.poll(100);
            assertEquals(records.count(), 0);
        });

        consumers.forEach(Consumer::close);
    }

    @Test
    public void testConsumerSeek() throws Exception {
        String topic = "persistent://sample/standalone/ns/testSimpleConsumer";

        Properties props = new Properties();
        props.put("bootstrap.servers", lookupUrl.toString());
        props.put("group.id", "my-subscription-name");
        props.put("enable.auto.commit", "false");
        props.put("key.deserializer", StringDeserializer.class.getName());
        props.put("value.deserializer", StringDeserializer.class.getName());

        Consumer<String, String> consumer = new PulsarKafkaConsumer<>(props);
        consumer.subscribe(Arrays.asList(topic));

        Producer<byte[]> pulsarProducer = pulsarClient.newProducer().topic(topic).create();

        for (int i = 0; i < 10; i++) {
            Message<byte[]> msg = MessageBuilder.create().setKey(Integer.toString(i))
                    .setContent(("hello-" + i).getBytes()).build();
            pulsarProducer.send(msg);
        }

        AtomicInteger received = new AtomicInteger();
        while (received.get() < 10) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            records.forEach(record -> {
                assertEquals(record.key(), Integer.toString(received.get()));
                assertEquals(record.value(), "hello-" + received.get());

                received.incrementAndGet();
            });

            consumer.commitSync();
        }

        consumer.seekToBeginning(Collections.emptyList());

        Thread.sleep(500);

        // Messages should be available again
        received.set(0);
        while (received.get() < 10) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            records.forEach(record -> {
                assertEquals(record.key(), Integer.toString(received.get()));
                assertEquals(record.value(), "hello-" + received.get());

                received.incrementAndGet();
            });

            consumer.commitSync();
        }

        consumer.close();
    }

    @Test
    public void testConsumerSeekToEnd() throws Exception {
        String topic = "persistent://sample/standalone/ns/testSimpleConsumer";

        Properties props = new Properties();
        props.put("bootstrap.servers", lookupUrl.toString());
        props.put("group.id", "my-subscription-name");
        props.put("enable.auto.commit", "false");
        props.put("key.deserializer", StringDeserializer.class.getName());
        props.put("value.deserializer", StringDeserializer.class.getName());

        Consumer<String, String> consumer = new PulsarKafkaConsumer<>(props);
        consumer.subscribe(Arrays.asList(topic));

        Producer<byte[]> pulsarProducer = pulsarClient.newProducer().topic(topic).create();

        for (int i = 0; i < 10; i++) {
            Message<byte[]> msg = MessageBuilder.create().setKey(Integer.toString(i))
                    .setContent(("hello-" + i).getBytes()).build();
            pulsarProducer.send(msg);
        }

        AtomicInteger received = new AtomicInteger();
        while (received.get() < 10) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            records.forEach(record -> {
                assertEquals(record.key(), Integer.toString(received.get()));
                assertEquals(record.value(), "hello-" + received.get());

                received.incrementAndGet();
            });

            consumer.commitSync();
        }

        consumer.seekToEnd(Collections.emptyList());
        Thread.sleep(500);

        consumer.close();

        // Recreate the consumer
        consumer = new PulsarKafkaConsumer<>(props);
        consumer.subscribe(Arrays.asList(topic));

        ConsumerRecords<String, String> records = consumer.poll(100);
        // Since we are at the end of the topic, there should be no messages
        assertEquals(records.count(), 0);

        consumer.close();
    }

}


text:
<?php

namespace PragmaRX\Tracker\Vendor\Laravel\Models;

class RoutePath extends Base {

	protected $table = 'tracker_route_paths';

	protected $fillable = array(
		'route_id',
		'path',
	);

	public function parameters()
	{
		return $this->hasMany($this->getConfig()->get('route_path_parameter_model'));
	}

	public function route()
	{
		return $this->belongsTo($this->getConfig()->get('route_model'), 'route_id');
	}

}


text:
package org.zaproxy.addon.oast.services.interactsh;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.MGF1ParameterSpec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.OAEPParameterSpec;
import javax.crypto.spec.PSource;
import javax.crypto.spec.SecretKeySpec;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bouncycastle.util.io.pem.PemObject;
import org.bouncycastle.util.io.pem.PemWriter;
import org.parosproxy.paros.Constant;
import org.parosproxy.paros.extension.OptionsChangedListener;
import org.parosproxy.paros.model.Model;
import org.parosproxy.paros.model.OptionsParam;
import org.parosproxy.paros.network.HttpHeader;
import org.parosproxy.paros.network.HttpMalformedHeaderException;
import org.parosproxy.paros.network.HttpMessage;
import org.parosproxy.paros.network.HttpRequestHeader;
import org.parosproxy.paros.network.HttpSender;
import org.zaproxy.addon.oast.ExtensionOast;
import org.zaproxy.addon.oast.OastService;
import org.zaproxy.addon.oast.OastState;
import org.zaproxy.zap.network.HttpRequestBody;
import org.zaproxy.zap.utils.Stats;

public class InteractshService extends OastService implements OptionsChangedListener {

    // The Interactsh client methods in this class are based on the official Interactsh CLI client:
    // https://github.com/projectdiscovery/interactsh/blob/f5b53a7b8be329ee6d4936ed753e3c46472e5726/pkg/client/client.go

    private static final Logger LOGGER = LogManager.getLogger(InteractshService.class);

    private final ScheduledExecutorService executorService =
            Executors.newSingleThreadScheduledExecutor(
                    new OastThreadFactory("ZAP-OAST-Interactsh-"));
    private final UUID secretKey;
    private final String correlationId;
    private final HttpSender httpSender;
    private final InteractshParam param;

    private URI serverUrl;
    private PrivateKey privateKey;
    private PublicKey publicKey;
    private HttpMessage pollMsg;
    private boolean isRegistered;
    private String currentServerUrl;
    private int currentPollingFrequency;
    private ScheduledFuture<?> pollingSchedule;

    public InteractshService() {
        this(new InteractshParam());
    }

    InteractshService(InteractshParam param) {
        httpSender =
                new HttpSender(
                        Model.getSingleton().getOptionsParam().getConnectionParam(),
                        true,
                        // TODO: Replace on next ZAP release with HttpSender.OAST_INITIATOR
                        ExtensionOast.HTTP_SENDER_OAST_INITIATOR);
        secretKey = UUID.randomUUID();
        correlationId = RandomStringUtils.randomAlphanumeric(20).toLowerCase(Locale.ROOT);
        this.param = param;
    }

    @Override
    public String getName() {
        return "Interactsh";
    }

    @Override
    public void startService() {
        LOGGER.debug("Starting Interactsh Service.");
        if (pollingSchedule == null || pollingSchedule.isDone()) {
            schedulePoller(param.getPollingFrequency());
        }
    }

    @Override
    public void stopService() {
        executorService.shutdown();
        deregister();
    }

    @Override
    public void sessionChanged() {
        if (isRegistered) {
            deregister();
        }
    }

    public void optionsLoaded() {
        currentServerUrl = param.getServerUrl();
        currentPollingFrequency = param.getPollingFrequency();
    }

    @Override
    public void optionsChanged(OptionsParam optionsParam) {
        if (!Objects.equals(currentServerUrl, param.getServerUrl())) {
            try {
                deregister();
                register();
                LOGGER.debug(
                        "Updated Interactsh params - server URL: {} and polling frequency: {} seconds.",
                        param.getServerUrl(),
                        param.getPollingFrequency());
            } catch (Exception e) {
                LOGGER.error(
                        "Error during applying Interactsh config changes - server URL: {} and polling frequency: {} seconds. {}",
                        param.getServerUrl(),
                        param.getPollingFrequency(),
                        e.getMessage(),
                        e);
            }
        } else if (currentPollingFrequency != param.getPollingFrequency()) {
            try {
                stopPoller();
                startService();
                LOGGER.debug(
                        "Updated Interactsh polling frequency: {} seconds.",
                        param.getPollingFrequency());
            } catch (Exception e) {
                LOGGER.error(
                        "Error during applying Interactsh polling frequency: {} seconds. {}",
                        param.getPollingFrequency(),
                        e.getMessage(),
                        e);
            }
        }

        optionsLoaded();
    }

    public synchronized void register() throws InteractshException {
        register(true);
    }

    synchronized void register(boolean startPolling) throws InteractshException {
        try {
            if (isRegistered) {
                return;
            }
            serverUrl = new URI(param.getServerUrl(), true);
            KeyPair keyPair = generateRsaKeyPair();
            privateKey = keyPair.getPrivate();
            publicKey = keyPair.getPublic();

            PemObject pemObject = new PemObject("PUBLIC KEY", publicKey.getEncoded());
            ByteArrayOutputStream pubKeyByteStream = new ByteArrayOutputStream();
            PemWriter pemWriter = new PemWriter(new OutputStreamWriter(pubKeyByteStream));
            pemWriter.writeObject(pemObject);
            pemWriter.close();
            String pubKeyEncoded =
                    new String(Base64.getEncoder().encode(pubKeyByteStream.toByteArray()));

            JSONObject reqBodyJson = new JSONObject();
            reqBodyJson.put("public-key", pubKeyEncoded);
            reqBodyJson.put("secret-key", secretKey.toString());
            reqBodyJson.put("correlation-id", correlationId);
            HttpRequestBody reqBody = new HttpRequestBody(reqBodyJson.toString());

            URI registrationUri = (URI) serverUrl.clone();
            registrationUri.setPath("/register");
            HttpRequestHeader reqHeader =
                    createRequestHeader(registrationUri, reqBody.getBytes().length);
            HttpMessage reqMsg = new HttpMessage(reqHeader, reqBody);
            httpSender.sendAndReceive(reqMsg);
            if (reqMsg.getResponseHeader().getStatusCode() != 200) {
                LOGGER.warn(
                        "Error during interactsh register, due to bad HTTP code {}. Content: {}",
                        reqMsg.getResponseHeader().getStatusCode(),
                        reqMsg.getResponseBody());

                throw new InteractshException(
                        Constant.messages.getString(
                                "oast.interactsh.error.register",
                                Constant.messages.getString("oast.interactsh.error.badHttpCode")));
            }

            LOGGER.debug(
                    "Registered correlationId {}. StatusCode: {}, Content {}",
                    correlationId,
                    reqMsg.getResponseHeader().getStatusCode(),
                    reqMsg.getResponseBody());
            isRegistered = true;
            if (startPolling) {
                schedulePoller(0);
            }
        } catch (IOException | CloneNotSupportedException | NoSuchAlgorithmException e) {
            LOGGER.error("Error during interactsh register: {}", e.getMessage(), e);
            throw new InteractshException(
                    Constant.messages.getString(
                            "oast.interactsh.error.register", e.getLocalizedMessage()));
        }
    }

    private static KeyPair generateRsaKeyPair() throws NoSuchAlgorithmException {
        KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
        generator.initialize(2048);

        KeyPair keyPair = generator.generateKeyPair();
        LOGGER.debug("OAST Interactsh: RSA key pair generated.");
        return keyPair;
    }

    // For unit tests
    PublicKey getRsaPublicKey() {
        return publicKey;
    }

    public synchronized void deregister() {
        try {
            if (!isRegistered) {
                return;
            }
            stopPoller();
            URI deregistrationUri = (URI) serverUrl.clone();
            deregistrationUri.setPath("/deregister");
            JSONObject reqBodyJson = new JSONObject();
            reqBodyJson.put("correlation-id", correlationId);
            reqBodyJson.put("secret-key", secretKey.toString());
            HttpRequestBody reqBody = new HttpRequestBody(reqBodyJson.toString());
            HttpRequestHeader reqHeader =
                    createRequestHeader(deregistrationUri, reqBody.getBytes().length);
            HttpMessage deregisterMsg = new HttpMessage(reqHeader, reqBody);
            httpSender.sendAndReceive(deregisterMsg);
            if (deregisterMsg.getResponseHeader().getStatusCode() != 200) {
                LOGGER.warn(
                        "Error during interactsh deregister, due to bad HTTP code {}. Content: {}",
                        deregisterMsg.getResponseHeader().getStatusCode(),
                        deregisterMsg.getResponseBody());
                return;
            }
            LOGGER.debug("Deregistered correlationId: {}", correlationId);
            isRegistered = false;
            fireOastStateChanged(new OastState(getName(), false, null));
        } catch (Exception e) {
            LOGGER.error("Error during interactsh deregister: {}", e.getMessage(), e);
        }
    }

    private HttpRequestHeader createRequestHeader(URI uri, int contentLength)
            throws HttpMalformedHeaderException {
        HttpRequestHeader reqHeader =
                new HttpRequestHeader(HttpRequestHeader.POST, uri, HttpHeader.HTTP11);
        reqHeader.setHeader(HttpHeader.CONTENT_TYPE, HttpHeader.JSON_CONTENT_TYPE);
        reqHeader.setHeader(HttpHeader.CONTENT_LENGTH, String.valueOf(contentLength));
        if (!param.getAuthToken().isEmpty()) {
            reqHeader.setHeader(HttpHeader.AUTHORIZATION, param.getAuthToken());
        }
        return reqHeader;
    }

    @Override
    public String getNewPayload() throws URIException, InteractshException {
        if (!isRegistered) {
            register();
        }
        Stats.incCounter("stats.oast.interactsh.payloadsGenerated");
        return RandomStringUtils.randomAlphanumeric(1).toLowerCase(Locale.ROOT)
                + '.'
                + correlationId
                + RandomStringUtils.randomAlphanumeric(13).toLowerCase(Locale.ROOT)
                + '.'
                + serverUrl.getHost();
    }

    @Override
    public void poll() {
        stopPoller();
        schedulePoller(0);
    }

    private synchronized void stopPoller() {
        if (pollingSchedule != null) {
            pollingSchedule.cancel(false);
        }
    }

    private synchronized void schedulePoller(int initialDelay) {
        if (!isRegistered) {
            return;
        }
        LOGGER.debug("Start Polling the Interactsh Server ...");
        pollingSchedule =
                executorService.scheduleAtFixedRate(
                        new InteractshPoller(this),
                        initialDelay,
                        param.getPollingFrequency(),
                        TimeUnit.SECONDS);
    }

    /** @return new interactions from the server. */
    public synchronized List<InteractshEvent> getInteractions() {
        try {
            if (!isRegistered) {
                LOGGER.warn(Constant.messages.getString("oast.interactsh.error.poll.unregistered"));
                return new ArrayList<>();
            }
            if (pollMsg == null) {
                URI pollUri = (URI) serverUrl.clone();
                pollUri.setPath("/poll");
                pollUri.setQuery("id=" + correlationId + "&secret=" + secretKey.toString());
                HttpRequestHeader reqHeader =
                        new HttpRequestHeader(HttpRequestHeader.GET, pollUri, HttpHeader.HTTP11);
                if (!param.getAuthToken().isEmpty()) {
                    reqHeader.setHeader(HttpHeader.AUTHORIZATION, param.getAuthToken());
                }
                pollMsg = new HttpMessage(reqHeader);
            }
            httpSender.sendAndReceive(pollMsg);
            if (pollMsg.getResponseHeader().getStatusCode() != 200) {
                LOGGER.warn(
                        "Error during interactsh poll, due to bad HTTP code {}. Content: {}",
                        pollMsg.getResponseHeader().getStatusCode(),
                        pollMsg.getResponseBody());
                return new ArrayList<>();
            }

            JSONObject response = JSONObject.fromObject(pollMsg.getResponseBody().toString());
            if (!response.containsKey("data") || !response.containsKey("aes_key")) {
                LOGGER.warn(
                        "Bad polling response received from interactsh server. Missing data or aes_key element. HTTP code {}. Content: {}",
                        pollMsg.getResponseHeader().getStatusCode(),
                        pollMsg.getResponseBody());
                return new ArrayList<>();
            }
            String aesKey = response.getString("aes_key");
            JSONArray interactions = response.getJSONArray("data");
            LOGGER.debug(
                    "Polled {} interactions for correlationId: {}",
                    interactions.size(),
                    correlationId);

            List<InteractshEvent> result = new ArrayList<>();
            for (int i = 0; i < interactions.size(); ++i) {
                String interaction = interactions.getString(i);
                result.add(
                        new InteractshEvent(
                                JSONObject.fromObject(
                                        new String(decryptMessage(aesKey, interaction)))));
            }
            if (LOGGER.isDebugEnabled()) {
                for (InteractshEvent event : result) {
                    LOGGER.debug(
                            "Returned interaction for correlationId: {}. Time: {}, Protocol:{}, UniqueId:{}, RemoteAddress:{}",
                            correlationId,
                            event.getTimestamp(),
                            event.getProtocol(),
                            event.getUniqueId(),
                            event.getRemoteAddress());
                }
            }
            Stats.incCounter("stats.oast.interactsh.interactions", result.size());
            return result;
        } catch (Exception e) {
            LOGGER.error("Error during interactsh poll: {}", e.getMessage(), e);
            return new ArrayList<>();
        }
    }

    /** Decrypts an AES-256-RSA-OAEP encrypted message to string */
    private byte[] decryptMessage(String encodedEncryptedKey, String encodedEncryptedMsg) {
        try {
            byte[] decodedEncryptedKey = Base64.getDecoder().decode(encodedEncryptedKey);
            Cipher decryptionCipher = Cipher.getInstance("RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING");
            OAEPParameterSpec oaepParameterSpec =
                    new OAEPParameterSpec(
                            "SHA-256",
                            "MGF1",
                            MGF1ParameterSpec.SHA256,
                            PSource.PSpecified.DEFAULT);
            decryptionCipher.init(Cipher.DECRYPT_MODE, privateKey, oaepParameterSpec);
            byte[] decodedDecryptedKey = decryptionCipher.doFinal(decodedEncryptedKey);

            byte[] decodedEncryptedMsg = Base64.getDecoder().decode(encodedEncryptedMsg);
            decryptionCipher = Cipher.getInstance("AES/CFB/NoPadding");
            SecretKey aesKey = new SecretKeySpec(decodedDecryptedKey, "AES");
            IvParameterSpec iv =
                    new IvParameterSpec(
                            Arrays.copyOf(decodedEncryptedMsg, decryptionCipher.getBlockSize()));
            decryptionCipher.init(Cipher.DECRYPT_MODE, aesKey, iv);
            return decryptionCipher.doFinal(
                    Arrays.copyOfRange(
                            decodedEncryptedMsg,
                            decryptionCipher.getBlockSize(),
                            decodedEncryptedMsg.length));
        } catch (Exception e) {
            LOGGER.warn(
                    "Could not decrypt Interactsh interactions: {}", e.getLocalizedMessage(), e);
            return new byte[0];
        }
    }

    public InteractshParam getParam() {
        return param;
    }

    @Override
    public boolean isRegistered() {
        return isRegistered;
    }
}


text:
package com.explodingpixels.macwidgets;

import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;

import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

/**
 * Creates a group of components and provides a label underneath those components. The added
 * components will be placed side by side, with no spacing in between them, like this:
 *

 *
 *

 * Here are a couple more practical applications of {@code LabledComponentGroup}:
 *

 *
 *

 * Here's how to create a {@code LabeledComponentGroup} with two buttons:
 *

 * JToggleButton leftButton = new JToggleButton("Left Button");
 * leftButton.putClientProperty("JButton.buttonType", "segmentedTextured");
 * leftButton.putClientProperty("JButton.segmentPosition", "first");
 *

 * JToggleButton rightButton = new JToggleButton("Right Button");
 * rightButton.putClientProperty("JButton.buttonType", "segmentedTextured");
 * rightButton.putClientProperty("JButton.segmentPosition", "last");
 *

 * LabeledComponentGroup group = new LabeledComponentGroup("Group", leftButton, rightButton);
 *

 */
public class LabeledComponentGroup {

    private JComponent fComponent;

    /**
     * Creates a labeled component group using the given label and components.
     *
     * @param labelString the label of the group.
     * @param components  the components in the group.
     */
    public LabeledComponentGroup(String labelString, JComponent... components) {
        this(labelString, Arrays.asList(components));
    }

    /**
     * Creates a labeled component group using the given label and components.
     *
     * @param labelString the label of the group.
     * @param components  the components in the group.
     */
    public LabeledComponentGroup(String labelString, List<JComponent> components) {
        init(labelString, components);
    }

    /**
     * Creates a labeled component group using the given button group.
     *
     * @param labelString the label of the group.
     * @param components  the components in the group.
     */
    public LabeledComponentGroup(String labelString, ButtonGroup group) {
    	ArrayList<JComponent> list = new ArrayList<JComponent> ();
    	for (Enumeration<AbstractButton> e = group.getElements() ; e.hasMoreElements() ;) {
    		AbstractButton element = e.nextElement();
    		list.add(element);
    	}
    	init(labelString, list);
    }

	protected void init(String labelString, List<JComponent> components)
	{
		JComponent componentToAdd;
        if (components.size() == 1) {
            componentToAdd = components.get(0);
        } else {
            componentToAdd = new JPanel(new FlowLayout(0, 0, FlowLayout.CENTER));
            componentToAdd.setOpaque(false);
            for (JComponent component : components) {
                componentToAdd.add(component);
            }
        }

        // definte the FormLayout columns and rows.
        FormLayout layout = new FormLayout("p", "fill:p:grow, p");
        // create the cell constraints to use in the layout.
        CellConstraints cc = new CellConstraints();
        // create the builder with our panel as the component to be filled.
        PanelBuilder builder = new PanelBuilder(layout, new JPanel());

        builder.add(componentToAdd, cc.xy(1, 1, "center, center"));
        builder.add(createLabel(labelString), cc.xy(1, 2, "center, top"));

        fComponent = builder.getPanel();
        fComponent.setOpaque(false);
	}

    public JComponent getComponent() {
        return fComponent;
    }

    private JLabel createLabel(String labelString) {
        JLabel label = MacWidgetFactory.makeEmphasizedLabel(new JLabel(labelString));
        label.setFont(MacFontUtils.TOOLBAR_LABEL_FONT);
        return label;
    }
}


text:
angular.module('account.properties.propertystatuses', ['ngRoute', 'security.authorization']);
angular.module('account.properties.propertystatuses').config(['$routeProvider', 'securityAuthorizationProvider', function($routeProvider, securityAuthorizationProvider){
  $routeProvider
    .when('/account/propertystatuses', {
      templateUrl: 'account/properties/account-propertystatuses.tpl.html',
      controller: 'PropertyStatusCtrl',
      title: 'PropertyStatus Area',
      resolve: {
        authenticatedUser: securityAuthorizationProvider.requireAuthenticatedUser,
        propertyStatusesResult: ['$q', '$location', 'securityAuthorization', 'accountResource' ,function($q, $location, securityAuthorization, accountResource){
          //get account details only for verified-user, otherwise redirect to /account/verification
          var redirectUrl;
          var promise = securityAuthorization.requireVerifiedUser()
            .then(accountResource.getPropertyStatuses, function(reason){
              //rejected either user is unverified or un-authenticated
              redirectUrl = reason === 'unverified-client'? '/account/verification': '/login';
              return $q.reject();
            })
            .catch(function(){
              redirectUrl = redirectUrl || '/account';
              $location.path(redirectUrl);
              return $q.reject();
            });
          return promise;
        }]
      }
    });
}]);
angular.module('account.properties.propertystatuses').controller('PropertyStatusCtrl', [ '$scope', '$location', 'propertyStatusesResult', 'accountResource',
  function($scope, $location, data, accountResource){
    $scope.statusesResults = data;
    accountResource.getAccountDetails().then(function(result){
      if (result.user.isCompletedProfile == 'no'){
           // $location.path('/account/settings');
      }
    });
  }]);


text:
package im.actor.sdk.util.images.common;

import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;

/**
 * Cache for reusing graphics primitives
 */
public class WorkCache {
    /**
     * Used for BitmapFactory.Options.inTempStorage
     */
    public static ThreadLocal<byte[]> BITMAP_TMP = new ThreadLocal<byte[]>() {
        @Override
        protected byte[] initialValue() {
            return new byte[16 * 1024];
        }
    };

    public static ThreadLocal<Paint> PAINT = new ThreadLocal<Paint>() {
        @Override
        protected Paint initialValue() {
            return new Paint();
        }
    };

    public static ThreadLocal<Rect> RECT1 = new ThreadLocal<Rect>() {
        @Override
        protected Rect initialValue() {
            return new Rect();
        }
    };

    public static ThreadLocal<Rect> RECT2 = new ThreadLocal<Rect>() {
        @Override
        protected Rect initialValue() {
            return new Rect();
        }
    };

    public static ThreadLocal<RectF> RECTF1 = new ThreadLocal<RectF>() {
        @Override
        protected RectF initialValue() {
            return new RectF();
        }
    };

    public static ThreadLocal<RectF> RECTF2 = new ThreadLocal<RectF>() {
        @Override
        protected RectF initialValue() {
            return new RectF();
        }
    };
}


text:
class PixieError(Exception):
    pass

class LoginFailed(PixieError):
    def __str__(self):
        return 'Login failed! Please check username/password/network.'

class NoAuth(PixieError):
    def __str__(self):
        return 'Authentication required. Please call login() first.'

class IllustError(PixieError):
    def __init__(self, illust_id, message=None):
        if message is None:
            message = 'Illust error.'

        self.illust_id = illust_id
        self.message = message

    def __str__(self):
        return '{} (illust_id: {})'.format(self.message, self.illust_id)

class APIError(PixieError):
    def __init__(self, call_func, errors):
        self.call_func = call_func
        self.errors = errors

    def __str__(self):
        return "Error while calling API request '{}'. Errors: {}.".format(
            self.call_func.__name__, self.errors)

class DownloadError(PixieError):
    def __init__(self, illust, msg):
        self.illust = illust
        self.msg = msg

    def __str__(self):
        return 'Error while downloading {}: {}'.format(
            self.illust, self.msg)


text:
// -*- C++ -*-

// Copyright (C) 2005-2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software
// Foundation; either version 3, or (at your option) any later
// version.

// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.

// Permission to use, copy, modify, sell, and distribute this software
// is hereby granted without fee, provided that the above copyright
// notice appears in all copies, and that both that copyright notice
// and this permission notice appear in supporting documentation. None
// of the above authors, nor IBM Haifa Research Laboratories, make any
// representation about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.

/**
 * @file rc_binomial_heap_/rc_binomial_heap_.hpp
 * Contains an implementation for redundant-counter binomial heap.
 */

#include <ext/pb_ds/detail/cond_dealtor.hpp>
#include <ext/pb_ds/detail/type_utils.hpp>
#include <ext/pb_ds/detail/binomial_heap_base_/binomial_heap_base_.hpp>
#include <ext/pb_ds/detail/rc_binomial_heap_/rc.hpp>
#include <debug/debug.h>

namespace __gnu_pbds
{
  namespace detail
  {
#define PB_DS_CLASS_T_DEC \
    template<typename Value_Type, typename Cmp_Fn, typename _Alloc>

#define PB_DS_CLASS_C_DEC \
    rc_binomial_heap<Value_Type, Cmp_Fn, _Alloc>

#define PB_DS_RC_C_DEC \
    rc<typename binomial_heap_base<Value_Type, Cmp_Fn, _Alloc>::node, _Alloc>

    /**
     *  Redundant-counter binomial heap.
     *
     *  @ingroup heap-detail
     */
    template<typename Value_Type, typename Cmp_Fn, typename _Alloc>
    class rc_binomial_heap
    : public binomial_heap_base<Value_Type, Cmp_Fn, _Alloc>
    {
    private:
      typedef binomial_heap_base<Value_Type, Cmp_Fn, _Alloc>
      							base_type;
      typedef typename base_type::node_pointer 		node_pointer;
      typedef typename base_type::node_const_pointer 	node_const_pointer;
      typedef PB_DS_RC_C_DEC 				rc_t;

    public:
      typedef Value_Type 				value_type;
      typedef typename _Alloc::size_type 		size_type;
      typedef typename _Alloc::difference_type 		difference_type;
      typedef typename base_type::pointer 		pointer;
      typedef typename base_type::const_pointer 	const_pointer;
      typedef typename base_type::reference 		reference;
      typedef typename base_type::const_reference 	const_reference;
      typedef typename base_type::point_const_iterator 	point_const_iterator;
      typedef typename base_type::point_iterator 	point_iterator;
      typedef typename base_type::const_iterator 	const_iterator;
      typedef typename base_type::iterator 		iterator;
      typedef typename base_type::cmp_fn 		cmp_fn;
      typedef typename base_type::allocator_type 	allocator_type;

      rc_binomial_heap();

      rc_binomial_heap(const Cmp_Fn&);

      rc_binomial_heap(const PB_DS_CLASS_C_DEC&);

      ~rc_binomial_heap();

      void
      swap(PB_DS_CLASS_C_DEC&);

      inline point_iterator
      push(const_reference);

      void
      modify(point_iterator, const_reference);

      inline void
      pop();

      void
      erase(point_iterator);

      inline void
      clear();

      template<typename Pred>
      size_type
      erase_if(Pred);

      template<typename Pred>
      void
      split(Pred, PB_DS_CLASS_C_DEC&);

      void
      join(PB_DS_CLASS_C_DEC&);

#ifdef _GLIBCXX_DEBUG
      void
      assert_valid(const char*, int) const;
#endif

#ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_
      void
      trace() const;
#endif

    private:

      inline node_pointer
      link_with_next_sibling(node_pointer);

      void
      make_0_exposed();

      void
      make_binomial_heap();

#ifdef _GLIBCXX_DEBUG
      static node_const_pointer
      next_2_pointer(node_const_pointer);

      static node_const_pointer
      next_after_0_pointer(node_const_pointer);
#endif

      rc_t 			m_rc;
    };

#include <ext/pb_ds/detail/rc_binomial_heap_/constructors_destructor_fn_imps.hpp>
#include <ext/pb_ds/detail/rc_binomial_heap_/debug_fn_imps.hpp>
#include <ext/pb_ds/detail/rc_binomial_heap_/erase_fn_imps.hpp>
#include <ext/pb_ds/detail/rc_binomial_heap_/trace_fn_imps.hpp>
#include <ext/pb_ds/detail/rc_binomial_heap_/insert_fn_imps.hpp>
#include <ext/pb_ds/detail/rc_binomial_heap_/split_join_fn_imps.hpp>

#undef PB_DS_CLASS_C_DEC
#undef PB_DS_CLASS_T_DEC
#undef PB_DS_RC_C_DEC
  } // namespace detail
} // namespace __gnu_pbds


text:
import slash from "slash";
import path from "path";
import fs from "fs";

import * as util from "./util";
import * as watcher from "./watcher";
import type { CmdOptions } from "./options";

const FILE_TYPE = Object.freeze({
  NON_COMPILABLE: "NON_COMPILABLE",
  COMPILED: "COMPILED",
  IGNORED: "IGNORED",
  ERR_COMPILATION: "ERR_COMPILATION",
} as const);

function outputFileSync(filePath: string, data: string | Buffer): void {
  fs.mkdirSync(path.dirname(filePath), { recursive: true });
  fs.writeFileSync(filePath, data);
}

export default async function ({
  cliOptions,
  babelOptions,
}: CmdOptions): Promise<void> {
  async function write(
    src: string,
    base: string,
  ): Promise<keyof typeof FILE_TYPE> {
    let relative = path.relative(base, src);

    if (!util.isCompilableExtension(relative, cliOptions.extensions)) {
      return FILE_TYPE.NON_COMPILABLE;
    }

    relative = util.withExtension(
      relative,
      cliOptions.keepFileExtension
        ? path.extname(relative)
        : cliOptions.outFileExtension,
    );

    const dest = getDest(relative, base);

    try {
      const res = await util.compile(src, {
        ...babelOptions,
        sourceFileName: slash(path.relative(dest + "/..", src)),
      });

      if (!res) return FILE_TYPE.IGNORED;

      // we've requested explicit sourcemaps to be written to disk
      if (
        res.map &&
        babelOptions.sourceMaps &&
        babelOptions.sourceMaps !== "inline"
      ) {
        const mapLoc = dest + ".map";
        res.code = util.addSourceMappingUrl(res.code, mapLoc);
        res.map.file = path.basename(relative);
        outputFileSync(mapLoc, JSON.stringify(res.map));
      }

      outputFileSync(dest, res.code);
      util.chmod(src, dest);

      if (cliOptions.verbose) {
        console.log(path.relative(process.cwd(), src) + " -> " + dest);
      }

      return FILE_TYPE.COMPILED;
    } catch (err) {
      if (cliOptions.watch) {
        console.error(err);
        return FILE_TYPE.ERR_COMPILATION;
      }

      throw err;
    }
  }

  function getDest(filename: string, base: string): string {
    if (cliOptions.relative) {
      return path.join(base, cliOptions.outDir, filename);
    }
    return path.join(cliOptions.outDir, filename);
  }

  async function handleFile(src: string, base: string): Promise<boolean> {
    const written = await write(src, base);

    if (
      (cliOptions.copyFiles && written === FILE_TYPE.NON_COMPILABLE) ||
      (cliOptions.copyIgnored && written === FILE_TYPE.IGNORED)
    ) {
      const filename = path.relative(base, src);
      const dest = getDest(filename, base);
      outputFileSync(dest, fs.readFileSync(src));
      util.chmod(src, dest);
    }
    return written === FILE_TYPE.COMPILED;
  }

  async function handle(filenameOrDir: string): Promise<number> {
    if (!fs.existsSync(filenameOrDir)) return 0;

    const stat = fs.statSync(filenameOrDir);

    if (stat.isDirectory()) {
      const dirname = filenameOrDir;

      let count = 0;

      const files = util.readdir(dirname, cliOptions.includeDotfiles);
      for (const filename of files) {
        const src = path.join(dirname, filename);

        const written = await handleFile(src, dirname);
        if (written) count += 1;
      }

      return count;
    } else {
      const filename = filenameOrDir;
      const written = await handleFile(filename, path.dirname(filename));

      return written ? 1 : 0;
    }
  }

  let compiledFiles = 0;
  let startTime = null;

  const logSuccess = util.debounce(function () {
    if (startTime === null) {
      // This should never happen, but just in case it's better
      // to ignore the log message rather than making @babel/cli crash.
      return;
    }

    const diff = process.hrtime(startTime);

    console.log(
      `Successfully compiled ${compiledFiles} ${
        compiledFiles !== 1 ? "files" : "file"
      } with Babel (${diff[0] * 1e3 + Math.round(diff[1] / 1e6)}ms).`,
    );
    compiledFiles = 0;
    startTime = null;
  }, 100);

  if (cliOptions.watch) watcher.enable({ enableGlobbing: true });

  if (!cliOptions.skipInitialBuild) {
    if (cliOptions.deleteDirOnStart) {
      util.deleteDir(cliOptions.outDir);
    }

    fs.mkdirSync(cliOptions.outDir, { recursive: true });

    startTime = process.hrtime();

    for (const filename of cliOptions.filenames) {
      // compiledFiles is just incremented without reading its value, so we
      // don't risk race conditions.
      // eslint-disable-next-line require-atomic-updates
      compiledFiles += await handle(filename);
    }

    if (!cliOptions.quiet) {
      logSuccess();
      logSuccess.flush();
    }
  }

  if (cliOptions.watch) {
    // This, alongside with debounce, allows us to only log
    // when we are sure that all the files have been compiled.
    let processing = 0;
    const { filenames } = cliOptions;
    let getBase;
    if (filenames.length === 1) {
      // fast path: If there is only one filenames, we know it must be the base
      const base = filenames[0];
      const absoluteBase = path.resolve(base);
      getBase = filename => {
        return filename === absoluteBase ? path.dirname(base) : base;
      };
    } else {
      // A map from absolute compiled file path to its base, from which
      // the output destination will be determined
      const filenameToBaseMap: Map<string, string> = new Map(
        filenames.map(filename => {
          const absoluteFilename = path.resolve(filename);
          return [absoluteFilename, path.dirname(filename)];
        }),
      );

      const absoluteFilenames: Map<string, string> = new Map(
        filenames.map(filename => {
          const absoluteFilename = path.resolve(filename);
          return [absoluteFilename, filename];
        }),
      );

      const { sep } = path;
      // determine base from the absolute file path
      getBase = filename => {
        const base = filenameToBaseMap.get(filename);
        if (base !== undefined) {
          return base;
        }
        for (const [absoluteFilenameOrDir, relative] of absoluteFilenames) {
          if (filename.startsWith(absoluteFilenameOrDir + sep)) {
            filenameToBaseMap.set(filename, relative);
            return relative;
          }
        }
        // Can't determine the base, probably external deps
        return "";
      };
    }

    filenames.forEach(filenameOrDir => {
      watcher.watch(filenameOrDir);
    });

    watcher.onFilesChange(async filenames => {
      processing++;
      if (startTime === null) startTime = process.hrtime();

      try {
        const written = await Promise.all(
          filenames.map(filename => handleFile(filename, getBase(filename))),
        );

        compiledFiles += written.filter(Boolean).length;
      } catch (err) {
        console.error(err);
      }

      processing--;
      if (processing === 0 && !cliOptions.quiet) logSuccess();
    });
  }
}