text:
package com.twitter.algebird

import org.scalatest.{ PropSpec, Matchers, WordSpec }
import org.scalatest.prop.{ GeneratorDrivenPropertyChecks, PropertyChecks }
import org.scalacheck.{ Gen, Arbitrary }

import CMSHasherImplicits._

import scala.util.Random

class CmsLaws extends PropSpec with PropertyChecks with Matchers {
  import BaseProperties._

  val DELTA = 1E-8
  val EPS = 0.005
  val SEED = 1

  private def createArbitrary[K: Numeric](cmsMonoid: CMSMonoid[K]): Arbitrary[CMS[K]] = {
    val k = implicitly[Numeric[K]]
    Arbitrary {
      for (v <- Gen.choose(0, 10000)) yield cmsMonoid.create(k.fromInt(v))
    }
  }

  property("CountMinSketch[Short] is a Monoid") {
    implicit val cmsMonoid = CMS.monoid[Short](EPS, DELTA, SEED)
    implicit val cmsGen = createArbitrary[Short](cmsMonoid)
    monoidLaws[CMS[Short]]
  }

  property("CountMinSketch[Int] is a Monoid") {
    implicit val cmsMonoid = CMS.monoid[Int](EPS, DELTA, SEED)
    implicit val cmsGen = createArbitrary[Int](cmsMonoid)
    monoidLaws[CMS[Int]]
  }

  property("CountMinSketch[Long] is a Monoid") {
    implicit val cmsMonoid = CMS.monoid[Long](EPS, DELTA, SEED)
    implicit val cmsGen = createArbitrary[Long](cmsMonoid)
    monoidLaws[CMS[Long]]
  }

  property("CountMinSketch[BigInt] is a Monoid") {
    implicit val cmsMonoid = CMS.monoid[BigInt](EPS, DELTA, SEED)
    implicit val cmsGen = createArbitrary[BigInt](cmsMonoid)
    monoidLaws[CMS[BigInt]]
  }

}

class TopPctCmsLaws extends PropSpec with PropertyChecks with Matchers {
  import BaseProperties._

  val DELTA = 1E-8
  val EPS = 0.005
  val SEED = 1
  val HEAVY_HITTERS_PCT = 0.1

  private def createArbitrary[K: Numeric](cmsMonoid: TopPctCMSMonoid[K]): Arbitrary[TopCMS[K]] = {
    val k = implicitly[Numeric[K]]
    Arbitrary {
      for (v <- Gen.choose(0, 10000)) yield cmsMonoid.create(k.fromInt(v))
    }
  }

  property("TopPctCms[Short] is a Monoid") {
    implicit val cmsMonoid = TopPctCMS.monoid[Short](EPS, DELTA, SEED, HEAVY_HITTERS_PCT)
    implicit val cmsGen = createArbitrary[Short](cmsMonoid)
    monoidLaws[TopCMS[Short]]
  }

  property("TopPctCms[Int] is a Monoid") {
    implicit val cmsMonoid = TopPctCMS.monoid[Int](EPS, DELTA, SEED, HEAVY_HITTERS_PCT)
    implicit val cmsGen = createArbitrary[Int](cmsMonoid)
    monoidLaws[TopCMS[Int]]
  }

  property("TopPctCms[Long] is a Monoid") {
    implicit val cmsMonoid = TopPctCMS.monoid[Long](EPS, DELTA, SEED, HEAVY_HITTERS_PCT)
    implicit val cmsGen = createArbitrary[Long](cmsMonoid)
    monoidLaws[TopCMS[Long]]
  }

  property("TopPctCms[BigInt] is a Monoid") {
    implicit val cmsMonoid = TopPctCMS.monoid[BigInt](EPS, DELTA, SEED, HEAVY_HITTERS_PCT)
    implicit val cmsGen = createArbitrary[BigInt](cmsMonoid)
    monoidLaws[TopCMS[BigInt]]
  }

}

class CMSShortTest extends CMSTest[Short]
class CMSIntTest extends CMSTest[Int]
class CMSLongTest extends CMSTest[Long]
class CMSBigIntTest extends CMSTest[BigInt]

abstract class CMSTest[K: Ordering: CMSHasher: Numeric] extends WordSpec with Matchers with GeneratorDrivenPropertyChecks {

  import TestImplicits._

  val DELTA = 1E-10
  val EPS = 0.001
  val SEED = 1

  // We use TopPctCMS for testing CMSCounting functionality.  We argue that because TopPctCMS[K] encapsulates CMS[K]
  // and uses it for all its counting/querying functionality (like an adapter) we can test CMS[K] indirectly through
  // testing TopPctCMS[K].
  val COUNTING_CMS_MONOID = {
    val ANY_HEAVY_HITTERS_PCT = 0.1 // heavy hitters functionality is not relevant for the tests using this monoid
    TopPctCMS.monoid[K](EPS, DELTA, SEED, ANY_HEAVY_HITTERS_PCT)
  }

  val RAND = new scala.util.Random

  /**
   * Returns the exact frequency of {x} in {data}.
   */
  def exactFrequency(data: Seq[K], x: K): Long = data.count(_ == x)

  /**
   * Returns the exact inner product between two data streams, when the streams
   * are viewed as count vectors.
   */
  def exactInnerProduct(data1: Seq[K], data2: Seq[K]): Long = {
    val counts1 = data1.groupBy(x => x).mapValues(_.size)
    val counts2 = data2.groupBy(x => x).mapValues(_.size)

    (counts1.keys.toSet & counts2.keys.toSet).toSeq.map { k => counts1(k) * counts2(k) }.sum
  }

  /**
   * Returns the elements in {data} that appear at least heavyHittersPct * data.size times.
   */
  def exactHeavyHitters(data: Seq[K], heavyHittersPct: Double): Set[K] = {
    val counts = data.groupBy(x => x).mapValues(_.size)
    val totalCount = counts.values.sum
    counts.filter { _._2 >= heavyHittersPct * totalCount }.keys.toSet
  }

  /**
   * Creates a random data stream.
   *
   * @param size Number of stream elements.
   * @param range Elements are randomly drawn from [0, range).
   * @return
   */
  def createRandomStream(size: Int, range: Int, rnd: Random = RAND): Seq[K] = {
    require(size > 0)
    (1 to size).map { _ => rnd.nextInt(range) }.toK[K]
  }

  "A Count-Min sketch implementing CMSCounting" should {

    "count total number of elements in a stream" in {
      val totalCount = 1243
      val range = 234
      val data = createRandomStream(totalCount, range)
      val cms = COUNTING_CMS_MONOID.create(data)

      cms.totalCount should be(totalCount)
    }

    "estimate frequencies" in {
      val totalCount = 5678
      val range = 897
      val data = createRandomStream(totalCount, range)
      val cms = COUNTING_CMS_MONOID.create(data)

      (0 to 100).foreach { _ =>
        val x = RAND.nextInt(range).toK[K]
        val exact = exactFrequency(data, x)
        val approx = cms.frequency(x).estimate
        val estimationError = approx - exact
        val maxError = approx - cms.frequency(x).min
        val beWithinTolerance = be >= 0L and be <= maxError

        approx should be >= exact
        estimationError should beWithinTolerance
      }
    }

    "exactly compute frequencies in a small stream" in {
      val one = COUNTING_CMS_MONOID.create(1.toK[K])
      one.frequency(1.toK[K]).estimate should be(1)
      one.frequency(2.toK[K]).estimate should be(0)
      val two = COUNTING_CMS_MONOID.create(2.toK[K])
      two.frequency(1.toK[K]).estimate should be(0)
      two.frequency(2.toK[K]).estimate should be(1)
      val cms = COUNTING_CMS_MONOID.plus(COUNTING_CMS_MONOID.plus(one, two), two)

      cms.frequency(0.toK[K]).estimate should be(0)
      cms.frequency(1.toK[K]).estimate should be(1)
      cms.frequency(2.toK[K]).estimate should be(2)

      val three = COUNTING_CMS_MONOID.create(Seq(1, 1, 1).toK[K])
      three.frequency(1.toK[K]).estimate should be(3)
      val four = COUNTING_CMS_MONOID.create(Seq(1, 1, 1, 1).toK[K])
      four.frequency(1.toK[K]).estimate should be(4)
      val cms2 = COUNTING_CMS_MONOID.plus(four, three)
      cms2.frequency(1.toK[K]).estimate should be(7)
    }

    "estimate inner products" in {
      val totalCounts = Gen.choose(1, 10000)
      val ranges = Gen.choose(100, 2000)

      forAll((totalCounts, "totalCount"), (ranges, "range"), minSuccessful(50)) { (totalCount: Int, range: Int) =>
        val data1 = createRandomStream(totalCount, range)
        val data2 = createRandomStream(totalCount, range)
        val cms1 = COUNTING_CMS_MONOID.create(data1)
        val cms2 = COUNTING_CMS_MONOID.create(data2)

        val approxA = cms1.innerProduct(cms2)
        val approx = approxA.estimate
        val exact = exactInnerProduct(data1, data2)
        val estimationError = approx - exact
        val maxError = approx - approxA.min
        val beWithinTolerance = be >= 0L and be <= maxError

        // We do not support negative counts, hence the lower limit of a frequency is 0 but never negative.
        approxA.min should be >= 0L

        approx should be(cms2.innerProduct(cms1).estimate)
        approx should be >= exact
        estimationError should beWithinTolerance
      }
    }

    "exactly compute inner product of small streams" in {
      // Nothing in common.
      val a1 = List(1, 2, 3).toK[K]
      val a2 = List(4, 5, 6).toK[K]
      COUNTING_CMS_MONOID.create(a1).innerProduct(COUNTING_CMS_MONOID.create(a2)).estimate should be(0)

      // One element in common.
      val b1 = List(1, 2, 3).toK[K]
      val b2 = List(3, 5, 6).toK[K]
      COUNTING_CMS_MONOID.create(b1).innerProduct(COUNTING_CMS_MONOID.create(b2)).estimate should be(1)

      // Multiple, non-repeating elements in common.
      val c1 = List(1, 2, 3).toK[K]
      val c2 = List(3, 2, 6).toK[K]
      COUNTING_CMS_MONOID.create(c1).innerProduct(COUNTING_CMS_MONOID.create(c2)).estimate should be(2)

      // Multiple, repeating elements in common.
      val d1 = List(1, 2, 2, 3, 3).toK[K]
      val d2 = List(2, 3, 3, 6).toK[K]
      COUNTING_CMS_MONOID.create(d1).innerProduct(COUNTING_CMS_MONOID.create(d2)).estimate should be(6)
    }

    "work as an Aggregator when created from a single, small stream" in {
      val data1 = Seq(1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5).toK[K]

      val cms = CMS.aggregator[K](EPS, DELTA, SEED).apply(data1)
      cms.frequency(1.toK[K]).estimate should be(1L)
      cms.frequency(2.toK[K]).estimate should be(2L)
      cms.frequency(3.toK[K]).estimate should be(3L)
      cms.frequency(4.toK[K]).estimate should be(4L)
      cms.frequency(5.toK[K]).estimate should be(5L)

      val topPctCMS = {
        val anyHeavyHittersPct = 0.1 // exact setting not relevant for this test
        TopPctCMS.aggregator[K](EPS, DELTA, SEED, anyHeavyHittersPct).apply(data1)
      }
      topPctCMS.frequency(1.toK[K]).estimate should be(1L)
      topPctCMS.frequency(2.toK[K]).estimate should be(2L)
      topPctCMS.frequency(3.toK[K]).estimate should be(3L)
      topPctCMS.frequency(4.toK[K]).estimate should be(4L)
      topPctCMS.frequency(5.toK[K]).estimate should be(5L)

      val topNCMS = {
        val anyHeavyHittersN = 1 // exact setting not relevant for this test
        TopNCMS.aggregator[K](EPS, DELTA, SEED, anyHeavyHittersN).apply(data1)
      }
      topNCMS.frequency(1.toK[K]).estimate should be(1L)
      topNCMS.frequency(2.toK[K]).estimate should be(2L)
      topNCMS.frequency(3.toK[K]).estimate should be(3L)
      topNCMS.frequency(4.toK[K]).estimate should be(4L)
      topNCMS.frequency(5.toK[K]).estimate should be(5L)
    }

  }

  "A Top-% Count-Min sketch implementing CMSHeavyHitters" should {

    "create correct sketches out of a single item" in {
      forAll{ (x: Int) =>
        val data = x.toK[K]
        val cmsMonoid = {
          val anyHeavyHittersPct = 0.1 // exact setting not relevant for this test
          TopPctCMS.monoid[K](EPS, DELTA, SEED, anyHeavyHittersPct)
        }
        val topCms = cmsMonoid.create(data)
        topCms.totalCount should be(1)
        topCms.cms.totalCount should be(1)
        topCms.frequency(x.toK[K]).estimate should be(1)
        // Poor man's way to come up with an item that is not x and that is very unlikely to hash to the same slot.
        val otherItem = x + 1
        topCms.frequency(otherItem.toK[K]).estimate should be(0)
        // The following assert indirectly verifies whether the counting table is not all-zero (cf. GH-393).
        topCms.innerProduct(topCms).estimate should be(1)
      }
    }

    "create correct sketches out of a single-item stream" in {
      forAll{ (x: Int) =>
        val data = Seq(x).toK[K]
        val cmsMonoid = {
          val anyHeavyHittersPct = 0.1 // exact setting not relevant for this test
          TopPctCMS.monoid[K](EPS, DELTA, SEED, anyHeavyHittersPct)
        }
        val topCms = cmsMonoid.create(data)
        topCms.totalCount should be(1)
        topCms.cms.totalCount should be(1)
        topCms.frequency(x.toK[K]).estimate should be(1)
        // Poor man's way to come up with an item that is not x and that is very unlikely to hash to the same slot.
        val otherItem = x + 1
        topCms.frequency(otherItem.toK[K]).estimate should be(0)
        // The following assert indirectly verifies whether the counting table is not all-zero (cf. GH-393).
        topCms.innerProduct(topCms).estimate should be(1)
      }
    }

    "estimate heavy hitters" in {
      // Simple way of making some elements appear much more often than others.
      val data1 = (1 to 3000).map { _ => RAND.nextInt(3) }.toK[K]
      val data2 = (1 to 3000).map { _ => RAND.nextInt(10) }.toK[K]
      val data3 = (1 to 1450).map { _ => -1 }.toK[K] // element close to being a 20% heavy hitter
      val data = data1 ++ data2 ++ data3

      // Find elements that appear at least 20% of the time.
      val heavyHittersPct = 0.2
      val cms = TopPctCMS.monoid[K](EPS, DELTA, SEED, 0.2).create(data)

      val trueHhs = exactHeavyHitters(data, heavyHittersPct)
      val estimatedHhs = cms.heavyHitters

      // All true heavy hitters must be claimed as heavy hitters.
      trueHhs.intersect(estimatedHhs) should be(trueHhs)

      // It should be very unlikely that any element with count less than
      // (heavyHittersPct - eps) * totalCount is claimed as a heavy hitter.
      val minHhCount = (heavyHittersPct - cms.eps) * cms.totalCount
      val infrequent = data.groupBy { x => x }.mapValues { _.size }.filter { _._2 < minHhCount }.keys.toSet
      infrequent.intersect(estimatedHhs) should be('empty)
    }

    "(when adding CMS instances) drop old heavy hitters when new heavy hitters replace them" in {
      val monoid = TopPctCMS.monoid[K](EPS, DELTA, SEED, 0.3)
      val cms1 = monoid.create(Seq(1, 2, 2).toK[K])
      cms1.heavyHitters should be(Set(1, 2))

      val cms2 = cms1 ++ monoid.create(2.toK[K])
      cms2.heavyHitters should be(Set(2))

      val cms3 = cms2 ++ monoid.create(1.toK[K])
      cms3.heavyHitters should be(Set(1, 2))

      val cms4 = cms3 ++ monoid.create(Seq(0, 0, 0, 0, 0, 0).toK[K])
      cms4.heavyHitters should be(Set(0))
    }

    "(when adding individual items) drop old heavy hitters when new heavy hitters replace them" in {
      val monoid = TopPctCMS.monoid[K](EPS, DELTA, SEED, 0.3)
      val cms1 = monoid.create(Seq(1, 2, 2).toK[K])
      cms1.heavyHitters should be(Set(1, 2))

      val cms2 = cms1 + 2.toK[K]
      cms2.heavyHitters should be(Set(2))

      val cms3 = cms2 + 1.toK[K]
      cms3.heavyHitters should be(Set(1, 2))

      val heaviest = 0.toK[K]
      val cms4 = cms3 + heaviest + heaviest + heaviest + heaviest + heaviest + heaviest
      cms4.heavyHitters should be(Set(heaviest))
    }

    "(when adding CMS instances) merge heavy hitters correctly [GH-353 regression test]" in {
      // See https://github.com/twitter/algebird/issues/353
      val monoid = TopPctCMS.monoid(EPS, DELTA, SEED, 0.1)

      val data1 = Seq(1, 1, 1, 2, 2, 3).toK[K]
      val data2 = Seq(3, 4, 4, 4, 5, 5).toK[K]
      val data3 = Seq(3, 6, 6, 6, 7, 7).toK[K]
      val data4 = Seq(3, 8, 8, 8, 9, 9).toK[K]
      val singleData = data1 ++ data2 ++ data3 ++ data4

      /*
        Data sets from above shown in tabular view

        Item    1   2   3   4   total (= singleData)
        ----------------------------------------
        A (1)   3   -   -   -   3
        B (2)   2   -   -   -   2
        C (3)   1   1   1   1   4  <<< C is global top 1 heavy hitter
        D (4)   -   3   -   -   3
        E (5)   -   2   -   -   2
        F (6)   -   -   3   -   3
        G (7)   -   -   2   -   2
        H (8)   -   -   -   3   3
        I (9)   -   -   -   2   2

       */

      val cms1 = monoid.create(data1)
      val cms2 = monoid.create(data2)
      val cms3 = monoid.create(data3)
      val cms4 = monoid.create(data4)
      val aggregated = cms1 ++ cms2 ++ cms3 ++ cms4

      val single = monoid.create(singleData)
      aggregated.heavyHitters should be(single.heavyHitters)
      aggregated.heavyHitters contains (3.toK[K]) // C=3 is global top 1 heavy hitter
    }

    "exactly compute heavy hitters when created from a single, small stream" in {
      val data1 = Seq(1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5).toK[K]

      val cms1 = TopPctCMS.monoid[K](EPS, DELTA, SEED, 0.01).create(data1)
      cms1.heavyHitters should be(Set(1, 2, 3, 4, 5))

      val cms2 = TopPctCMS.monoid[K](EPS, DELTA, SEED, 0.1).create(data1)
      cms2.heavyHitters should be(Set(2, 3, 4, 5))

      val cms3 = TopPctCMS.monoid[K](EPS, DELTA, SEED, 0.3).create(data1)
      cms3.heavyHitters should be(Set(5))

      val cms4 = TopPctCMS.monoid[K](EPS, DELTA, SEED, 0.9).create(data1)
      cms4.heavyHitters should be(Set[K]())
    }

    "work as an Aggregator when created from a single, small stream" in {
      val data1 = Seq(1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5).toK[K]

      val cms1 = TopPctCMS.aggregator[K](EPS, DELTA, SEED, 0.01).apply(data1)
      cms1.heavyHitters should be(Set(1, 2, 3, 4, 5))

      val cms2 = TopPctCMS.aggregator[K](EPS, DELTA, SEED, 0.1).apply(data1)
      cms2.heavyHitters should be(Set(2, 3, 4, 5))

      val cms3 = TopPctCMS.aggregator[K](EPS, DELTA, SEED, 0.3).apply(data1)
      cms3.heavyHitters should be(Set(5))

      val cms4 = TopPctCMS.aggregator[K](EPS, DELTA, SEED, 0.9).apply(data1)
      cms4.heavyHitters should be(Set[K]())
    }

  }

  "A Top-N Count-Min sketch implementing CMSHeavyHitters" should {

    // Note: As described in https://github.com/twitter/algebird/issues/353, a top-N CMS is, in general, not able to
    // merge heavy hitters correctly.  This is because merging top-N based heavy hitters is not an associative
    // operation.

    "create correct sketches out of a single item" in {
      forAll{ (x: Int) =>
        val data = x.toK[K]
        val cmsMonoid = {
          val anyHeavyHittersN = 2 // exact setting not relevant for this test
          TopNCMS.monoid[K](EPS, DELTA, SEED, anyHeavyHittersN)
        }
        val topCms = cmsMonoid.create(data)
        topCms.totalCount should be(1)
        topCms.cms.totalCount should be(1)
        topCms.frequency(x.toK[K]).estimate should be(1)
        // Poor man's way to come up with an item that is not x and that is very unlikely to hash to the same slot.
        val otherItem = x + 1
        topCms.frequency(otherItem.toK[K]).estimate should be(0)
        // The following assert indirectly verifies whether the counting table is not all-zero (cf. GH-393).
        topCms.innerProduct(topCms).estimate should be(1)
      }
    }

    "create correct sketches out of a single-item stream" in {
      forAll{ (x: Int) =>
        val data = Seq(x).toK[K]
        val cmsMonoid = {
          val anyHeavyHittersN = 2 // exact setting not relevant for this test
          TopNCMS.monoid[K](EPS, DELTA, SEED, anyHeavyHittersN)
        }
        val topCms = cmsMonoid.create(data)
        topCms.totalCount should be(1)
        topCms.cms.totalCount should be(1)
        topCms.frequency(x.toK[K]).estimate should be(1)
        // Poor man's way to come up with an item that is not x and that is very unlikely to hash to the same slot.
        val otherItem = x + 1
        topCms.frequency(otherItem.toK[K]).estimate should be(0)
        // The following assert indirectly verifies whether the counting table is not all-zero (cf. GH-393).
        topCms.innerProduct(topCms).estimate should be(1)
      }
    }

    // This test involves merging of top-N CMS instances, which is not an associative operation.  This means that the
    // success or failure of this test depends on the merging order and/or the test data characteristics.
    "(when adding CMS instances) drop old heavy hitters when new heavy hitters replace them, if merge order matches data" in {
      val heavyHittersN = 2
      val monoid = TopNCMS.monoid[K](EPS, DELTA, SEED, heavyHittersN)
      val cms1 = monoid.create(Seq(1, 2, 2).toK[K])
      cms1.heavyHitters should be(Set(1, 2))
      val cms2 = cms1 ++ monoid.create(Seq(3, 3, 3).toK[K])
      cms2.heavyHitters should be(Set(2, 3))
      val cms3 = cms2 ++ monoid.create(Seq(1, 1, 1).toK[K])
      cms3.heavyHitters should be(Set(3, 1))
      val cms4 = cms3 ++ monoid.create(Seq(6, 6, 6, 6, 6, 6).toK[K])
      cms4.heavyHitters should be(Set(1, 6))
    }

    "(when adding individual items) drop old heavy hitters when new heavy hitters replace them" in {
      val monoid = TopPctCMS.monoid[K](EPS, DELTA, SEED, 0.3)
      val cms1 = monoid.create(Seq(1, 2, 2).toK[K])
      cms1.heavyHitters should be(Set(1, 2))

      val cms2 = cms1 + 2.toK[K]
      cms2.heavyHitters should be(Set(2))

      val cms3 = cms2 + 1.toK[K]
      cms3.heavyHitters should be(Set(1, 2))

      val heaviest = 0.toK[K]
      val cms4 = cms3 + heaviest + heaviest + heaviest + heaviest + heaviest + heaviest
      cms4.heavyHitters should be(Set(heaviest))
    }

    // This test documents the order bias of top-N CMS, i.e. it's a negative test case.
    // See https://github.com/twitter/algebird/issues/353
    "(when adding CMS instances) generally FAIL to merge heavy hitters correctly due to order bias" in {
      val topN = 2
      val monoid = TopNCMS.monoid(EPS, DELTA, SEED, topN)

      val data1 = Seq(1, 1, 1, 2, 2, 3).toK[K]
      val data2 = Seq(3, 4, 4, 4, 5, 5).toK[K]
      val data3 = Seq(3, 6, 6, 6, 7, 7).toK[K]
      val data4 = Seq(3, 8, 8, 8, 9, 9).toK[K]
      val singleData = data1 ++ data2 ++ data3 ++ data4

      /*
        Data sets from above shown in tabular view

        Item    1   2   3   4   total (= singleData)
        ----------------------------------------
        A (1)   3   -   -   -   3
        B (2)   2   -   -   -   2
        C (3)   1   1   1   1   4  <<< C is global top 1 heavy hitter
        D (4)   -   3   -   -   3
        E (5)   -   2   -   -   2
        F (6)   -   -   3   -   3
        G (7)   -   -   2   -   2
        H (8)   -   -   -   3   3
        I (9)   -   -   -   2   2

       */

      val cms1 = monoid.create(data1)
      val cms2 = monoid.create(data2)
      val cms3 = monoid.create(data3)
      val cms4 = monoid.create(data4)
      val aggregated = cms1 ++ cms2 ++ cms3 ++ cms4

      val single = monoid.create(singleData)
      aggregated.heavyHitters shouldNot be(single.heavyHitters)
      aggregated.heavyHitters shouldNot contain(3.toK[K]) // C=3 is global top 1 heavy hitter
    }

    // Compared to adding top-N CMS instances, which is generally unsafe because of order bias (see test cases above),
    // adding individual items to a top-N CMS is a safe operation.
    // See https://github.com/twitter/algebird/issues/353
    "(when adding individual items) merge heavy hitters correctly [GH-353 regression test]" in {
      val topN = 2
      val monoid = TopNCMS.monoid(EPS, DELTA, SEED, topN)

      val data1 = Seq(1, 1, 1, 2, 2, 3).toK[K]
      val data2 = Seq(3, 4, 4, 4, 5, 5).toK[K]
      val data3 = Seq(3, 6, 6, 6, 7, 7).toK[K]
      val data4 = Seq(3, 8, 8, 8, 9, 9).toK[K]
      val singleData = data1 ++ data2 ++ data3 ++ data4

      /*
        Data sets from above shown in tabular view

        Item    1   2   3   4   total (= singleData)
        ----------------------------------------
        A (1)   3   -   -   -   3
        B (2)   2   -   -   -   2
        C (3)   1   1   1   1   4  <<< C is global top 1 heavy hitter
        D (4)   -   3   -   -   3
        E (5)   -   2   -   -   2
        F (6)   -   -   3   -   3
        G (7)   -   -   2   -   2
        H (8)   -   -   -   3   3
        I (9)   -   -   -   2   2

       */

      val cms1 = monoid.create(data1)
      val cms2 = cms1 + 3.toK[K] + 4.toK[K] + 4.toK[K] + 4.toK[K] + 5.toK[K] + 5.toK[K] // effectively "++ data2"
      val cms3 = cms2 + 3.toK[K] + 6.toK[K] + 6.toK[K] + 6.toK[K] + 7.toK[K] + 7.toK[K] // "++ data3"
      val aggregated = cms3 + 3.toK[K] + 8.toK[K] + 8.toK[K] + 8.toK[K] + 9.toK[K] + 9.toK[K] // "++ data4"

      val single = monoid.create(singleData)
      aggregated.heavyHitters should be(single.heavyHitters)
      aggregated.heavyHitters should contain(3.toK[K]) // C=3 is global top 1 heavy hitter
    }

    "exactly compute heavy hitters when created a from single, small stream" in {
      val data1 = Seq(1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5).toK[K]

      val cms1 = TopNCMS.monoid[K](EPS, DELTA, SEED, 5).create(data1)
      cms1.heavyHitters should be(Set(1, 2, 3, 4, 5))

      val cms2 = TopNCMS.monoid[K](EPS, DELTA, SEED, 4).create(data1)
      cms2.heavyHitters should be(Set(2, 3, 4, 5))

      val cms3 = TopNCMS.monoid[K](EPS, DELTA, SEED, 3).create(data1)
      cms3.heavyHitters should be(Set(3, 4, 5))

      val cms4 = TopNCMS.monoid[K](EPS, DELTA, SEED, 2).create(data1)
      cms4.heavyHitters should be(Set(4, 5))

      val cms5 = TopNCMS.monoid[K](EPS, DELTA, SEED, 1).create(data1)
      cms5.heavyHitters should be(Set(5))
    }

    "work as an Aggregator when created from a single, small stream" in {
      val data1 = Seq(1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5).toK[K]

      val cms1 = TopNCMS.aggregator[K](EPS, DELTA, SEED, 5).apply(data1)
      cms1.heavyHitters should be(Set(1, 2, 3, 4, 5))

      val cms2 = TopNCMS.aggregator[K](EPS, DELTA, SEED, 4).apply(data1)
      cms2.heavyHitters should be(Set(2, 3, 4, 5))

      val cms3 = TopNCMS.aggregator[K](EPS, DELTA, SEED, 3).apply(data1)
      cms3.heavyHitters should be(Set(3, 4, 5))

      val cms4 = TopNCMS.aggregator[K](EPS, DELTA, SEED, 2).apply(data1)
      cms4.heavyHitters should be(Set(4, 5))

      val cms5 = TopNCMS.aggregator[K](EPS, DELTA, SEED, 1).apply(data1)
      cms5.heavyHitters should be(Set(5))
    }

  }

}

class CMSFunctionsSpec extends PropSpec with PropertyChecks with Matchers {

  property("roundtrips width->eps->width") {
    forAll { (i: Int) =>
      whenever(i > 0) {
        CMSFunctions.width(CMSFunctions.eps(i)) should be(i)
      }
    }
  }

  property("roundtrips depth->delta->depth for common depth values") {
    // For all i > 709 this test break because of precision limits:  For all i > 709 will return 0.0, which is not the
    // mathematically correct value but rather the asymptote of delta.
    val maxI = 709
    forAll((Gen.choose(1, maxI), "depth")) { (i: Int) =>
      CMSFunctions.depth(CMSFunctions.delta(i)) should be(i)
    }
  }

  // Documents a precision error that is exposed by all depths > 709.
  // For all i > 709, CMSFunctions.delta(i) will return 0.0, which is not the mathematically correct value but rather
  // the asymptote of the delta function.
  property("throw IAE when deriving delta from invalid depth values") {
    val maxValidDelta = 709
    forAll(Gen.choose(maxValidDelta + 1, 10000)) { (invalidDepth: Int) =>
      val exception = intercept[IllegalArgumentException] {
        CMSFunctions.delta(invalidDepth)
      }
      exception.getMessage should fullyMatch regex
        """requirement failed: depth must be smaller as it causes precision errors when computing delta \(\d+ led to an invalid delta of 0.0\)"""
    }
  }

  property("throw IAE when deriving depth from invalid delta values") {
    val invalidDeltas = Table("invalidDelta", 0.0, 1E-330, 1E-400)
    forAll(invalidDeltas) { (invalidDelta: Double) =>
      val exception = intercept[IllegalArgumentException] {
        CMSFunctions.depth(invalidDelta)
      }
      exception.getMessage should be("requirement failed: delta must lie in (0, 1)")
    }
  }

}

class CMSParamsSpec extends PropSpec with PropertyChecks with Matchers {

  val AnyEps = 0.001
  val AnyDelta = 1E-5
  val AnyHashes = {
    val AnySeed = 1
    CMSFunctions.generateHashes[Long](AnyEps, AnyDelta, AnySeed)
  }

  property("throw IAE for invalid eps values") {
    val invalidEpsilons = Table("invalidEps", 0.0, 1.0, 2.0, 100.0)
    forAll(invalidEpsilons) { (invalidEps: Double) =>
      val exception = intercept[IllegalArgumentException] {
        CMSParams(AnyHashes, invalidEps, AnyDelta)
      }
      exception.getMessage should be("requirement failed: eps must lie in (0, 1)")
    }
  }

  property("throw IAE for invalid delta values") {
    val invalidDeltas = Table("invalidDelta", 0.0, 1.0, 2.0, 100.0, 1E-330, 1E-400)
    forAll(invalidDeltas) { (invalidDelta: Double) =>
      val exception = intercept[IllegalArgumentException] {
        CMSParams(AnyHashes, AnyEps, invalidDelta)
      }
      exception.getMessage should be("requirement failed: delta must lie in (0, 1)")
    }
  }

  property("throw IAE when we do not have enough hashes") {
    val tooFewHashes = Seq.empty[CMSHash[Long]]
    val exception = intercept[IllegalArgumentException] {
      CMSParams(tooFewHashes, AnyEps, AnyDelta)
    }
    exception.getMessage should fullyMatch regex """requirement failed: we require at least (\d+) hash functions"""
  }

}

class CMSHasherShortSpec extends CMSHasherSpec[Short]
class CMSHasherIntSpec extends CMSHasherSpec[Int]
class CMSHasherLongSpec extends CMSHasherSpec[Long]
class CMSHasherBigIntSpec extends CMSHasherSpec[BigInt]

abstract class CMSHasherSpec[K: CMSHasher: Numeric] extends PropSpec with PropertyChecks with Matchers {

  import TestImplicits._

  property("returns positive hashes (i.e. slots) only") {
    forAll { (a: Int, b: Int, width: Int, x: Int) =>
      whenever (width > 0) {
        val hash = CMSHash[K](a, b, width)
        hash(x.toK[K]) should be >= 0
      }
    }
  }

}

/**
 * This spec verifies that we provide legacy types for the CMS and CountMinSketchMonoid classes we had in Algebird
 * versions < 0.8.1.  Note that this spec is not meant to verify their actual functionality.
 */
class LegacyCMSSpec extends WordSpec with Matchers {

  import legacy.CountMinSketchMonoid

  val DELTA = 1E-10
  val EPS = 0.001
  val SEED = 1

  val CMS_MONOID: CountMinSketchMonoid = CountMinSketchMonoid(EPS, DELTA, SEED)

  "The legacy package" should {

    "provide a legacy type for the CMS implementation in Algebird versions < 0.8.1" in {
      val cms: legacy.CMS = CMS_MONOID.create(Seq(0L, 0L))
      cms.frequency(0L).estimate should be (2)
      cms.heavyHitters should be(Set(0L))
    }

    "provide a legacy type for the CMS monoid implementation in Algebird versions < 0.8.1" in {
      val cmsMonoid: CountMinSketchMonoid = {
        val eps = 0.001
        val delta = 1E-5
        val seed = 1
        val heavyHittersPct = 0.1
        CountMinSketchMonoid(eps, delta, seed, heavyHittersPct)
      }
      val cms = cmsMonoid.create(Seq(0L, 0L))
      cms.frequency(0L).estimate should be (2)
      cms.heavyHitters should be(Set(0L))
    }

  }

}

object TestImplicits {

  // Convenience methods to convert from `Int` to the actual `K` type, and we prefer these conversions to be explicit
  // (cf. JavaConverters vs. JavaConversions). We use the name `toK` to clarify the intent and to prevent name conflicts
  // with the existing `to[Col]` method in Scala.
  implicit class IntCast(x: Int) {
    def toK[A: Numeric]: A = implicitly[Numeric[A]].fromInt(x)
  }

  implicit class SeqCast(xs: Seq[Int]) {
    def toK[A: Numeric]: Seq[A] = xs map { _.toK[A] }
  }

  implicit class SetCast(xs: Set[Int]) {
    def toK[A: Numeric]: Set[A] = xs map { _.toK[A] }
  }

}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QL_BanHang.Model;
using QL_BanHang.Obiect;

namespace QL_BanHang.Control
{
    class NhanVienCtr
    {
        NhanVienMod nvMod = new NhanVienMod();
        public DataTable GetData()
        {
            return nvMod.GetData();
        }
        public bool AddData(NhanVienObj nvObj)
        {
            return nvMod.AddData(nvObj);
        }
        public bool UpdData(NhanVienObj nvObj)
        {
            return nvMod.UpdData(nvObj);
        }
        public bool UpdMK(NhanVienObj nvObj)
        {
            return nvMod.UpdMK(nvObj);
        }
        public bool DelData(string ma)
        {
            return nvMod.DelData(ma);
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
package org.elasticsearch.index.mapper;

import org.apache.lucene.search.Query;
import org.apache.lucene.util.SetOnce;
import org.elasticsearch.common.CheckedConsumer;
import org.elasticsearch.common.Explicit;
import org.elasticsearch.common.geo.GeoJsonGeometryFormat;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.support.MapXContentParser;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.query.SearchExecutionContext;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * Base field mapper class for all spatial field types
 */
public abstract class AbstractGeometryFieldMapper<T> extends FieldMapper {

    public static Parameter<Explicit<Boolean>> ignoreMalformedParam(Function<FieldMapper, Explicit<Boolean>> initializer,
                                                                    boolean ignoreMalformedByDefault) {
        return Parameter.explicitBoolParam("ignore_malformed", true, initializer, ignoreMalformedByDefault);
    }

    public static Parameter<Explicit<Boolean>> ignoreZValueParam(Function<FieldMapper, Explicit<Boolean>> initializer) {
        return Parameter.explicitBoolParam("ignore_z_value", true, initializer, true);
    }

    /**
     * Interface representing parser in geometry indexing pipeline.
     */
    public abstract static class Parser<T> {
        /**
         * Parse the given xContent value to one or more objects of type {@link T}. The value can be
         * in any supported format.
         */
        public abstract void parse(
            XContentParser parser,
            CheckedConsumer<T, IOException> consumer,
            Consumer<Exception> onMalformed) throws IOException;

        /**
         * Given a parsed value and a format string, formats the value into a plain Java object.
         *
         * Supported formats include 'geojson' and 'wkt'. The different formats are defined
         * as subclasses of {@link org.elasticsearch.common.geo.GeometryFormat}.
         */
        public abstract Object format(T value, String format);

        private void fetchFromSource(Object sourceMap, Consumer<Object> consumer, String format) {
            try (XContentParser parser = MapXContentParser.wrapObject(sourceMap)) {
                parse(parser, v -> consumer.accept(format(v, format)), e -> {}); /* ignore malformed */
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    }

    public abstract static class AbstractGeometryFieldType extends MappedFieldType {

        protected final Parser<?> geometryParser;
        protected final boolean parsesArrayValue;

        protected AbstractGeometryFieldType(String name, boolean indexed, boolean stored, boolean hasDocValues,
                                            boolean parsesArrayValue, Parser<?> geometryParser, Map<String, String> meta) {
            super(name, indexed, stored, hasDocValues, TextSearchInfo.NONE, meta);
            this.parsesArrayValue = parsesArrayValue;
            this.geometryParser = geometryParser;
        }

        @Override
        public final Query termQuery(Object value, SearchExecutionContext context) {
            throw new IllegalArgumentException("Geometry fields do not support exact searching, use dedicated geometry queries instead: ["
                    + name() + "]");
        }

        @Override
        public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
            String geoFormat = format != null ? format : GeoJsonGeometryFormat.NAME;

            if (parsesArrayValue) {
                return new ArraySourceValueFetcher(name(), context) {
                    @Override
                    protected Object parseSourceValue(Object value) {
                        List<Object> values = new ArrayList<>();
                        geometryParser.fetchFromSource(value, values::add, geoFormat);
                        return values;
                    }
                };
            } else {
                return new SourceValueFetcher(name(), context) {
                    @Override
                    protected Object parseSourceValue(Object value) {
                        SetOnce<Object> holder = new SetOnce<>();
                        geometryParser.fetchFromSource(value, holder::set, geoFormat);
                        return holder.get();
                    }
                };
            }
        }
    }

    private final Explicit<Boolean> ignoreMalformed;
    private final Explicit<Boolean> ignoreZValue;
    private final Parser<? extends T> parser;

    protected AbstractGeometryFieldMapper(String simpleName, MappedFieldType mappedFieldType,
                                          Map<String, NamedAnalyzer> indexAnalyzers,
                                          Explicit<Boolean> ignoreMalformed, Explicit<Boolean> ignoreZValue,
                                          MultiFields multiFields, CopyTo copyTo,
                                          Parser<? extends T> parser) {
        super(simpleName, mappedFieldType, indexAnalyzers, multiFields, copyTo, false, null);
        this.ignoreMalformed = ignoreMalformed;
        this.ignoreZValue = ignoreZValue;
        this.parser = parser;
    }

    protected AbstractGeometryFieldMapper(String simpleName, MappedFieldType mappedFieldType,
                                          Explicit<Boolean> ignoreMalformed, Explicit<Boolean> ignoreZValue,
                                          MultiFields multiFields, CopyTo copyTo,
                                          Parser<? extends T> parser) {
        this(simpleName, mappedFieldType, Collections.emptyMap(), ignoreMalformed, ignoreZValue, multiFields, copyTo, parser);
    }

    protected AbstractGeometryFieldMapper(
        String simpleName,
        MappedFieldType mappedFieldType,
        MultiFields multiFields,
        CopyTo copyTo,
        Parser<? extends T> parser,
        String onScriptError
    ) {
        super(simpleName, mappedFieldType, Collections.emptyMap(), multiFields, copyTo, true, onScriptError);
        this.ignoreMalformed = new Explicit<>(false, true);
        this.ignoreZValue = new Explicit<>(false, true);
        this.parser = parser;
    }

    @Override
    public AbstractGeometryFieldType fieldType() {
        return (AbstractGeometryFieldType) mappedFieldType;
    }

    @Override
    protected void parseCreateField(ParseContext context) throws IOException {
        throw new UnsupportedOperationException("Parsing is implemented in parse(), this method should NEVER be called");
    }

    /**
     * Build an index document using a parsed geometry
     * @param context   the ParseContext holding the document
     * @param geometry  the parsed geometry object
     */
    protected abstract void index(ParseContext context, T geometry) throws IOException;

    @Override
    public final void parse(ParseContext context) throws IOException {
        if (hasScript) {
            throw new MapperParsingException("failed to parse field [" + fieldType().name() + "] of type + " + contentType() + "]",
                new IllegalArgumentException("Cannot index data directly into a field with a [script] parameter"));
        }
        parser.parse(context.parser(), v -> index(context, v), e -> {
            if (ignoreMalformed()) {
                context.addIgnoredField(fieldType().name());
            } else {
                throw new MapperParsingException(
                    "failed to parse field [" + fieldType().name() + "] of type [" + contentType() + "]", e
                );
            }
        });
    }

    public boolean ignoreMalformed() {
        return ignoreMalformed.value();
    }

    public boolean ignoreZValue() {
        return ignoreZValue.value();
    }
}


text:
package org.devgateway.ocds.persistence.mongo.spring;

import java.util.List;

/**
 * @author idobre
 * @since 5/20/16
 * <p>
 * Service that imports Excel sheets in OCDS format
 */
public interface ExcelImportService extends ImportService {

    ImportResult importAllSheets(List<String> fileTypes, byte[] prototypeDatabase, byte[]
            locations, byte[] publicInstitutionsSuppliers, byte[] cdg, Boolean purgeDatabase,
                                 Boolean validateData, Boolean flagData) throws InterruptedException;
}


text:
package gov.nih.nci.ispy.service.findings;

import gov.nih.nci.caintegrator.analysis.messaging.AnalysisResult;
import gov.nih.nci.caintegrator.analysis.messaging.CategoricalCorrelationRequest;
import gov.nih.nci.caintegrator.analysis.messaging.CategoricalCorrelationResult;
import gov.nih.nci.caintegrator.analysis.messaging.DataPointVector;
import gov.nih.nci.caintegrator.enumeration.FindingStatus;
import gov.nih.nci.caintegrator.service.findings.AnalysisFinding;
import gov.nih.nci.ispy.service.clinical.ContinuousType;

import java.util.List;

public class ISPYCategoricalCorrelationFinding extends AnalysisFinding {

	private CategoricalCorrelationRequest catCorrRequest;
	private CategoricalCorrelationResult catCorrResult;
	private ContinuousType contType;

	public ISPYCategoricalCorrelationFinding(String session, String task, FindingStatus status) {
		super(session, task, status);
	}

	private static final long serialVersionUID = 1L;

	public void setAnalysisResult(AnalysisResult results) throws ClassCastException{
		super.setAnalysisResult(results);
		this.catCorrResult = (CategoricalCorrelationResult)results;
	}

	public List<DataPointVector> getDataVectors() {
		return catCorrResult.getDataVectors();
	}

	public CategoricalCorrelationResult getCatCorrResult() {
		return catCorrResult;
	}

	public void setCatCorrResult(CategoricalCorrelationResult catCorrResult) {
		this.catCorrResult = catCorrResult;
	}

	public ContinuousType getContType() {
		return contType;
	}

	public void setContType(ContinuousType contType) {
		this.contType = contType;
	}

	public CategoricalCorrelationRequest getCatCorrRequest() {
		return catCorrRequest;
	}

	public void setCatCorrRequest(CategoricalCorrelationRequest catCorrRequest) {
		this.catCorrRequest = catCorrRequest;
	}

}


text:
package org.gradle.ide.visualstudio.plugins;

import org.gradle.api.*;
import org.gradle.api.internal.file.FileResolver;
import org.gradle.api.internal.project.ProjectIdentifier;
import org.gradle.api.internal.resolve.ProjectModelResolver;
import org.gradle.api.tasks.Delete;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.ide.visualstudio.VisualStudioProject;
import org.gradle.ide.visualstudio.VisualStudioSolution;
import org.gradle.ide.visualstudio.internal.DefaultVisualStudioExtension;
import org.gradle.ide.visualstudio.internal.DefaultVisualStudioProject;
import org.gradle.ide.visualstudio.internal.VisualStudioExtensionInternal;
import org.gradle.ide.visualstudio.internal.VisualStudioProjectConfiguration;
import org.gradle.ide.visualstudio.tasks.GenerateFiltersFileTask;
import org.gradle.ide.visualstudio.tasks.GenerateProjectFileTask;
import org.gradle.ide.visualstudio.tasks.GenerateSolutionFileTask;
import org.gradle.internal.reflect.Instantiator;
import org.gradle.internal.service.ServiceRegistry;
import org.gradle.model.Model;
import org.gradle.model.Mutate;
import org.gradle.model.RuleSource;
import org.gradle.nativeplatform.NativeBinarySpec;
import org.gradle.nativeplatform.NativeComponentSpec;
import org.gradle.nativeplatform.plugins.NativeComponentModelPlugin;
import org.gradle.platform.base.BinaryContainer;

/**
 * A plugin for creating a Visual Studio solution for a gradle project.
 */
@Incubating
public class VisualStudioPlugin implements Plugin<Project> {

    @Override
    public void apply(Project project) {
        project.getPluginManager().apply(NativeComponentModelPlugin.class);
    }

    static class Rules extends RuleSource {
        @Model
        public static VisualStudioExtensionInternal visualStudio(ServiceRegistry serviceRegistry, ProjectIdentifier projectIdentifier) {
            Instantiator instantiator = serviceRegistry.get(Instantiator.class);
            ProjectModelResolver projectModelResolver = serviceRegistry.get(ProjectModelResolver.class);
            FileResolver fileResolver = serviceRegistry.get(FileResolver.class);

            return instantiator.newInstance(DefaultVisualStudioExtension.class, projectIdentifier, instantiator, projectModelResolver, fileResolver);
        }

        @Mutate
        public static void includeBuildFileInProject(VisualStudioExtensionInternal visualStudio, final ProjectIdentifier projectIdentifier) {
            visualStudio.getProjects().all(new Action<VisualStudioProject>() {
                public void execute(VisualStudioProject project) {
                    if (projectIdentifier.getBuildFile() != null) {
                        ((DefaultVisualStudioProject) project).addSourceFile(projectIdentifier.getBuildFile());
                    }
                }
            });
        }

        @Mutate
        public static void createVisualStudioModelForBinaries(VisualStudioExtensionInternal visualStudioExtension, BinaryContainer binaries) {
            for (NativeBinarySpec binary : binaries.withType(NativeBinarySpec.class)) {
                VisualStudioProjectConfiguration configuration = visualStudioExtension.getProjectRegistry().addProjectConfiguration(binary);

                // Only create a solution if one of the binaries is buildable
                if (binary.isBuildable()) {
                    DefaultVisualStudioProject visualStudioProject = configuration.getProject();
                    visualStudioExtension.getSolutionRegistry().addSolution(visualStudioProject);
                }
            }
        }

        @Mutate
        public static void createTasksForVisualStudio(TaskContainer tasks, VisualStudioExtensionInternal visualStudioExtension) {
            for (VisualStudioProject vsProject : visualStudioExtension.getProjects()) {
                vsProject.builtBy(createProjectsFileTask(tasks, vsProject));
                vsProject.builtBy(createFiltersFileTask(tasks, vsProject));
            }

            for (VisualStudioSolution vsSolution : visualStudioExtension.getSolutions()) {
                Task solutionTask = tasks.create(vsSolution.getName() + "VisualStudio");
                solutionTask.setDescription(String.format("Generates the '%s' Visual Studio solution file.", vsSolution.getName()));
                vsSolution.setBuildTask(solutionTask);
                vsSolution.builtBy(createSolutionTask(tasks, vsSolution));

                // Lifecycle task for component
                NativeComponentSpec component = vsSolution.getComponent();
                Task lifecycleTask = tasks.maybeCreate(component.getName() + "VisualStudio");
                lifecycleTask.dependsOn(vsSolution);
                lifecycleTask.setGroup("IDE");
                lifecycleTask.setDescription(String.format("Generates the Visual Studio solution for %s.", component));
            }

            addCleanTask(tasks);
        }

        private static void addCleanTask(TaskContainer tasks) {
            Delete cleanTask = tasks.create("cleanVisualStudio", Delete.class);
            for (Task task : tasks.withType(GenerateSolutionFileTask.class)) {
                cleanTask.delete(task.getOutputs().getFiles());
            }
            for (Task task : tasks.withType(GenerateFiltersFileTask.class)) {
                cleanTask.delete(task.getOutputs().getFiles());
            }
            for (Task task : tasks.withType(GenerateProjectFileTask.class)) {
                cleanTask.delete(task.getOutputs().getFiles());
            }
            cleanTask.setGroup("IDE");
            cleanTask.setDescription("Removes all generated Visual Studio project and solution files");
        }

        private static Task createSolutionTask(TaskContainer tasks, VisualStudioSolution solution) {
            GenerateSolutionFileTask solutionFileTask = tasks.create(solution.getName() + "VisualStudioSolution", GenerateSolutionFileTask.class);
            solutionFileTask.setVisualStudioSolution(solution);
            return solutionFileTask;
        }

        private static Task createProjectsFileTask(TaskContainer tasks, VisualStudioProject vsProject) {
            GenerateProjectFileTask task = tasks.create(vsProject.getName() + "VisualStudioProject", GenerateProjectFileTask.class);
            task.setVisualStudioProject(vsProject);
            task.initGradleCommand();
            return task;
        }

        private static Task createFiltersFileTask(TaskContainer tasks, VisualStudioProject vsProject) {
            GenerateFiltersFileTask task = tasks.create(vsProject.getName() + "VisualStudioFilters", GenerateFiltersFileTask.class);
            task.setVisualStudioProject(vsProject);
            return task;
        }
    }
}


text:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="nl_NL">
<context>
    <name>LLockScreen</name>
    <message>
        <location filename="../LLockScreen.ui" line="14"/>
        <source>Form</source>
        <translation>Formulier</translation>
    </message>
    <message>
        <location filename="../LLockScreen.ui" line="114"/>
        <source>Password</source>
        <translation>Wachtwoord</translation>
    </message>
    <message>
        <location filename="../LLockScreen.ui" line="126"/>
        <source>Unlock Session</source>
        <translation>Ontgrendel sessie</translation>
    </message>
    <message>
        <location filename="../LLockScreen.cpp" line="39"/>
        <source>Locked by: %1</source>
        <translation>Vergrendeld door: %1</translation>
    </message>
    <message>
        <location filename="../LLockScreen.cpp" line="76"/>
        <source>Too Many Failures</source>
        <translation type="unfinished"></translation>
    </message>
    <message>
        <location filename="../LLockScreen.cpp" line="76"/>
        <source>Wait %1 Minutes</source>
        <translation type="unfinished"></translation>
    </message>
    <message>
        <location filename="../LLockScreen.cpp" line="77"/>
        <source>Failed Attempts: %1</source>
        <translation type="unfinished"></translation>
    </message>
</context>
</TS>


text:
<!DOCTYPE html>
<html>
<title>Service Workers: register()</title>
    <head>
        <link rel="help" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#navigator-service-worker-register">
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>

    </head>
    <body>

<!--

`navigator.serviceWorker.register(url, options)` method must run the
[Registration algorithm][1] passing `url` and `options`.`scope` as the
arguments.

[1]: #registration-algorithm

-->

    <script>
        test(function() {
            // not_implemented();
        }, "There are no tests for section register() so far.");
    </script>

    </body>
</html>


text:
package wor.com.wor.models;

import com.google.firebase.database.Exclude;

import java.io.Serializable;
import java.util.HashMap;

public class Cycle implements Serializable {

    private String Image, model;
    private Long quantity;
    public Cycle() {
        // Default constructor required for calls to DataSnapshot.getValue(User.class)
    }
    public Cycle(String Image, String model, Long quantity) {
        this.Image = Image;
        this.quantity = quantity;
        this.model = model;
    }

    @Exclude
    public HashMap<String, Object> toMap(){
        HashMap<String, Object> result =  new HashMap<>();
        result.put("Image", Image);
        result.put("model", model);
        result.put("quantity", quantity);
        return result;
    }
    public String getImage() {
        return Image;
    }

    public void setImage(String image) {
        Image = image;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public Long getQuantity() {
        return quantity;
    }

    public void setQuantity(Long quantity) {
        this.quantity = quantity;
    }

}