text:
package org.scalatest

import org.scalatest.prop.Checkers
import org.scalacheck._
import Arbitrary._
import Prop._
import org.scalatest.exceptions.TestFailedException
import FailureMessages._
import Matchers._

class ShouldContainKeySpec extends Spec with Checkers with ReturnsNormallyThrowsAssertion {

  // Checking for a specific size
  object `The 'contain key (Int)' syntax` {

    object `on scala.collection.immutable.Map` {

      def `should do nothing if map contains specified key` {
        Map("one" -> 1, "two" -> 2) should contain key ("two")
        Map("one" -> 1, "two" -> 2) should (contain key ("two"))
        Map(1 -> "one", 2 -> "two") should contain key (2)
      }

      def `should do nothing if map does not contain the specified key and used with not` {
        Map("one" -> 1, "two" -> 2) should not { contain key ("three") }
        Map("one" -> 1, "two" -> 2) should not contain key ("three")
        Map("one" -> 1, "two" -> 2) should (not contain key ("three"))
      }

      def `should do nothing when map contains specified key and used in a logical-and expression` {

        Map("one" -> 1, "two" -> 2) should { be (Map("one" -> 1, "two" -> 2)) and (contain key ("one")) }
        Map("one" -> 1, "two" -> 2) should ((be (Map("one" -> 1, "two" -> 2))) and (contain key ("one")))
        Map("one" -> 1, "two" -> 2) should (be (Map("one" -> 1, "two" -> 2)) and contain key ("one"))

        Map("one" -> 1, "two" -> 2) should { contain key ("two") and (contain key ("one")) }
        Map("one" -> 1, "two" -> 2) should ((contain key ("two")) and (contain key ("one")))
        Map("one" -> 1, "two" -> 2) should (contain key ("two") and contain key ("one"))
      }

      def `should do nothing when map contains specified key and used in a logical-or expression` {
        Map("one" -> 1, "two" -> 2) should { be (Map("one" -> 1, "two" -> 2)) or (contain key ("one")) }
        Map("one" -> 1, "two" -> 2) should ((be (Map("one" -> 1, "two" -> 2))) or (contain key ("one")))
        Map("one" -> 1, "two" -> 2) should (be (Map("one" -> 1, "two" -> 2)) or contain key ("one"))

        Map("one" -> 1, "two" -> 2) should { contain key ("cat") or (contain key ("one")) }
        Map("one" -> 1, "two" -> 2) should ((contain key ("cat")) or (contain key ("one")))
        Map("one" -> 1, "two" -> 2) should (contain key ("cat") or contain key ("one"))
      }

      def `should do nothing when map does not contain the specified key and used in a logical-and expression with not` {
        Map("one" -> 1, "two" -> 2) should { be (Map("one" -> 1, "two" -> 2)) and not { contain key ("three") }}
        Map("one" -> 1, "two" -> 2) should ((be (Map("one" -> 1, "two" -> 2))) and (not contain key ("three")))
        Map("one" -> 1, "two" -> 2) should (be (Map("one" -> 1, "two" -> 2)) and not contain key ("three"))

        Map("one" -> 1, "two" -> 2) should { not { contain key ("five") } and not { contain key ("three") }}
        Map("one" -> 1, "two" -> 2) should ((not contain key ("five")) and (not contain key ("three")))
        Map("one" -> 1, "two" -> 2) should (not contain key ("five") and not contain key ("three"))
      }

      def `should do nothing when map does not contain the specified key and used in a logical-or expression with not` {
        Map("one" -> 1, "two" -> 2) should { be (Map("one" -> 1, "three" -> 2)) or not { contain key ("three") }}
        Map("one" -> 1, "two" -> 2) should (be (Map("one" -> 1, "three" -> 2)) or (not contain key ("three")))
        Map("one" -> 1, "two" -> 2) should (be (Map("one" -> 1, "three" -> 2)) or not contain key ("three"))

        Map("one" -> 1, "two" -> 2) should { not { contain key ("two") } or not { contain key ("three") }}
        Map("one" -> 1, "two" -> 2) should ((not contain key ("two")) or (not contain key ("three")))
        Map("one" -> 1, "two" -> 2) should (not contain key ("two") or not contain key ("three"))
      }

      def `should throw TestFailedException if map does not contain the specified key` {
        val caught1 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should contain key ("three")
        }
        assert(caught1.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"three\"")
      }

      def `should throw TestFailedException if contains the specified key when used with not` {

        val caught1 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should (not contain key ("two"))
        }
        assert(caught1.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")

        val caught2 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should not (contain key ("two"))
        }
        assert(caught2.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")

        val caught3 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should not contain key ("two")
        }
        assert(caught3.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")
      }

      def `should throw an TestFailedException when map doesn't contain specified key and used in a logical-and expression` {

        intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should { be (Map("one" -> 1, "two" -> 2)) and (contain key ("five")) }
        }
        intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should ((be (Map("one" -> 1, "two" -> 2))) and (contain key ("five")))
        }
        intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should (be (Map("one" -> 1, "two" -> 2)) and contain key ("five"))
        }

        val caught1 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should { contain key ("five") and (contain key ("two")) }
        }
        assert(caught1.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"five\"")

        val caught2 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should ((contain key ("five")) and (contain key ("two")))
        }
        assert(caught2.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"five\"")

        val caught3 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should (contain key ("five") and contain key ("two"))
        }
        assert(caught3.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"five\"")
      }

      def `should throw an TestFailedException when map doesn't contain specified key and used in a logical-or expression` {

        intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should { be (Map.empty) or (contain key ("twenty two")) }
        }
        intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should ((be (Map.empty)) or (contain key ("twenty two")))
        }
        intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should (be (Map.empty) or contain key ("twenty two"))
        }

        val caught1 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should { contain key ("fifty five") or (contain key ("twenty two")) }
        }
        assert(caught1.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"fifty five\", and Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"twenty two\"")

        val caught2 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should ((contain key ("fifty five")) or (contain key ("twenty two")))
        }
        assert(caught2.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"fifty five\", and Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"twenty two\"")

        val caught3 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should (contain key ("fifty five") or contain key ("twenty two"))
        }
        assert(caught3.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"fifty five\", and Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"twenty two\"")
      }

      def `should throw an TestFailedException when map contains specified key and used in a logical-and expression with not` {

        intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should { be (Map("one" -> 1, "two" -> 2)) and not { contain key ("two") }}
        }
        intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should ((be (Map("one" -> 1, "two" -> 2))) and (not contain key ("two")))
        }
        intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should (be (Map("one" -> 1, "two" -> 2)) and not contain key ("two"))
        }

        val caught1 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should { not { contain key ("three") } and not { contain key ("two") }}
        }
        assert(caught1.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"three\", but Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")

        val caught2 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should ((not contain key ("three")) and (not contain key ("two")))
        }
        assert(caught2.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"three\", but Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")

        val caught3 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should (not contain key ("three") and not contain key ("two"))
        }
        assert(caught3.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"three\", but Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")
      }

      def `should throw an TestFailedException when map contains specified key and used in a logical-or expression with not` {

        intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should { be (Map.empty) or not { contain key ("two") }}
        }
        intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should ((be (Map.empty)) or (not contain key ("two")))
        }
        intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should (be (Map.empty) or not contain key ("two"))
        }

        val caught1 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should { not { contain key ("two") } or not { contain key ("two") }}
        }
        assert(caught1.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\", and Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")

        val caught2 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should ((not contain key ("two")) or (not contain key ("two")))
        }
        assert(caught2.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\", and Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")

        val caught3 = intercept[TestFailedException] {
          Map("one" -> 1, "two" -> 2) should (not contain key ("two") or not contain key ("two"))
        }
        assert(caught3.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\", and Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")
      }

      def `should work on parallel form` {
        Map("one" -> 1, "two" -> 2).par should contain key ("two")
      }
    }

    object `on scala.collection.mutable.Map` {

      import scala.collection.mutable

      def `should do nothing if map contains specified key` {
        mutable.Map("one" -> 1, "two" -> 2) should contain key ("two")
        mutable.Map("one" -> 1, "two" -> 2) should (contain key ("two"))
        mutable.Map(1 -> "one", 2 -> "two") should contain key (2)
      }

      def `should do nothing if map does not contain the specified key and used with not` {
        mutable.Map("one" -> 1, "two" -> 2) should not { contain key ("three") }
        mutable.Map("one" -> 1, "two" -> 2) should not contain key ("three")
        mutable.Map("one" -> 1, "two" -> 2) should (not contain key ("three"))
      }

      def `should do nothing when map contains specified key and used in a logical-and expression` {
        mutable.Map("one" -> 1, "two" -> 2) should { contain key ("two") and (contain key ("one")) }
        mutable.Map("one" -> 1, "two" -> 2) should ((contain key ("two")) and (contain key ("one")))
        mutable.Map("one" -> 1, "two" -> 2) should (contain key ("two") and contain key ("one"))
      }

      def `should do nothing when map contains specified key and used in a logical-or expression` {
        mutable.Map("one" -> 1, "two" -> 2) should { contain key ("cat") or (contain key ("one")) }
        mutable.Map("one" -> 1, "two" -> 2) should ((contain key ("cat")) or (contain key ("one")))
        mutable.Map("one" -> 1, "two" -> 2) should (contain key ("cat") or contain key ("one"))
      }

      def `should do nothing when map does not contain the specified key and used in a logical-and expression with not` {
        mutable.Map("one" -> 1, "two" -> 2) should { not { contain key ("five") } and not { contain key ("three") }}
        mutable.Map("one" -> 1, "two" -> 2) should ((not contain key ("five")) and (not contain key ("three")))
        mutable.Map("one" -> 1, "two" -> 2) should (not contain key ("five") and not contain key ("three"))
      }

      def `should do nothing when map does not contain the specified key and used in a logical-or expression with not` {
        mutable.Map("one" -> 1, "two" -> 2) should { not { contain key ("two") } or not { contain key ("three") }}
        mutable.Map("one" -> 1, "two" -> 2) should ((not contain key ("two")) or (not contain key ("three")))
        mutable.Map("one" -> 1, "two" -> 2) should (not contain key ("two") or not contain key ("three"))
      }

      def `should throw TestFailedException if map does not contain the specified key` {
        val map = mutable.Map("one" -> 1, "two" -> 2)
        val caught1 = intercept[TestFailedException] {
          map should contain key ("three")
        }
        assert(caught1.getMessage === decorateToStringValue(map) + " did not contain key \"three\"")
      }

      def `should throw TestFailedException if contains the specified key when used with not` {
        val map1 = mutable.Map("one" -> 1, "two" -> 2)
        val caught1 = intercept[TestFailedException] {
          map1 should (not contain key ("two"))
        }
        assert(caught1.getMessage === decorateToStringValue(map1) + " contained key \"two\"")
        val map2 = mutable.Map("one" -> 1, "two" -> 2)
        val caught2 = intercept[TestFailedException] {
          map2 should not (contain key ("two"))
        }
        assert(caught2.getMessage === decorateToStringValue(map2) + " contained key \"two\"")

        val map3 = mutable.Map("one" -> 1, "two" -> 2)
        val caught3 = intercept[TestFailedException] {
          map3 should not contain key ("two")
        }
        assert(caught3.getMessage === decorateToStringValue(map3) + " contained key \"two\"")
      }

      def `should throw an TestFailedException when map doesn't contain specified key and used in a logical-and expression` {
        val map1 = mutable.Map("one" -> 1, "two" -> 2)
        val caught1 = intercept[TestFailedException] {
          map1 should { contain key ("five") and (contain key ("two")) }
        }
        assert(caught1.getMessage === decorateToStringValue(map1) + " did not contain key \"five\"")

        val map2 = mutable.Map("one" -> 1, "two" -> 2)
        val caught2 = intercept[TestFailedException] {
          map2 should ((contain key ("five")) and (contain key ("two")))
        }
        assert(caught2.getMessage === decorateToStringValue(map2) + " did not contain key \"five\"")

        val map3 = mutable.Map("one" -> 1, "two" -> 2)
        val caught3 = intercept[TestFailedException] {
          map3 should (contain key ("five") and contain key ("two"))
        }
        assert(caught3.getMessage === decorateToStringValue(map3) + " did not contain key \"five\"")
      }

      def `should throw an TestFailedException when map doesn't contain specified key and used in a logical-or expression` {
        val map1 = mutable.Map("one" -> 1, "two" -> 2)
        val caught1 = intercept[TestFailedException] {
          map1 should { contain key ("fifty five") or (contain key ("twenty two")) }
        }
        assert(caught1.getMessage === decorateToStringValue(map1) + " did not contain key \"fifty five\", and " + decorateToStringValue(map1) + " did not contain key \"twenty two\"")

        val map2 = mutable.Map("one" -> 1, "two" -> 2)
        val caught2 = intercept[TestFailedException] {
          map2 should ((contain key ("fifty five")) or (contain key ("twenty two")))
        }
        assert(caught2.getMessage === decorateToStringValue(map2) + " did not contain key \"fifty five\", and " + decorateToStringValue(map2) + " did not contain key \"twenty two\"")

        val map3 = mutable.Map("one" -> 1, "two" -> 2)
        val caught3 = intercept[TestFailedException] {
          map3 should (contain key ("fifty five") or contain key ("twenty two"))
        }
        assert(caught3.getMessage === decorateToStringValue(map3) + " did not contain key \"fifty five\", and " + decorateToStringValue(map3) + " did not contain key \"twenty two\"")
      }

      def `should throw an TestFailedException when map contains specified key and used in a logical-and expression with not` {
        val map1 = mutable.Map("one" -> 1, "two" -> 2)
        val caught1 = intercept[TestFailedException] {
          map1 should { not { contain key ("three") } and not { contain key ("two") }}
        }
        assert(caught1.getMessage === decorateToStringValue(map1) + " did not contain key \"three\", but " + decorateToStringValue(map1) + " contained key \"two\"")

        val map2 = mutable.Map("one" -> 1, "two" -> 2)
        val caught2 = intercept[TestFailedException] {
          map2 should ((not contain key ("three")) and (not contain key ("two")))
        }
        assert(caught2.getMessage === decorateToStringValue(map2) + " did not contain key \"three\", but " + decorateToStringValue(map2) + " contained key \"two\"")

        val map3 = mutable.Map("one" -> 1, "two" -> 2)
        val caught3 = intercept[TestFailedException] {
          map3 should (not contain key ("three") and not contain key ("two"))
        }
        assert(caught3.getMessage === decorateToStringValue(map3) + " did not contain key \"three\", but " + decorateToStringValue(map3) + " contained key \"two\"")
      }

      def `should throw an TestFailedException when map contains specified key and used in a logical-or expression with not` {
        val map1 = mutable.Map("one" -> 1, "two" -> 2)
        val caught1 = intercept[TestFailedException] {
          map1 should { not { contain key ("two") } or not { contain key ("two") }}
        }
        assert(caught1.getMessage === decorateToStringValue(map1) + " contained key \"two\", and " + decorateToStringValue(map1) + " contained key \"two\"")

        val map2 = mutable.Map("one" -> 1, "two" -> 2)
        val caught2 = intercept[TestFailedException] {
          map2 should ((not contain key ("two")) or (not contain key ("two")))
        }
        assert(caught2.getMessage === decorateToStringValue(map2) + " contained key \"two\", and " + decorateToStringValue(map2) + " contained key \"two\"")

        val map3 = mutable.Map("one" -> 1, "two" -> 2)
        val caught3 = intercept[TestFailedException] {
          map3 should (not contain key ("two") or not contain key ("two"))
        }
        assert(caught3.getMessage === decorateToStringValue(map3) + " contained key \"two\", and " + decorateToStringValue(map3) + " contained key \"two\"")
      }

      def `should work on parallel form` {
        mutable.Map("one" -> 1, "two" -> 2).par should contain key ("two")
      }
    }

    object `on scala.collection.Map` {

      val map: scala.collection.Map[String, Int] = Map("one" -> 1, "two" -> 2)

      def `should do nothing if map contains specified key` {
        map should contain key ("two")
        map should (contain key ("two"))
      }

      def `should do nothing if map does not contain the specified key and used with not` {
        map should not { contain key ("three") }
        map should not contain key ("three")
        map should (not contain key ("three"))
      }

      def `should do nothing when map contains specified key and used in a logical-and expression` {
        map should { contain key ("two") and (contain key ("one")) }
        map should ((contain key ("two")) and (contain key ("one")))
        map should (contain key ("two") and contain key ("one"))
      }

      def `should do nothing when map contains specified key and used in a logical-or expression` {
        map should { contain key ("cat") or (contain key ("one")) }
        map should ((contain key ("cat")) or (contain key ("one")))
        map should (contain key ("cat") or contain key ("one"))
      }

      def `should do nothing when map does not contain the specified key and used in a logical-and expression with not` {
        map should { not { contain key ("five") } and not { contain key ("three") }}
        map should ((not contain key ("five")) and (not contain key ("three")))
        map should (not contain key ("five") and not contain key ("three"))
      }

      def `should do nothing when map does not contain the specified key and used in a logical-or expression with not` {
        map should { not { contain key ("two") } or not { contain key ("three") }}
        map should ((not contain key ("two")) or (not contain key ("three")))
        map should (not contain key ("two") or not contain key ("three"))
      }

      def `should throw TestFailedException if map does not contain the specified key` {
        val caught1 = intercept[TestFailedException] {
          map should contain key ("three")
        }
        assert(caught1.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"three\"")
      }

      def `should throw TestFailedException if contains the specified key when used with not` {

        val caught1 = intercept[TestFailedException] {
          map should (not contain key ("two"))
        }
        assert(caught1.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")

        val caught2 = intercept[TestFailedException] {
          map should not (contain key ("two"))
        }
        assert(caught2.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")

        val caught3 = intercept[TestFailedException] {
          map should not contain key ("two")
        }
        assert(caught3.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")
      }

      def `should throw an TestFailedException when map doesn't contain specified key and used in a logical-and expression` {

        val caught1 = intercept[TestFailedException] {
          map should { contain key ("five") and (contain key ("two")) }
        }
        assert(caught1.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"five\"")

        val caught2 = intercept[TestFailedException] {
          map should ((contain key ("five")) and (contain key ("two")))
        }
        assert(caught2.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"five\"")

        val caught3 = intercept[TestFailedException] {
          map should (contain key ("five") and contain key ("two"))
        }
        assert(caught3.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"five\"")
      }

      def `should throw an TestFailedException when map doesn't contain specified key and used in a logical-or expression` {

        val caught1 = intercept[TestFailedException] {
          map should { contain key ("fifty five") or (contain key ("twenty two")) }
        }
        assert(caught1.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"fifty five\", and Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"twenty two\"")

        val caught2 = intercept[TestFailedException] {
          map should ((contain key ("fifty five")) or (contain key ("twenty two")))
        }
        assert(caught2.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"fifty five\", and Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"twenty two\"")

        val caught3 = intercept[TestFailedException] {
          map should (contain key ("fifty five") or contain key ("twenty two"))
        }
        assert(caught3.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"fifty five\", and Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"twenty two\"")
      }

      def `should throw an TestFailedException when map contains specified key and used in a logical-and expression with not` {

        val caught1 = intercept[TestFailedException] {
          map should { not { contain key ("three") } and not { contain key ("two") }}
        }
        assert(caught1.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"three\", but Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")

        val caught2 = intercept[TestFailedException] {
          map should ((not contain key ("three")) and (not contain key ("two")))
        }
        assert(caught2.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"three\", but Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")

        val caught3 = intercept[TestFailedException] {
          map should (not contain key ("three") and not contain key ("two"))
        }
        assert(caught3.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) did not contain key \"three\", but Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")
      }

      def `should throw an TestFailedException when map contains specified key and used in a logical-or expression with not` {

        val caught1 = intercept[TestFailedException] {
          map should { not { contain key ("two") } or not { contain key ("two") }}
        }
        assert(caught1.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\", and Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")

        val caught2 = intercept[TestFailedException] {
          map should ((not contain key ("two")) or (not contain key ("two")))
        }
        assert(caught2.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\", and Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")

        val caught3 = intercept[TestFailedException] {
          map should (not contain key ("two") or not contain key ("two"))
        }
        assert(caught3.getMessage === "Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\", and Map(\"one\" -> 1, \"two\" -> 2) contained key \"two\"")
      }

      def `should work on parallel form` {
        map.par should contain key ("two")
      }
    }

    object `on scala.collection.immutable.HashMap` {

      import scala.collection.immutable.HashMap

      def `should do nothing if map contains specified key` {
        HashMap("one" -> 1, "two" -> 2) should contain key ("two")
        HashMap("one" -> 1, "two" -> 2) should (contain key ("two"))
        HashMap(1 -> "one", 2 -> "two") should contain key (2)
      }

      def `should do nothing if map does not contain the specified key and used with not` {
        HashMap("one" -> 1, "two" -> 2) should not { contain key ("three") }
        HashMap("one" -> 1, "two" -> 2) should not contain key ("three")
        HashMap("one" -> 1, "two" -> 2) should (not contain key ("three"))
      }

      def `should do nothing when map contains specified key and used in a logical-and expression` {
        HashMap("one" -> 1, "two" -> 2) should { contain key ("two") and (contain key ("one")) }
        HashMap("one" -> 1, "two" -> 2) should ((contain key ("two")) and (contain key ("one")))
        HashMap("one" -> 1, "two" -> 2) should (contain key ("two") and contain key ("one"))
      }

      def `should do nothing when map contains specified key and used in a logical-or expression` {
        HashMap("one" -> 1, "two" -> 2) should { contain key ("cat") or (contain key ("one")) }
        HashMap("one" -> 1, "two" -> 2) should ((contain key ("cat")) or (contain key ("one")))
        HashMap("one" -> 1, "two" -> 2) should (contain key ("cat") or contain key ("one"))
      }

      def `should do nothing when map does not contain the specified key and used in a logical-and expression with not` {
        HashMap("one" -> 1, "two" -> 2) should { not { contain key ("five") } and not { contain key ("three") }}
        HashMap("one" -> 1, "two" -> 2) should ((not contain key ("five")) and (not contain key ("three")))
        HashMap("one" -> 1, "two" -> 2) should (not contain key ("five") and not contain key ("three"))
      }

      def `should do nothing when map does not contain the specified key and used in a logical-or expression with not` {
        HashMap("one" -> 1, "two" -> 2) should { not { contain key ("two") } or not { contain key ("three") }}
        HashMap("one" -> 1, "two" -> 2) should ((not contain key ("two")) or (not contain key ("three")))
        HashMap("one" -> 1, "two" -> 2) should (not contain key ("two") or not contain key ("three"))
      }

      def `should throw TestFailedException if map does not contain the specified key` {
        val caught1 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should contain key ("three")
        }
        //assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain key \"three\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) did not contain key \"three\"")
      }

      def `should throw TestFailedException if contains the specified key when used with not` {

        val caught1 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should (not contain key ("two"))
        }
        //assert(caught1.getMessage === "Map(one -> 1, two -> 2) contained key \"two\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) contained key \"two\"")

        val caught2 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should not (contain key ("two"))
        }
        //assert(caught2.getMessage === "Map(one -> 1, two -> 2) contained key \"two\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) contained key \"two\"")

        val caught3 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should not contain key ("two")
        }
        //assert(caught3.getMessage === "Map(one -> 1, two -> 2) contained key \"two\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) contained key \"two\"")
      }

      def `should throw an TestFailedException when map doesn't contain specified key and used in a logical-and expression` {

        val caught1 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should { contain key ("five") and (contain key ("two")) }
        }
        //assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain key \"five\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) did not contain key \"five\"")

        val caught2 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should ((contain key ("five")) and (contain key ("two")))
        }
        //assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain key \"five\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) did not contain key \"five\"")

        val caught3 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should (contain key ("five") and contain key ("two"))
        }
        //assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain key \"five\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) did not contain key \"five\"")
      }

      def `should throw an TestFailedException when map doesn't contain specified key and used in a logical-or expression` {

        val caught1 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should { contain key ("fifty five") or (contain key ("twenty two")) }
        }
        //assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain key \"fifty five\", and Map(one -> 1, two -> 2) did not contain key \"twenty two\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) did not contain key \"fifty five\", and Map(.*) did not contain key \"twenty two\"")

        val caught2 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should ((contain key ("fifty five")) or (contain key ("twenty two")))
        }
        //assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain key \"fifty five\", and Map(one -> 1, two -> 2) did not contain key \"twenty two\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) did not contain key \"fifty five\", and Map(.*) did not contain key \"twenty two\"")

        val caught3 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should (contain key ("fifty five") or contain key ("twenty two"))
        }
        // assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain key \"fifty five\", and Map(one -> 1, two -> 2) did not contain key \"twenty two\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) did not contain key \"fifty five\", and Map(.*) did not contain key \"twenty two\"")
      }

      def `should throw an TestFailedException when map contains specified key and used in a logical-and expression with not` {

        val caught1 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should { not { contain key ("three") } and not { contain key ("two") }}
        }
        //assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain key \"three\", but Map(one -> 1, two -> 2) contained key \"two\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) did not contain key \"three\", but Map(.*) contained key \"two\"")

        val caught2 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should ((not contain key ("three")) and (not contain key ("two")))
        }
        //assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain key \"three\", but Map(one -> 1, two -> 2) contained key \"two\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) did not contain key \"three\", but Map(.*) contained key \"two\"")

        val caught3 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should (not contain key ("three") and not contain key ("two"))
        }
        //assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain key \"three\", but Map(one -> 1, two -> 2) contained key \"two\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) did not contain key \"three\", but Map(.*) contained key \"two\"")
      }

      def `should throw an TestFailedException when map contains specified key and used in a logical-or expression with not` {

        val caught1 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should { not { contain key ("two") } or not { contain key ("two") }}
        }
        //assert(caught1.getMessage === "Map(one -> 1, two -> 2) contained key \"two\", and Map(one -> 1, two -> 2) contained key \"two\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) contained key \"two\", and Map(.*) contained key \"two\"")

        val caught2 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should ((not contain key ("two")) or (not contain key ("two")))
        }
        //assert(caught2.getMessage === "Map(one -> 1, two -> 2) contained key \"two\", and Map(one -> 1, two -> 2) contained key \"two\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) contained key \"two\", and Map(.*) contained key \"two\"")

        val caught3 = intercept[TestFailedException] {
          HashMap("one" -> 1, "two" -> 2) should (not contain key ("two") or not contain key ("two"))
        }
        //assert(caught3.getMessage === "Map(one -> 1, two -> 2) contained key \"two\", and Map(one -> 1, two -> 2) contained key \"two\"")
        caught1.getMessage should fullyMatch regex ("Map(.*) contained key \"two\", and Map(.*) contained key \"two\"")
      }

      def `should work on parallel form` {
        HashMap("one" -> 1, "two" -> 2).par should contain key ("two")
      }
    }

    object `on scala.collection.mutable.HashMap` {

      import scala.collection.mutable

      def `should do nothing if map contains specified key` {
        mutable.HashMap("one" -> 1, "two" -> 2) should contain key ("two")
        mutable.HashMap("one" -> 1, "two" -> 2) should (contain key ("two"))
        mutable.HashMap(1 -> "one", 2 -> "two") should contain key (2)
      }

      def `should do nothing if map does not contain the specified key and used with not` {
        mutable.HashMap("one" -> 1, "two" -> 2) should not { contain key ("three") }
        mutable.HashMap("one" -> 1, "two" -> 2) should not contain key ("three")
        mutable.HashMap("one" -> 1, "two" -> 2) should (not contain key ("three"))
      }

      def `should do nothing when map contains specified key and used in a logical-and expression` {
        mutable.HashMap("one" -> 1, "two" -> 2) should { contain key ("two") and (contain key ("one")) }
        mutable.HashMap("one" -> 1, "two" -> 2) should ((contain key ("two")) and (contain key ("one")))
        mutable.HashMap("one" -> 1, "two" -> 2) should (contain key ("two") and contain key ("one"))
      }

      def `should do nothing when map contains specified key and used in a logical-or expression` {
        mutable.HashMap("one" -> 1, "two" -> 2) should { contain key ("cat") or (contain key ("one")) }
        mutable.HashMap("one" -> 1, "two" -> 2) should ((contain key ("cat")) or (contain key ("one")))
        mutable.HashMap("one" -> 1, "two" -> 2) should (contain key ("cat") or contain key ("one"))
      }

      def `should do nothing when map does not contain the specified key and used in a logical-and expression with not` {
        mutable.HashMap("one" -> 1, "two" -> 2) should { not { contain key ("five") } and not { contain key ("three") }}
        mutable.HashMap("one" -> 1, "two" -> 2) should ((not contain key ("five")) and (not contain key ("three")))
        mutable.HashMap("one" -> 1, "two" -> 2) should (not contain key ("five") and not contain key ("three"))
      }

      def `should do nothing when map does not contain the specified key and used in a logical-or expression with not` {
        mutable.HashMap("one" -> 1, "two" -> 2) should { not { contain key ("two") } or not { contain key ("three") }}
        mutable.HashMap("one" -> 1, "two" -> 2) should ((not contain key ("two")) or (not contain key ("three")))
        mutable.HashMap("one" -> 1, "two" -> 2) should (not contain key ("two") or not contain key ("three"))
      }

      def `should throw TestFailedException if map does not contain the specified key` {
        val map = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught1 = intercept[TestFailedException] {
          map should contain key ("three")
        }
        assert(caught1.getMessage === decorateToStringValue(map) + " did not contain key \"three\"")
      }

      def `should throw TestFailedException if contains the specified key when used with not` {
        val map1 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught1 = intercept[TestFailedException] {
          map1 should (not contain key ("two"))
        }
        assert(caught1.getMessage === decorateToStringValue(map1) + " contained key \"two\"")

        val map2 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught2 = intercept[TestFailedException] {
          map2 should not (contain key ("two"))
        }
        assert(caught2.getMessage === decorateToStringValue(map2) + " contained key \"two\"")

        val map3 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught3 = intercept[TestFailedException] {
          map3 should not contain key ("two")
        }
        assert(caught3.getMessage === decorateToStringValue(map3) + " contained key \"two\"")
      }

      def `should throw an TestFailedException when map doesn't contain specified key and used in a logical-and expression` {
        val map1 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught1 = intercept[TestFailedException] {
          map1 should { contain key ("five") and (contain key ("two")) }
        }
        assert(caught1.getMessage === decorateToStringValue(map1) + " did not contain key \"five\"")

        val map2 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught2 = intercept[TestFailedException] {
          map2 should ((contain key ("five")) and (contain key ("two")))
        }
        assert(caught2.getMessage === decorateToStringValue(map2) + " did not contain key \"five\"")

        val map3 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught3 = intercept[TestFailedException] {
          map3 should (contain key ("five") and contain key ("two"))
        }
        assert(caught3.getMessage === decorateToStringValue(map3) + " did not contain key \"five\"")
      }

      def `should throw an TestFailedException when map doesn't contain specified key and used in a logical-or expression` {
        val map1 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught1 = intercept[TestFailedException] {
          map1 should { contain key ("fifty five") or (contain key ("twenty two")) }
        }
        assert(caught1.getMessage === decorateToStringValue(map1) + " did not contain key \"fifty five\", and " + decorateToStringValue(map1) + " did not contain key \"twenty two\"")

        val map2 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught2 = intercept[TestFailedException] {
          map2 should ((contain key ("fifty five")) or (contain key ("twenty two")))
        }
        assert(caught2.getMessage === decorateToStringValue(map2) + " did not contain key \"fifty five\", and " + decorateToStringValue(map2) + " did not contain key \"twenty two\"")

        val map3 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught3 = intercept[TestFailedException] {
          map3 should (contain key ("fifty five") or contain key ("twenty two"))
        }
        assert(caught3.getMessage === decorateToStringValue(map3) + " did not contain key \"fifty five\", and " + decorateToStringValue(map3) + " did not contain key \"twenty two\"")
      }

      def `should throw an TestFailedException when map contains specified key and used in a logical-and expression with not` {
        val map1 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught1 = intercept[TestFailedException] {
          map1 should { not { contain key ("three") } and not { contain key ("two") }}
        }
        assert(caught1.getMessage === decorateToStringValue(map1) + " did not contain key \"three\", but " + decorateToStringValue(map1) + " contained key \"two\"")

        val map2 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught2 = intercept[TestFailedException] {
          map2 should ((not contain key ("three")) and (not contain key ("two")))
        }
        assert(caught2.getMessage === decorateToStringValue(map2) + " did not contain key \"three\", but " + decorateToStringValue(map2) + " contained key \"two\"")
        val map3 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught3 = intercept[TestFailedException] {
          map3 should (not contain key ("three") and not contain key ("two"))
        }
        assert(caught3.getMessage === decorateToStringValue(map3) + " did not contain key \"three\", but " + decorateToStringValue(map3) + " contained key \"two\"")
      }

      def `should throw an TestFailedException when map contains specified key and used in a logical-or expression with not` {
        val map1 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught1 = intercept[TestFailedException] {
          map1 should { not { contain key ("two") } or not { contain key ("two") }}
        }
        assert(caught1.getMessage === decorateToStringValue(map1) + " contained key \"two\", and " + decorateToStringValue(map1) + " contained key \"two\"")

        val map2 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught2 = intercept[TestFailedException] {
          map2 should ((not contain key ("two")) or (not contain key ("two")))
        }
        assert(caught2.getMessage === decorateToStringValue(map2) + " contained key \"two\", and " + decorateToStringValue(map2) + " contained key \"two\"")

        val map3 = mutable.HashMap("one" -> 1, "two" -> 2)
        val caught3 = intercept[TestFailedException] {(
          map3 should (not contain key ("two") or not contain key ("two")))
        }
        assert(caught3.getMessage === decorateToStringValue(map3) + " contained key \"two\", and " + decorateToStringValue(map3) + " contained key \"two\"")
      }

      def `should work on parallel form` {
        mutable.HashMap("one" -> 1, "two" -> 2).par should contain key ("two")
      }
    }

    object `on java.util.Map` {

      val javaMap: java.util.Map[String, Int] = new java.util.HashMap
      javaMap.put("one",1)
      javaMap.put("two", 2)

      def `should do nothing if map contains specified key` {
        javaMap should contain key ("two")
        javaMap should (contain key ("two"))
      }

      def `should do nothing if map does not contain the specified key and used with not` {
        javaMap should not { contain key ("three") }
        javaMap should not contain key ("three")
        javaMap should (not contain key ("three"))
      }

      def `should do nothing when map contains specified key and used in a logical-and expression` {
        javaMap should { contain key ("two") and (contain key ("one")) }
        javaMap should ((contain key ("two")) and (contain key ("one")))
        javaMap should (contain key ("two") and contain key ("one"))
      }

      def `should do nothing when map contains specified key and used in a logical-or expression` {
        javaMap should { contain key ("cat") or (contain key ("one")) }
        javaMap should ((contain key ("cat")) or (contain key ("one")))
        javaMap should (contain key ("cat") or contain key ("one"))
      }

      def `should do nothing when map does not contain the specified key and used in a logical-and expression with not` {
        javaMap should { not { contain key ("five") } and not { contain key ("three") }}
        javaMap should ((not contain key ("five")) and (not contain key ("three")))
        javaMap should (not contain key ("five") and not contain key ("three"))
      }

      def `should do nothing when map does not contain the specified key and used in a logical-or expression with not` {
        javaMap should { not { contain key ("two") } or not { contain key ("three") }}
        javaMap should ((not contain key ("two")) or (not contain key ("three")))
        javaMap should (not contain key ("two") or not contain key ("three"))
      }

      def `should throw TestFailedException if map does not contain the specified key` {
        val caught1 = intercept[TestFailedException] {
          javaMap should contain key ("three")
        }
        caught1.getMessage should (equal ("{\"one\"=1, \"two\"=2} did not contain key \"three\"") or
          equal ("{\"two\"=2, \"one\"=1} did not contain key \"three\""))
      }

      def `should throw TestFailedException if contains the specified key when used with not` {

        val caught1 = intercept[TestFailedException] {
          javaMap should (not contain key ("two"))
        }
        caught1.getMessage should (equal ("{\"one\"=1, \"two\"=2} contained key \"two\"") or
          equal ("{\"two\"=2, \"one\"=1} contained key \"two\""))

        val caught2 = intercept[TestFailedException] {
          javaMap should not (contain key ("two"))
        }
        caught2.getMessage should (equal ("{\"one\"=1, \"two\"=2} contained key \"two\"") or
          equal ("{\"two\"=2, \"one\"=1} contained key \"two\""))

        val caught3 = intercept[TestFailedException] {
          javaMap should not contain key ("two")
        }
        caught3.getMessage should (equal ("{\"one\"=1, \"two\"=2} contained key \"two\"") or
          equal ("{\"two\"=2, \"one\"=1} contained key \"two\""))
      }

      def `should throw an TestFailedException when map doesn't contain specified key and used in a logical-and expression` {

        val caught1 = intercept[TestFailedException] {
          javaMap should { contain key ("five") and (contain key ("two")) }
        }
        caught1.getMessage should (equal ("{\"one\"=1, \"two\"=2} did not contain key \"five\"") or
          equal ("{\"two\"=2, \"one\"=1} did not contain key \"five\""))

        val caught2 = intercept[TestFailedException] {
          javaMap should ((contain key ("five")) and (contain key ("two")))
        }
        caught2.getMessage should (equal ("{\"one\"=1, \"two\"=2} did not contain key \"five\"") or
          equal ("{\"two\"=2, \"one\"=1} did not contain key \"five\""))

        val caught3 = intercept[TestFailedException] {
          javaMap should (contain key ("five") and contain key ("two"))
        }
        caught3.getMessage should (equal ("{\"one\"=1, \"two\"=2} did not contain key \"five\"") or
          equal ("{\"two\"=2, \"one\"=1} did not contain key \"five\""))
      }

      def `should throw an TestFailedException when map doesn't contain specified key and used in a logical-or expression` {

        val caught1 = intercept[TestFailedException] {
          javaMap should { contain key ("fifty five") or (contain key ("twenty two")) }
        }
        caught1.getMessage should (equal ("{\"one\"=1, \"two\"=2} did not contain key \"fifty five\", and {\"one\"=1, \"two\"=2} did not contain key \"twenty two\"") or
          equal ("{\"two\"=2, \"one\"=1} did not contain key \"fifty five\", and {\"two\"=2, \"one\"=1} did not contain key \"twenty two\""))

        val caught2 = intercept[TestFailedException] {
          javaMap should ((contain key ("fifty five")) or (contain key ("twenty two")))
        }
        caught2.getMessage should (equal ("{\"one\"=1, \"two\"=2} did not contain key \"fifty five\", and {\"one\"=1, \"two\"=2} did not contain key \"twenty two\"") or
          equal ("{\"two\"=2, \"one\"=1} did not contain key \"fifty five\", and {\"two\"=2, \"one\"=1} did not contain key \"twenty two\""))

        val caught3 = intercept[TestFailedException] {
          javaMap should (contain key ("fifty five") or contain key ("twenty two"))
        }
        caught3.getMessage should (equal ("{\"one\"=1, \"two\"=2} did not contain key \"fifty five\", and {\"one\"=1, \"two\"=2} did not contain key \"twenty two\"") or
          equal ("{\"two\"=2, \"one\"=1} did not contain key \"fifty five\", and {\"two\"=2, \"one\"=1} did not contain key \"twenty two\""))
      }

      def `should throw an TestFailedException when map contains specified key and used in a logical-and expression with not` {

        val caught1 = intercept[TestFailedException] {
          javaMap should { not { contain key ("three") } and not { contain key ("two") }}
        }
        caught1.getMessage should (equal ("{\"one\"=1, \"two\"=2} did not contain key \"three\", but {\"one\"=1, \"two\"=2} contained key \"two\"") or
          equal ("{\"two\"=2, \"one\"=1} did not contain key \"three\", but {\"two\"=2, \"one\"=1} contained key \"two\""))

        val caught2 = intercept[TestFailedException] {
          javaMap should ((not contain key ("three")) and (not contain key ("two")))
        }
        caught2.getMessage should (equal ("{\"one\"=1, \"two\"=2} did not contain key \"three\", but {\"one\"=1, \"two\"=2} contained key \"two\"") or
          equal ("{\"two\"=2, \"one\"=1} did not contain key \"three\", but {\"two\"=2, \"one\"=1} contained key \"two\""))

        val caught3 = intercept[TestFailedException] {
          javaMap should (not contain key ("three") and not contain key ("two"))
        }
        caught3.getMessage should (equal ("{\"one\"=1, \"two\"=2} did not contain key \"three\", but {\"one\"=1, \"two\"=2} contained key \"two\"") or
          equal ("{\"two\"=2, \"one\"=1} did not contain key \"three\", but {\"two\"=2, \"one\"=1} contained key \"two\""))
      }

      def `should throw an TestFailedException when map contains specified key and used in a logical-or expression with not` {

        val caught1 = intercept[TestFailedException] {
          javaMap should { not { contain key ("two") } or not { contain key ("two") }}
        }
        caught1.getMessage should (equal ("{\"one\"=1, \"two\"=2} contained key \"two\", and {\"one\"=1, \"two\"=2} contained key \"two\"") or
          equal ("{\"two\"=2, \"one\"=1} contained key \"two\", and {\"two\"=2, \"one\"=1} contained key \"two\""))

        val caught2 = intercept[TestFailedException] {
          javaMap should ((not contain key ("two")) or (not contain key ("two")))
        }
        caught2.getMessage should (equal ("{\"one\"=1, \"two\"=2} contained key \"two\", and {\"one\"=1, \"two\"=2} contained key \"two\"") or
          equal ("{\"two\"=2, \"one\"=1} contained key \"two\", and {\"two\"=2, \"one\"=1} contained key \"two\""))

        val caught3 = intercept[TestFailedException] {
          javaMap should (not contain key ("two") or not contain key ("two"))
        }
        caught3.getMessage should (equal ("{\"one\"=1, \"two\"=2} contained key \"two\", and {\"one\"=1, \"two\"=2} contained key \"two\"") or
          equal ("{\"two\"=2, \"one\"=1} contained key \"two\", and {\"two\"=2, \"one\"=1} contained key \"two\""))
      }
    }
  }
}


text:
//
//  NXAlertView.h
//  NXlib
//
//  Created by AK on 14/12/8.
//  Copyright (c) 2014年 AK. All rights reserved.
//

#import <UIKit/UIKit.h>

typedef void (^NXAlertViewClickedHandler)(UIAlertView *alertView, NSInteger buttonIndex);
typedef void (^NXAlertViewCancelHandler)(UIAlertView *alertView);
typedef void (^NXAlertViewWillPresentHandler)(UIAlertView *alertView);
typedef void (^NXAlertViewDidPresentHandler)(UIAlertView *alertView);
typedef void (^NXAlertViewWillDismissHandler)(UIAlertView *alertView, NSInteger buttonIndex);
typedef void (^NXAlertViewDidDismissHandler)(UIAlertView *alertView, NSInteger buttonIndex);
typedef BOOL (^NXAlertViewShouldEnableHandler)(UIAlertView *alertView);

@interface NXAlertView : UIAlertView

/**
    初始化NXAlertView
 @param title 标题
 @param message 内容
 @return NXAlertView
 */
- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message;

/**

 初始化NXAlertView
 @param title 标题
 @param message 内容
 @param handler 点击按钮回掉
 @return NXAlertView
 */
- (instancetype)initWithTitle:(NSString *)title
                      message:(NSString *)message
               clickedHandler:(NXAlertViewClickedHandler)handler;

/**
 初始化NXAlertView

 @param title 标题
 @param message 内容
 @param otherBtns 显示更多的按钮
 @param clickedHandler 点击按钮的回掉
 @return NXAlertView
 */
- (instancetype)initWithTitle:(NSString *)title
                      message:(NSString *)message
                    otherBtns:(NSArray<NSString *> *)otherBtns
               clickedHandler:(NXAlertViewClickedHandler)clickedHandler;

/*
 * 点击 "完成" 回调
 *
 */
- (void)setClickedHandler:(NXAlertViewClickedHandler)clickedHandler;

/*
 * 点击 "取消" 回调
 *
 */
- (void)setCancelHandler:(NXAlertViewCancelHandler)cancelHandler;

/*
 * 即将显示回调
 *
 */
- (void)setWillPresentHandler:(NXAlertViewWillPresentHandler)willPresentHandler;

/*
 * 显示完成回调
 *
 */
- (void)setDidPresentHandler:(NXAlertViewDidPresentHandler)didPresentHandler;

/*
 * 即将消失回调
 *
 */
- (void)setWillDismissHandler:(NXAlertViewWillDismissHandler)willDismissHandler;

/*
 * 消失完成回调
 *
 */
- (void)setDidDismissHandler:(NXAlertViewDidDismissHandler)didDismissHandler;

/**
 Called after edits in any of the default fields added by the style

 @param shouldEnableHandler 输入字符后 回调
 */
- (void)setShouldEnableHandler:(NXAlertViewShouldEnableHandler)shouldEnableHandler;

@end

redpajama_set_name: RedPajamaGithub


text:
package de.gitzoz.akkastreamkafkasample

import scala.io.StdIn

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import de.gitzoz.akkastreamkafkasample.domain.CalculateClickedMetricsConsumer
import de.gitzoz.akkastreamkafkasample.domain.PrintClickedConsumer
import de.gitzoz.akkastreamkafkasample.domain.RandomClickProducer
import scala.concurrent.duration.DurationInt
import scala.concurrent.Await

object SampleApp {
  def main(args: Array[String]): Unit = {
    implicit val system       = ActorSystem("sample-app-system")
    implicit val materializer = ActorMaterializer()

    val whatOptions  = Seq("a", "b", "c", "d", "e", "f", "g", "h")
    val whereOptions = Seq("1", "2", "3", "4", "5", "6", "7", "8")

    val host  = "localhost"
    val port  = 9092
    val topic = "clicked"

    val producer =
      new RandomClickProducer(system, whatOptions, whereOptions, host, port)
    val printConsumer =
      new PrintClickedConsumer(system, startAtOffset = 0, host, port)
        .runConsumer(topic)
    val calculateConsumer =
      new CalculateClickedMetricsConsumer(system,
                                          startAtOffset = 0,
                                          host,
                                          port).runConsumer(topic)

    var run = true
    while (run) {
      println("Type 'add' to produce 10 Clicked")
      println("Enter exit to stop >>")
      val input = StdIn.readLine()
      if (input == "stop") {
        Await.result(system.terminate, 5.seconds)
        run = false
      } else if (input == "add") {
        producer.publishClicksWithPlainSink(10, topic)
      }

    }
  }
}


text:
package todo.model;

import java.util.Date;
import java.util.regex.Pattern;

/**
 * Custom class holds two date in custom format
 *
 * @author Murat Duzgun
 */
public class DateRange {

    private final static String RANGE_SEPERATOR = "_";

    private Date beginDate;

    private Date endDate;

    public DateRange(Date beginDate, Date endDate) {
        this.beginDate = beginDate;
        this.endDate = endDate;
    }

    public DateRange(String dateRangeStr) throws IllegalArgumentException {

        if (dateRangeStr.contains(RANGE_SEPERATOR)) {

            String[] ranges = dateRangeStr.split(Pattern.quote(RANGE_SEPERATOR));

            if (ranges.length != 2)
                throw new IllegalArgumentException("dateRangeStr must be likely: 39283129382|312321321!");

            this.beginDate = new Date(Long.parseLong(ranges[0]));
            this.endDate = new Date(Long.parseLong(ranges[1]));
        }
    }

    public Date getBeginDate() {
        return beginDate;
    }

    public void setBeginDate(Date beginDate) {
        this.beginDate = beginDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
}


text:
// -*- c++ -*-
// Generated by gmmproc 2.44.0 -- DO NOT MODIFY!
#ifndef _GTKMM_ORIENTABLE_H
#define _GTKMM_ORIENTABLE_H

#include <glibmm/ustring.h>
#include <sigc++/sigc++.h>

#include <glibmm/interface.h>
#include <gtkmm/enums.h>

#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C"
{
typedef struct _GtkOrientableIface GtkOrientableIface;
}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct _GtkOrientable GtkOrientable;
typedef struct _GtkOrientableClass GtkOrientableClass;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace Gtk
{ class Orientable_Class; } // namespace Gtk
#endif // DOXYGEN_SHOULD_SKIP_THIS

namespace Gtk
{

/** This interface is implemented by all widgets that can be oriented
 * horizontally or vertically. Historically, such widgets have been realized as
 * subclasses of a common base class (e.g GtkBox/GtkHBox/GtkVBox and
 * GtkScale/GtkHScale/GtkVScale). GtkOrientable is more flexible in that it
 * allows the orientation to be changed at runtime, allowing the widgets to 'flip'.
 *
 * @newin{2,16}
 */

class Orientable : public Glib::Interface
{

#ifndef DOXYGEN_SHOULD_SKIP_THIS

public:
  typedef Orientable CppObjectType;
  typedef Orientable_Class CppClassType;
  typedef GtkOrientable BaseObjectType;
  typedef GtkOrientableIface BaseClassType;

private:
  friend class Orientable_Class;
  static CppClassType orientable_class_;

  // noncopyable
  Orientable(const Orientable&);
  Orientable& operator=(const Orientable&);

#endif /* DOXYGEN_SHOULD_SKIP_THIS */
protected:
  /**
   * You should derive from this class to use it.
   */
  Orientable();

#ifndef DOXYGEN_SHOULD_SKIP_THIS
  /** Called by constructors of derived classes. Provide the result of
   * the Class init() function to ensure that it is properly
   * initialized.
   *
   * @param interface_class The Class object for the derived type.
   */
  explicit Orientable(const Glib::Interface_Class& interface_class);

public:
  // This is public so that C++ wrapper instances can be
  // created for C instances of unwrapped types.
  // For instance, if an unexpected C type implements the C interface.
  explicit Orientable(GtkOrientable* castitem);

protected:
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

public:
  virtual ~Orientable();

  static void add_interface(GType gtype_implementer);

  /** Get the GType for this class, for use with the underlying GObject type system.
   */
  static GType get_type()      G_GNUC_CONST;

#ifndef DOXYGEN_SHOULD_SKIP_THIS
  static GType get_base_type() G_GNUC_CONST;
#endif

  ///Provides access to the underlying C GObject.
  GtkOrientable*       gobj()       { return reinterpret_cast<GtkOrientable*>(gobject_); }

  ///Provides access to the underlying C GObject.
  const GtkOrientable* gobj() const { return reinterpret_cast<GtkOrientable*>(gobject_); }

private:

public:

  /** Sets the orientation of the @a orientable.
   *
   * @newin{2,16}
   *
   * @param orientation The orientable's new orientation.
   */
  void set_orientation(Orientation orientation);

  /** Retrieves the orientation of the @a orientable.
   *
   * @newin{2,16}
   *
   * @return The orientation of the @a orientable.
   */
  Orientation get_orientation() const;

  /** The orientation of the orientable.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the value of the property,
   * or receive notification when the value of the property changes.
   */
  Glib::PropertyProxy< Orientation > property_orientation() ;

/** The orientation of the orientable.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy_ReadOnly that allows you to get the value of the property,
   * or receive notification when the value of the property changes.
   */
  Glib::PropertyProxy_ReadOnly< Orientation > property_orientation() const;

public:

public:
  //C++ methods used to invoke GTK+ virtual functions:

protected:
  //GTK+ Virtual Functions (override these to change behaviour):

  //Default Signal Handlers::

};

} // namespace Gtk

namespace Glib
{
  /** A Glib::wrap() method for this object.
   *
   * @param object The C instance.
   * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
   * @result A C++ instance that wraps this C instance.
   *
   * @relates Gtk::Orientable
   */
  Glib::RefPtr<Gtk::Orientable> wrap(GtkOrientable* object, bool take_copy = false);

} // namespace Glib

#endif /* _GTKMM_ORIENTABLE_H */


text:
<bill session="110" type="hr" number="633" updated="2009-01-09T09:10:58-05:00">
	<status><vote date="1189088340" datetime="2007-09-06T11:19:00-04:00" where="h" result="pass" how="roll" roll="855"/></status>

	<introduced date="1188964800" datetime="2007-09-05"/>
	<titles>
		<title type="official" as="introduced">Providing for consideration of the bill (H.R. 2786) to reauthorize the programs for housing assistance for Native Americans.</title>
	</titles>
	<sponsor id="400263"/>
	<cosponsors>

	</cosponsors>
	<actions>
		<action date="1189024080" datetime="2007-09-05T17:28:00-04:00"><text>The House Committee on Rules reported an original measure, H. Rept. 110-316, by Mr. McGovern.</text></action>
		<action date="1189024080" datetime="2007-09-05T17:28:00-04:00"><text>Rule provides for consideration of H.R. 2786 with 1 hour of general debate. Previous question shall be considered as ordered without intervening motions except motion to recommit with or without instructions. Measure will be considered read. Bill is open to amendments.</text></action>
		<calendar date="1189024080" datetime="2007-09-05T17:28:00-04:00" ><text>Placed on the House Calendar, Calendar No. 107.</text></calendar>
		<action date="1189085100" datetime="2007-09-06T10:25:00-04:00"><text>Considered as privileged matter.</text><reference label="consideration" ref="CR H10164-10166"/></action>
		<action date="1189085160" datetime="2007-09-06T10:26:00-04:00"><text>DEBATE - The House proceeded with one hour of debate on H. Res. 633.</text></action>
		<action date="1189086180" datetime="2007-09-06T10:43:00-04:00"><text>The previous question was ordered without objection.</text><reference label="consideration" ref="CR H10166"/></action>
		<action date="1189086240" datetime="2007-09-06T10:44:00-04:00"><text>POSTPONED PROCEEDINGS - At the conclusion of the debate on H.Res. 633, the Chair put the question on adoption of the resolution and by voice vote, announced that the ayes had prevailed. Mr. McGovern objected to the voice vote based upon the absence of a quorum. The Chair postponed further proceedings on the question of adoption until later in the legislative day. The point of no quorum is considered as withdrawn.</text></action>
		<action date="1189087740" datetime="2007-09-06T11:09:00-04:00"><text>Considered as unfinished business.</text><reference label="consideration" ref="CR H10167-10168"/></action>
		<vote date="1189088340" how="roll" roll="855" datetime="2007-09-06T11:19:00-04:00" where="h" type="vote" result="pass" ><text>On agreeing to the resolution Agreed to by the Yeas and Nays: 221 - 178 (Roll no. 855).</text><reference label="text" ref="CR H10164"/></vote>
	</actions>
	<committees>

	</committees>
	<relatedbills>

	</relatedbills>
	<subjects>

	</subjects>
	<amendments>

	</amendments>
	<summary>
	9/6/2007--Passed House without amendment. Sets forth the rule for consideration of H.R. 2786 (Native American Housing Assistance and Self-Determination Reauthorization Act of 2007).<br/>
	</summary>
</bill>


text:
package ie.ucd.clops.runtime.automaton;

/*
 * The implementation slighty follows the reg-exp NDA implementation at
 * http://swtch.com/~rsc/regexp/
 */

import ie.ucd.clops.runtime.automaton.exception.EmptyAlternativeException;
import ie.ucd.clops.runtime.automaton.exception.EmptyFormatException;
import ie.ucd.clops.runtime.automaton.exception.LeftOpenBracketException;
import ie.ucd.clops.runtime.automaton.exception.OpenPlusException;
import ie.ucd.clops.runtime.automaton.exception.OpenQuestionException;
import ie.ucd.clops.runtime.automaton.exception.OpenStarException;
import ie.ucd.clops.runtime.automaton.exception.RightOpenBracketException;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import java.util.Set;
import java.util.IdentityHashMap;

/**
 * Represents a regular expression (command line format) as a finite-state automaton and enables traversing
 * the automaton with tokens of the regular expression (options).
 *
 * @param <T> TODO
 *
 * @author Viliam Holub
 * @author Mikolas Janota
 */
public class Automaton<T> {

	/*
	 * Automaton fields
	 */
	/** Starting state of the automaton. */
	State<T> /*@ non_null @*/ start_state;

	/** Automaton state.
	 */
	public class AutomatonRun {
		/** Indication of error state.
		 * If this variable is set, we are in the error state. */
		boolean error;
		/** List of active states.
		 * The list is updated every step. */
		IdentityHashMap<State<T>,Integer> /*@ non_null @*/ actives;
		/** Backup of active states. Used for backtracking. */
		Stack<IdentityHashMap<State<T>,Integer>> archive;

		AutomatonRun() {
			error = false;
			actives = new IdentityHashMap<State<T>,Integer>();
			archive = new Stack<IdentityHashMap<State<T>,Integer>>();
			addSuccessors( start_state, actives);
		}

		/** Adds MATCH and END successors of a state.
		 * To avoid duplicates in the output list (and avoid cycling as well),
		 * we update each state with step index and process only those, which
		 * state index is less than the current one. Uses recursion to
		 * transitively explore the graph.
		 * @param state state to add or follow
		 * @param successors output list of states
		 */
		private void addSuccessors2(
				/*@ non_null @*/ State<T> state,
				/*@ non_null @*/ IdentityHashMap<State<T>,Integer> nexts) {
			if (state == null || nexts.containsKey( state))
				return;
			nexts.put( state, null);
			//state.state_index = step_index; //XXX
			if (state.type == StateType.SPLIT) {
				addSuccessors2( state.next1, nexts);
				addSuccessors2( state.next2, nexts);
			} else {
				nexts.put( state, null);
			}
		}

		/** Adds successors of s of the type MATCH or END to the list.
		 * Type of the state s must by MATCH or END.
		 * @param state state to follow
		 * @param next output successor states
		 */
		private void addSuccessors(
				/*@ non_null @*/ State<T> state,
				/*@ non_null @*/ IdentityHashMap<State<T>,Integer> nexts) {
			addSuccessors2( state.next1, nexts);
			addSuccessors2( state.next2, nexts);
		}

		/** Follows specified transitions in the automaton and returns MATCH and END successor states.
		 * @param state state to follow
		 * @param transition_labels a collection of transition labels to process
		 * @param actives list of currently active states
		 * @param nexts output list of successor states
		 */
		private void follow(
				/*@ non_null @*/ State<T> state,
				/*@ non_null @*/ Collection<T> transition_labels,
				/*@ non_null @*/ IdentityHashMap<State<T>,Integer> nexts) {

			// Type of the state must be ready to match.
			if (state.type != StateType.MATCH)
				return;
			// Follow all the transition labels.
			for (T transition_label:transition_labels) {
				if (state.match.equals( transition_label)) {
					// We have a match, add succesors
					addSuccessors( state, nexts);
				}
			}
		}

		/** Apply next step in automaton.
		 * If possible (i.e. matched), we follow all the transitions for all the active states.
		 * @param t a collection of transition labels to process
		 * @return true iff we could follow at least one of the transition labels
		 */
		public boolean nextStep( /*@ non_null @*/ Collection<T> t) {
			// Do not continue if we are in an error state
			if (error)
				return false;

			// Process next step, store states
			archive.push( actives);
			IdentityHashMap<State<T>,Integer> nexts = new IdentityHashMap<State<T>,Integer>();
			for (State<T> s:actives.keySet())
				follow( s, t, nexts);
			actives = nexts;

			// If the resulting list of states is empty, we are in an error
			// state
			error = actives.isEmpty();

			return !error;
		}

		/** Apply next step in automaton.
		 * @param transition a transition label to process
		 * @return true iff it was possible to follow the given transition
		 */
		public boolean nextStep( /*@ non_null @*/ T transition) {
			Collection<T> trans = new LinkedList<T>();
			trans.add( transition);
			return nextStep( trans);
		}

		/** Determines whether the automaton is in an accepting state.
		 * Automaton is accepting if at least one of the current automaton
		 * states is accepting.
		 *
		 * @return true iff the automaton is in an accepting state
		 */
		/*@pure*/public boolean isAccepting() {
			for (State<T> s:actives.keySet()) {
				if (s.isAccepting())
					return true;
			}
			return false;
		}

		/** Determines whether the automaton is in an error state.
		 * @return true iff the automaton is in an error state
		 */
		/*@pure*/public boolean inErrorState() {
			return error;
		}

		/** Computes a list of transitions that lead from the current state to
		 * a state that is not an error state.
		 * @return list of available trantions
		 */
		//@ ensures \fresh(\result);
		/*@pure*/public /*@non_null*/List<T> availableTransitions() {
			List<T> transitions = new LinkedList<T>();
			for (State<T> state : actives.keySet())
				if (state.type == StateType.MATCH)
					transitions.add( state.match);
			return transitions;
		}

		/** Computes a set of available transitions.
		 * @see ie.ucd.clops.runtime.automaton.Automaton#availableTransitions()
		 * @return set of available transitions
		 */
		//@ ensures \fresh(\result);
		/*@pure*/public /*@non_null*/HashSet<T> availableTransitionsUnique() {
		    return new HashSet<T>( availableTransitions());
		}

		/** Undo the last {@code nextStep()} call. */
		public void previousStep() {
			actives = archive.pop();
		}

		/** Returns a set of active states.
		 */
		public Set<State<T>> activeStates() {
			return actives.keySet();
		}
	}

	/*
	 * Code
	 */

	/** Creates an automaton representation of a given command line format.
         * @param tokens a regular expression represented as a set of tokens
         * @see ie.ucd.clops.runtime.automaton.Tokenizer
	 */
	//@ tokens.size() != 0;
	public Automaton( /*@ non_null @*/ List<Token<T>> tokens)
			throws RightOpenBracketException, LeftOpenBracketException,
			OpenQuestionException, EmptyAlternativeException,
			OpenStarException, OpenPlusException, EmptyFormatException {

		build( tokens);
	}

	/**
	 * Context class used for format parsing and automation building.
	 */
	private class Context {
		int alternatives; // Level of alternatives "|"
		int atoms; // Number of atoms (options to concatenate)
	}

	/**
	 * Builds an automaton from a given  list of tokens.
	 */
	//@ tokens.size() != 0;
	private void build( /*@ non_null @*/ List<Token<T>> tokens)
			throws RightOpenBracketException, LeftOpenBracketException,
			OpenQuestionException, EmptyAlternativeException,
			OpenStarException, OpenPlusException, EmptyFormatException {
		// Stack of contexts, each context represents nested ()
		Stack<Context> ctxs = new Stack<Context>();
		// Fragments of automaton
		Stack<Fragment<T>> fragments = new Stack<Fragment<T>>();
		// Current context
		Context ctx = new Context();

		for (Token<T> t:tokens) switch (t.type) {
			case MATCH:
				// If there are two atom fragments on stack, concatenate
				if (ctx.atoms > 1) {
					Fragment<T> f = fragments.pop();
					fragments.peek().concatenate( f);
					ctx.atoms--;
				}
				// Create fragment that matches the given string
				// Push fragment into stack
				fragments.push( new Fragment<T>( new State<T>( StateType.MATCH, t.match)));
				ctx.atoms++;
				break;
			case LEFT:
				// Concatenate atoms on stack
				if (ctx.atoms > 1) {
					Fragment<T> f = fragments.pop();
					fragments.peek().concatenate( f);
					ctx.atoms--;
				}
				// Save context and create a new one
				ctxs.push( ctx);
				ctx = new Context();
				break;
			case RIGHT:
				// Test if right bracket without left one
				if (ctxs.size() == 0)
					throw new RightOpenBracketException();

				// If there are no atoms, syntax error -- ok if alternatives != 0
				if (ctx.atoms == 0) {
					throw new RightOpenBracketException();
				}
				// Concatenate atoms on stack
				if (ctx.atoms > 1) {
					Fragment<T> f = fragments.pop();
					fragments.peek().concatenate( f);
					ctx.atoms--;
				}
				// Create alternatives from fragments on stack
				if (ctx.alternatives > 0) {
					if (fragments.size() == 1)
						throw new EmptyAlternativeException();
					fragments.push( Fragment.alternative(
						fragments.pop(), fragments.pop()));
				}
				// Recover old context
				ctx = ctxs.pop();
				ctx.atoms++;
				break;
			case OR:
				if (ctx.atoms == 0 && ctx.alternatives != 0) {
					// Use of multiple alternatives ||
					// Ignore this one
					break;
				}
				if (ctx.atoms == 0 && ctx.alternatives == 0) {
					// If there are no fragments, raise error
					throw new EmptyAlternativeException();
				}

				// Concatenate fragments on stack
				while (ctx.atoms>1) {
					// Concatenate two fragments
					Fragment<T> f = fragments.pop();
					fragments.peek().concatenate( f);
					ctx.atoms--;
				}
				// Continue to make alternatives...
				if (ctx.alternatives > 0) {
					fragments.push( Fragment.alternative(
						fragments.pop(), fragments.pop()));
				}
				// Set status of alternatives
				ctx.alternatives = 1;
				ctx.atoms = 0;
				break;
			case PLUS:
				// If there are no atom fragments, raise error
				if (ctx.atoms == 0) throw new OpenPlusException();
				// Apply operator to the last fragment
				fragments.push( Fragment.apply_operator( TokenType.PLUS, fragments.pop()));
				break;
			case STAR:
				// If there are no atom fragments, raise error
				if (ctx.atoms == 0) throw new OpenStarException();
				// Apply operator to the last fragment
				fragments.push( Fragment.apply_operator( TokenType.STAR, fragments.pop()));
				break;
			case QUESTION:
				// If there are no atom fragments, raise error
				if (ctx.atoms == 0) throw new OpenQuestionException();
				// Apply operator to the last fragment
				fragments.push( Fragment.apply_operator( TokenType.QUESTION, fragments.pop()));
				break;
		}

		// Report error if there are unclosed brackets
		if (ctxs.size() != 0)
			throw new LeftOpenBracketException();

		// If the stack is empty, comply
		if (fragments.size() == 0) {
			throw new EmptyFormatException();
		}
		// Concatenate any residual atoms
		if (ctx.atoms > 1) {
			Fragment<T> f = fragments.pop();
			fragments.peek().concatenate( f);
		}
		// If there is unclosed alternative, close it
		if (ctx.alternatives != 0) {
			if (fragments.size() == 1)
				throw new EmptyAlternativeException();
			fragments.push( Fragment.alternative(
					fragments.pop(), fragments.pop()));
		}
		// Create final fragment
		State<T> s = new State<T>( StateType.END, null, null, null);
		Fragment<T> fin = fragments.pop();
		fin.assignNext( s);

		assert fragments.isEmpty();

		// Write start state
		start_state = new State<T>( StateType.SPLIT, null, fin.start, null);
	}

	/** Returns followable NDA state.
	 */
	public AutomatonRun run() {
		return new AutomatonRun();
	}

	/** Returns initial state.
	 */
	public State<T> getInitialState() {
		return start_state;
	}

	/** Computes a list of transitions that lead from the state specified.
	 *
	 * @param state root state
	 * @return list of available trantions
	 */
	/*@pure*/public /*@non_null*/List<T> getOutgoing( State<T> state) {
		List<T> transitions = new LinkedList<T>();
		if (state.type == StateType.MATCH)
			transitions.add( state.match);
		return transitions;
	}
}


text:
module Gamification
  module Checksum
    # Generate a checksum from the given values.
    #
    # values - An Array of values.
    #
    # Returns a String.
    def self.generate values
      Digest::MD5.hexdigest "#{secret_key}#{values.join}"
    end

    # Verify a given checksum against the given values.
    #
    # checksum - A String describing a checksum.
    # values   - An Array of values.
    #
    # Returns a boolean.
    def self.verify checksum, values
      checksum == generate(values)
    end

    private

    def self.secret_key
      Rails.application.secrets[:secret_key_base]
    end
  end
end