com.wix.accord

java8

package java8

Adds support for temporals (and subclasses) to the Accord DSL.

Usage

To use these extensions, import this package as follows:

import java.time.LocalDateTime
import java.time.temporal.ChronoUnit
import java.time.Duration

case class Person( name: String, birthDate: LocalDateTime )

// Import the Accord DSL and Java 8 extensions...
import com.wix.accord.dsl._
import com.wix.accord.java8._

// LocalDateTime (and other temporals) are now supported
implicit val personValidator = validator[ Person ] { p =>
  p.name is notEmpty
  p.birthDate is before( LocalDateTime.now )
}

Combinators

Supported operations:

// Simple equality/inequality
val lastYear = LocalDateTime.now.minus( 1L, ChronoUnit.YEARS )
p.birthDate is equalTo( lastYear )
p.birthDate is notEqualTo( lastYear )

// Equality with tolerance (both variants are equivalent)
val oneWeek = Duration.ofDays( 7L )
p.birthDate is within( oneWeek ).of( lastYear )
p.birthDate is within( 7L, ChronoUnit.DAYS ).of( lastYear )

// Before/after
val ageOfAdulthood = LocalDateTime.now.minus( 18L, ChronoUnit.YEARS )
p.birthDate is before( ageOfAdulthood )
p.birthDate is after( ageOfAdulthood )

// Arithmetic-style operations
p.birthDate must be <= ageOfAdulthood
p.birthDate is between( lastYear, LocalDateTime.now.minus( oneWeek ) )
Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. java8
  2. TemporalOps
  3. TemporalCombinators
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. class After[T <: Temporal] extends NullSafeValidator[T]

    A validator that succeeds only for values that come strictly after before the specified bound.

    A validator that succeeds only for values that come strictly after before the specified bound.

    T

    The specific temporal type this validator operates on.

    Definition Classes
    TemporalCombinators
  2. class Before[T <: Temporal] extends NullSafeValidator[T]

    A validator that succeeds only for values that come strictly before the specified bound.

    A validator that succeeds only for values that come strictly before the specified bound.

    T

    The specific temporal type this validator operates on.

    Definition Classes
    TemporalCombinators
  3. implicit class ExtendAccordDSL extends AnyRef

    Extends the Accord DSL with additional within operations over temporals.

    Extends the Accord DSL with additional within operations over temporals.

    Definition Classes
    TemporalOps
  4. trait TemporalCombinators extends AnyRef

    Combinators that operate specifically on temporals (and subclasses thereof).

  5. trait TemporalOps extends AnyRef

    Provides a DSL for validating temporals (and subclasses thereof).

  6. class Within[T <: Temporal] extends NullSafeValidator[T]

    A validator that succeeds only for values that are within (i.

    A validator that succeeds only for values that are within (i.e. before or after) a duration of the specified temporal (for example, "within a month of this person's birth date").

    This is essentially equivalent to (value >= of - duration) && (value <= of + duration).

    T

    The specific temporal type this validator operates on.

    Definition Classes
    TemporalCombinators
  7. class WithinBuilder[T <: Temporal] extends AnyRef

    A builder to support the within DSL extensions.

    A builder to support the within DSL extensions.

    Definition Classes
    TemporalOps

Value Members

  1. def after[T <: Temporal](right: T): After[T]

    Generates a validator that succeeds only if the provided value comes strictly after the specified bound.

    Generates a validator that succeeds only if the provided value comes strictly after the specified bound.

    Definition Classes
    TemporalOps
  2. def before[T <: Temporal](right: T): Before[T]

    Generates a validator that succeeds only if the provided value comes strictly before the specified bound.

    Generates a validator that succeeds only if the provided value comes strictly before the specified bound.

    Definition Classes
    TemporalOps
  3. implicit def temporalOrdering[T <: Temporal]: Ordering[T]

    Implements Ordering over Temporal and its subclasses.

    Implements Ordering over Temporal and its subclasses.

    Implementation note: this assumes T implements Comparable, which per the JavaDoc for java.time.temporal.Temporal should always be the case.

    T

    The specific temporal type for which to construct an Ordering.

    Definition Classes
    TemporalCombinators

Inherited from TemporalOps

Inherited from TemporalCombinators

Inherited from AnyRef

Inherited from Any

Ungrouped