scala.sys.BooleanProp

trait BooleanProp extends Prop[Boolean]

A few additional conveniences for Boolean properties.

Abstract Value Members From scala.sys.Prop

abstract def option: Option[Boolean]

Some(value) if the property is set, None otherwise.

  • Definition Classes
    • Prop

(defined at scala.sys.Prop)

abstract def set(newValue: String): String

Sets the property.

  • newValue
    • the new string value
  • returns
    • the old value, or null if it was unset.
  • Definition Classes
    • Prop

(defined at scala.sys.Prop)

abstract def setValue[T1 >: Boolean](value: T1): Boolean

Sets the property with a value of the represented type.

  • Definition Classes
    • Prop

(defined at scala.sys.Prop)

abstract def zero: Boolean

A value of type T for use when the property is unset. The default implementation delivers null for reference types and 0/0.0/false for non-reference types.

  • Attributes
    • protected
  • Definition Classes
    • Prop

(defined at scala.sys.Prop)

Concrete Value Members From scala.sys.Prop

abstract def clear(): Unit

Removes the property from the underlying map.

  • Definition Classes
    • Prop

(defined at scala.sys.Prop)


Concrete Value Members From Implicit scala.sys.BooleanProp.booleanPropAsBoolean ——————————————————————————–

def &&(x: Boolean): Boolean

Compares two Boolean expressions and returns true if both of them evaluate to true.

a && b returns true if and only if

  • a and b are true .

  • Implicit information
    • This member is added by an implicit conversion from BooleanProp to Boolean performed by method booleanPropAsBoolean in scala.sys.BooleanProp.
  • Definition Classes
    • Boolean
  • Note
    • This method uses ‘short-circuit’ evaluation and behaves as if it was declared as def &&(x: => Boolean): Boolean . If a evaluates to false , false is returned without evaluating b .

(added by implicit convertion: scala.sys.BooleanProp.booleanPropAsBoolean)

def &(x: Boolean): Boolean

Compares two Boolean expressions and returns true if both of them evaluate to true.

a & b returns true if and only if

  • a and b are true .

  • Implicit information
    • This member is added by an implicit conversion from BooleanProp to Boolean performed by method booleanPropAsBoolean in scala.sys.BooleanProp.
  • Definition Classes
    • Boolean
  • Note
    • This method evaluates both a and b , even if the result is already determined after evaluating a .

(added by implicit convertion: scala.sys.BooleanProp.booleanPropAsBoolean)

def ^(x: Boolean): Boolean

Compares two Boolean expressions and returns true if they evaluate to a different value.

a ^ b returns true if and only if

  • a is true and b is false or
  • a is false and b is true .

  • Implicit information
    • This member is added by an implicit conversion from BooleanProp to Boolean performed by method booleanPropAsBoolean in scala.sys.BooleanProp.
  • Definition Classes
    • Boolean

(added by implicit convertion: scala.sys.BooleanProp.booleanPropAsBoolean)

def |(x: Boolean): Boolean

Compares two Boolean expressions and returns true if one or both of them evaluate to true.

a | b returns true if and only if

  • a is true or
  • b is true or
  • a and b are true .

  • Implicit information
    • This member is added by an implicit conversion from BooleanProp to Boolean performed by method booleanPropAsBoolean in scala.sys.BooleanProp.
  • Definition Classes
    • Boolean
  • Note
    • This method evaluates both a and b , even if the result is already determined after evaluating a .

(added by implicit convertion: scala.sys.BooleanProp.booleanPropAsBoolean)

def ||(x: Boolean): Boolean

Compares two Boolean expressions and returns true if one or both of them evaluate to true.

a || b returns true if and only if

  • a is true or
  • b is true or
  • a and b are true .

  • Implicit information
    • This member is added by an implicit conversion from BooleanProp to Boolean performed by method booleanPropAsBoolean in scala.sys.BooleanProp.
  • Definition Classes
    • Boolean
  • Note
    • This method uses ‘short-circuit’ evaluation and behaves as if it was declared as def ||(x: => Boolean): Boolean . If a evaluates to true , true is returned without evaluating b . (added by implicit convertion: scala.sys.BooleanProp.booleanPropAsBoolean)

Full Source:

/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2013, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

package scala
package sys

import scala.language.implicitConversions

/** A few additional conveniences for Boolean properties.
 */
trait BooleanProp extends Prop[Boolean] {
  /** The semantics of value are determined at Prop creation.  See methods
   *  `valueIsTrue` and `keyExists` in object BooleanProp for examples.
   *
   *  @return   true if the current String is considered true, false otherwise
   */
  def value: Boolean

  /** Alter this property so that `value` will be true. */
  def enable(): Unit

  /** Alter this property so that `value` will be false. */
  def disable(): Unit

  /** Toggle the property between enabled and disabled states. */
  def toggle(): Unit
}

object BooleanProp {
  private[sys]
  class BooleanPropImpl(key: String, valueFn: String => Boolean) extends PropImpl(key, valueFn) with BooleanProp {
    override def setValue[T1 >: Boolean](newValue: T1): Boolean = newValue match {
      case x: Boolean if !x   => val old = value ; clear() ; old
      case x                  => super.setValue(newValue)
    }
    def enable()  = this setValue true
    def disable() = this.clear()
    def toggle()  = if (value) disable() else enable()
  }
  private[sys]
  class ConstantImpl(val key: String, val value: Boolean) extends BooleanProp {
    val isSet = value
    def set(newValue: String) = "" + value
    def setValue[T1 >: Boolean](newValue: T1): Boolean = value
    def get: String = "" + value
    val clear, enable, disable, toggle = ()
    def option = if (isSet) Some(value) else None
    //def or[T1 >: Boolean](alt: => T1): T1 = if (value) true else alt

    protected def zero = false
  }

  /** The java definition of property truth is that the key be in the map and
   *  the value be equal to the String "true", case insensitively.  This method
   *  creates a BooleanProp instance which adheres to that definition.
   *
   *  @return   A BooleanProp which acts like java's Boolean.getBoolean
   */
  def valueIsTrue[T](key: String): BooleanProp = new BooleanPropImpl(key, _.toLowerCase == "true")

  /** As an alternative, this method creates a BooleanProp which is true
   *  if the key exists in the map and is not assigned a value other than "true",
   *  compared case-insensitively, or the empty string.  This way -Dmy.property
   *  results in a true-valued property, but -Dmy.property=false does not.
   *
   *  @return   A BooleanProp with a liberal truth policy
   */
  def keyExists[T](key: String): BooleanProp = new BooleanPropImpl(key, s => s == "" || s.equalsIgnoreCase("true"))

  /** A constant true or false property which ignores all method calls.
   */
  def constant(key: String, isOn: Boolean): BooleanProp = new ConstantImpl(key, isOn)

  implicit def booleanPropAsBoolean(b: BooleanProp): Boolean = b.value
}