com.rojoma.json.matcher

Variable

abstract class Variable[T] extends Pattern with PartialFunction[Results, T]

A com.rojoma.json.matcher.Pattern which matches any com.rojoma.json.ast.JValue which can be decoded into an object of type T. If this variable is already bound in the environment at match-time, then this matches only if the two decoded objects are equal, in which case the environment is unchanged.

Linear Supertypes
PartialFunction[Results, T], (Results) ⇒ T, Pattern, OptPattern, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Variable
  2. PartialFunction
  3. Function1
  4. Pattern
  5. OptPattern
  6. AnyRef
  7. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Variable()

Abstract Value Members

  1. abstract def evaluate(x: JValue, environment: Results): Option[Results]

    Tests the given com.rojoma.json.ast.JValue against this Pattern, with the restriction that any com.rojoma.json.matcher.Variables that are bound in the environment must match those values if they are re-used in this Pattern.

    Tests the given com.rojoma.json.ast.JValue against this Pattern, with the restriction that any com.rojoma.json.matcher.Variables that are bound in the environment must match those values if they are re-used in this Pattern.

    Generally you won't use this directly.

    x

    The value to test.

    returns

    The environment augmented with any new com.rojoma.json.matcher.Variables encountered in this Pattern, or None if it didn't match.

    Definition Classes
    Pattern
  2. abstract def generate(environment: Results): Option[JValue]

    Uses this Pattern together with the bindings generated as the result of a call to matches or evaluate to produce a com.rojoma.json.ast.JValue.

    Uses this Pattern together with the bindings generated as the result of a call to matches or evaluate to produce a com.rojoma.json.ast.JValue.

    Generally the other generate method is simpler to use.

    returns

    The new com.rojoma.json.ast.JValue, or None if a required com.rojoma.json.matcher.Variable is not bound in the environment, or a matcher which cannot generate is used.

    Definition Classes
    Pattern

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def :=(x: T): (Results) ⇒ Results

    Bind this variable into an environment.

    Bind this variable into an environment. This is usually used with com.rojoma.json.matcher.Pattern#generate.

    Example:
    1. val intVar = Variable[Int]
      val pattern = PObject("i" -> intVar)
      
      println(pattern.generate(intVar := 5)) // { "i" : 5 }
  5. def :=?(x: Option[T]): (Results) ⇒ Results

    Possibly this variable into an environment.

    Possibly this variable into an environment. This is usually used with com.rojoma.json.matcher.Pattern#generate.

    Example:
    1. val intVar = Variable[Int]
      val pattern = PObject("i" -> POption(intVar))
      
      println(pattern.generate(intVar :=? Some(5))) // { "i" : 5 }
      println(pattern.generate(intVar :=? None)) // { }
  6. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  7. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  8. def andThen[C](k: (T) ⇒ C): PartialFunction[Results, C]

    Definition Classes
    PartialFunction → Function1
  9. def apply(results: Results): T

    Look up the value of this variable in an environment.

    Look up the value of this variable in an environment.

    returns

    The value found

    Definition Classes
    Variable → Function1
    Exceptions thrown
    NoSuchElementException

    if the variable is not bound.

  10. def applyOrElse[A1 <: Results, B1 >: T](x: A1, default: (A1) ⇒ B1): B1

    Definition Classes
    PartialFunction
  11. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  12. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  13. def compose[A](g: (A) ⇒ Results): (A) ⇒ T

    Definition Classes
    Function1
    Annotations
    @unspecialized()
  14. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  16. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. def generate(bindings: (Results) ⇒ Results*): JValue

    Uses this Pattern together with the provided variable bindings to generate a new com.rojoma.json.ast.JValue.

    Uses this Pattern together with the provided variable bindings to generate a new com.rojoma.json.ast.JValue.

    returns

    The new com.rojoma.json.ast.JValue

    Definition Classes
    Pattern
    Example:
    1. val intVar = Variable[Int]
      val strVar = Variable[String]
      val pattern = PObject("i" -> intVar, "s" -> POption(strVar))
      
      pattern.generate(i := 1)                      // { "i" : 1 }
      pattern.generate(i := 1, s := "hello")        // { "i" : 1, "s" : "hello" }
      pattern.generate(i := 1, s :=? None )         // { "i" : 1 }
      pattern.generate(i := 1, s :=? Some("hello")) // { "i" : 1, "s" : "hello" }
    Exceptions thrown
    JsonGenerationException

    if a required com.rojoma.json.matcher.Variable is not bound or a matcher which cannot generate (such as com.rojoma.json.matcher.AllOf) is used.

  18. def get(results: Results): Option[T]

    Look up the value of this variable in an environment.

    Look up the value of this variable in an environment.

    returns

    The value found, or None if it was not bound.

  19. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  20. def getOrElse[U >: T](results: Results, alternative: ⇒ U): U

    Look up the value of this variable in an environment.

    Look up the value of this variable in an environment.

    returns

    The value found, or alternative if it was not bound.

  21. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  22. def isBound(results: Results): Boolean

  23. def isDefinedAt(results: Results): Boolean

    Definition Classes
    Variable → PartialFunction
  24. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  25. def lift: (Results) ⇒ Option[T]

    Definition Classes
    PartialFunction
  26. def matches(x: JValue): Option[Results]

    Tests the given com.rojoma.json.ast.JValue against this Pattern, and if it matches returns an object that can be used to retrieve the values matched by any com.rojoma.json.matcher.Variables in the Pattern.

    Tests the given com.rojoma.json.ast.JValue against this Pattern, and if it matches returns an object that can be used to retrieve the values matched by any com.rojoma.json.matcher.Variables in the Pattern.

    x

    The value to test.

    returns

    An environment which can be used to look up variable bindings, or None if it didn't match.

    Definition Classes
    Pattern
    Example:
    1. val intVar = Variable[Int]
      val strVar = Variable[String]
      val pattern = PObject("i" -> intVar, "s" -> strVar)
      
      pattern.matches(jvalue) match {
        case Some(results) => println("The integer was " + intVar(results))
        case None => println("It didn't match the pattern")
      }
  27. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  28. final def notify(): Unit

    Definition Classes
    AnyRef
  29. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  30. def orElse[A1 <: Results, B1 >: T](that: PartialFunction[A1, B1]): PartialFunction[A1, B1]

    Definition Classes
    PartialFunction
  31. def runWith[U](action: (T) ⇒ U): (Results) ⇒ Boolean

    Definition Classes
    PartialFunction
  32. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  33. def toString(): String

    Definition Classes
    Function1 → AnyRef → Any
  34. def unapply(x: JValue): Option[Results]

    Allows this Pattern to be used in a match expression, with the output being the environment of com.rojoma.json.matcher.Variable bindings as produced by matches.

    Allows this Pattern to be used in a match expression, with the output being the environment of com.rojoma.json.matcher.Variable bindings as produced by matches.

    Definition Classes
    Pattern
    Example:
    1. val intVar = Variable[Int]
      val strVar = Variable[String]
      val Pattern1 = PObject("i" -> intVar, "s" -> strVar)
      val Pattern2 = PObject("hello" -> "world")
      
      jvalue match {
        case Pattern1(results) => println("The integer was " + intVar(results))
        case Pattern2(result) => println("It was just a hello world object")
        case _ => println("It was something else")
      }
  35. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  36. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  37. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from PartialFunction[Results, T]

Inherited from (Results) ⇒ T

Inherited from Pattern

Inherited from OptPattern

Inherited from AnyRef

Inherited from Any

Ungrouped