|
Scala example source code file (PartialOrdering.scala)
This example Scala source code file (PartialOrdering.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.
The Scala PartialOrdering.scala source code
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
package scala.math
/** <p>
* A trait for representing partial orderings. It is important to
* distinguish between a type that has a partial order and a representation
* of partial ordering on some type. This trait is for representing the
* latter.
* </p>
* <p>
* A <a href="http://en.wikipedia.org/wiki/Partial_order">partial ordering
* is a binary relation on a type <code>T that is also an equivalence
* relation on values of type <code>T. This relation is exposed as
* the <code>lteq method of the PartialOrdering trait.
* This relation must be:
* </p>
* <ul>
* <li>reflexive: lteq(x, x) == true , for any x of
* type <code>T.
* <li>anti-symmetric: lteq(x, y) == true and
* <code>lteq(y, x) == true then equiv(x, y) , for any
* <code>x and y of type T .
* <li>transitive: if lteq(x, y) == true and
* <code>lteq(y, z) == true then lteq(x, z) == true ,
* for any <code>x, y , and z of type
* <code>T.
* </ul>
*
* @author Geoffrey Washburn
* @version 1.0, 2008-04-0-3
* @since 2.7
*/
trait PartialOrdering[T] extends Equiv[T] {
outer =>
/** Result of comparing <code>x with operand y .
* Returns <code>None if operands are not comparable.
* If operands are comparable, returns <code>Some(r) where
* <code>r < 0 iff x < y
* <code>r == 0 iff x == y
* <code>r > 0 iff x > y
*/
def tryCompare(x: T, y: T): Option[Int]
/** Returns <code>true iff x comes before
* <code>y in the ordering.
*/
def lteq(x: T, y: T): Boolean
/** Returns <code>true iff y comes before
* <code>x in the ordering.
*/
def gteq(x: T, y: T): Boolean = lteq(y, x)
/** Returns <code>true iff x comes before
* <code>y in the ordering and is not the same as y .
*/
def lt(x: T, y: T): Boolean = lteq(x, y) && !equiv(x, y)
/** Returns <code>true iff y comes before
* <code>x in the ordering and is not the same as x .
*/
def gt(x: T, y: T): Boolean = gteq(x, y) && !equiv(x, y)
/** Returns <code>true iff x is equivalent to
* <code>y in the ordering.
*/
def equiv(x: T, y: T): Boolean = lteq(x,y) && lteq(y,x)
def reverse : PartialOrdering[T] = new PartialOrdering[T] {
override def reverse = outer
def lteq(x: T, y: T) = outer.lteq(y, x)
def tryCompare(x: T, y: T) = outer.tryCompare(y, x)
}
}
Other Scala examples (source code examples)
Here is a short list of links related to this Scala PartialOrdering.scala source code file:
|