com.rojoma.json.matcher

Variable

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

A Pattern which matches any 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.

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

Instance Constructors

  1. new Variable ()

Abstract Value Members

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

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

    Tests the given JValue against this Pattern, with the restriction that any 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 Variables encountered in this Pattern, or None if it didn't match.

    Attributes
    abstract
    Definition Classes
    Pattern
  2. 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 JValue.

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

    Generally the other generate method is simpler to use.

    returns

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

    Attributes
    abstract
    Definition Classes
    Pattern

Concrete Value Members

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

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

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

    Attributes
    final
    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 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 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. def == (arg0: AnyRef): Boolean

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

    Attributes
    final
    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
  10. def asInstanceOf [T0] : T0

    Attributes
    final
    Definition Classes
    Any
  11. def clone (): AnyRef

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

    Definition Classes
    Function1
  13. def eq (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  14. def equals (arg0: Any): Boolean

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

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

    Uses this Pattern together with the provided variable bindings to generate a new JValue.

    Uses this Pattern together with the provided variable bindings to generate a new JValue.

    returns

    The new 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" }
      
  17. 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.

  18. def getClass (): java.lang.Class[_]

    Attributes
    final
    Definition Classes
    AnyRef
  19. 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.

  20. def hashCode (): Int

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

  22. def isDefinedAt (results: Results): Boolean

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

    Attributes
    final
    Definition Classes
    Any
  24. def lift : (Results) ⇒ Option[T]

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

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

    Tests the given JValue against this Pattern, and if it matches returns an object that can be used to retrieve the values matched by any 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")
      }
      
  26. def ne (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  27. def notify (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  28. def notifyAll (): Unit

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

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

    Attributes
    final
    Definition Classes
    AnyRef
  31. def toString (): String

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

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

    Allows this Pattern to be used in a match expression, with the output being the environment of 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")
      }
      
  33. def wait (): Unit

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

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

    Attributes
    final
    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