alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (Properties.scala)

This example Scala source code file (Properties.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

consolereporter, incorrect, nosuccess, nosuccess, prop, prop, properties, propertyspecifier, seq, string, success, success, unit, unit

The Scala Properties.scala source code

/*-------------------------------------------------------------------------*\
**  ScalaCheck                                                             **
**  Copyright (c) 2007-2010 Rickard Nilsson. All rights reserved.          **
**  http://www.scalacheck.org                                              **
**                                                                         **
**  This software is released under the terms of the Revised BSD License.  **
**  There is NO WARRANTY. See the file LICENSE for the full text.          **
\*-------------------------------------------------------------------------*/

package org.scalacheck

/** Represents a collection of properties, with convenient methods
 *  for checking all properties at once. This class is itself a property, which
 *  holds if and only if all of the contained properties hold.
 *  <p>Properties are added in the following way:

* * <p> * <code> * object MyProps extends Properties("MyProps") { * property("myProp1") = forAll { (n:Int, m:Int) => * n+m == m+n * } * * property("myProp2") = ((0/1) throws classOf[ArithmeticException]) * } */ class Properties(val name: String) extends Prop { import Test.cmdLineParser.{Success, NoSuccess} private val props = new scala.collection.mutable.ListBuffer[(String,Prop)] /** Returns one property which holds if and only if all of the * properties in this property collection hold */ private def oneProperty: Prop = Prop.all((properties map (_._2)):_*) /** Returns all properties of this collection in a list of name/property * pairs. */ def properties: Seq[(String,Prop)] = props def apply(p: Prop.Params) = oneProperty(p) /** Convenience method that checks the properties with the given parameters * and reports the result on the console. If you need to get the results * from the test use the <code>check methods in Test * instead. */ override def check(prms: Test.Params): Unit = Test.checkProperties( prms copy (testCallback = ConsoleReporter(1) chain prms.testCallback), this ) /** Convenience method that checks the properties and reports the * result on the console. If you need to get the results from the test use * the <code>check methods in Test instead. */ override def check(): Unit = check(Test.Params()) /** Convenience method that makes it possible to use a this instance * as an application that checks itself on execution */ override def main(args: Array[String]): Unit = Test.cmdLineParser.parseParams(args) match { case Success(params, _) => Test.checkProperties(params, this) case e: NoSuccess => println("Incorrect options:"+"\n"+e+"\n") Test.cmdLineParser.printHelp } /** Adds all properties from another property collection to this one. */ def include(ps: Properties) = for((n,p) <- ps.properties) property(n) = p /** Used for specifying properties. Usage: * <code>property("myProp") = ... */ class PropertySpecifier() { def update(propName: String, p: Prop) = props += ((name+"."+propName, p)) } lazy val property = new PropertySpecifier() }

Other Scala examples (source code examples)

Here is a short list of links related to this Scala Properties.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.