Class Probability

All Implemented Interfaces:
Atomic<Probability>, Comparable<Probability>

public final class Probability extends Primitive<Probability>
This class implements a mathematical probability as a primitive type. The allowed values are double precision floating point numbers in the range [0.0..1.0]. Instances of this class are immutable.
Author:
Derk Norton
  • Constructor Summary

    Constructors
    Constructor
    Description
    This constructor creates a new instance of a probability with a random value between [0.0..1.0).
    Probability​(double value)
    This constructor creates a new instance of a probability with the specified value.
    Probability​(String string)
    This constructor creates a new instance of a probability with the specified value.
  • Method Summary

    Modifier and Type
    Method
    Description
    and​(Probability probability1, Probability probability2)
    This function returns the logical conjunction of the specified probabilities.
    static boolean
    coinToss​(Probability probability)
    This function returns the result of a coin toss that is weighted with the specified probability.
    int
    compareTo​(Probability probability)
     
    boolean
    equals​(Object obj)
     
    int
     
    not​(Probability probability)
    This function returns the logical inverse of the specified probability.
    or​(Probability probability1, Probability probability2)
    This function returns the logical disjunction of the specified probabilities.
    sans​(Probability probability1, Probability probability2)
    This function returns the material nonimplication of the specified probabilities.
    boolean
    This method converts this probability into a boolean value.
    double
    This method converts this probability into a double value.
     
    xor​(Probability probability1, Probability probability2)
    This function returns the logical exclusive disjunction of the specified probabilities.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Probability

      public Probability()
      This constructor creates a new instance of a probability with a random value between [0.0..1.0). Notice that the random value can never be 1.0.
    • Probability

      public Probability(double value)
      This constructor creates a new instance of a probability with the specified value.
      Parameters:
      value - The value of the new probability [0.0..1.0].
    • Probability

      public Probability(String string)
      This constructor creates a new instance of a probability with the specified value.
      Parameters:
      string - The string value of the new probability [0.0..1.0].
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(Probability probability)
      Specified by:
      compareTo in interface Comparable<Probability>
      Overrides:
      compareTo in class Primitive<Probability>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Primitive<Probability>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Primitive<Probability>
    • toBoolean

      public boolean toBoolean()
      This method converts this probability into a boolean value. If the value is greater than 0.5 then the result is true, and false otherwise.
      Returns:
      The boolean value of this probability.
    • toDouble

      public double toDouble()
      This method converts this probability into a double value.
      Returns:
      The double value of this probability.
    • coinToss

      public static boolean coinToss(Probability probability)
      This function returns the result of a coin toss that is weighted with the specified probability. A probability of zero will always return false and a probability of one will always return true.
      Parameters:
      probability - The probability of the weighted coin.
      Returns:
      The result of the coin toss.
    • not

      public static Probability not(Probability probability)
      This function returns the logical inverse of the specified probability. The value of the logical inverse of a probability is 1.0 - P.
      Parameters:
      probability - The probability whose inverse is being determined.
      Returns:
      The logical inverse of the probability.
    • and

      public static Probability and(Probability probability1, Probability probability2)
      This function returns the logical conjunction of the specified probabilities. The value of the logical conjunction of two probabilities is P * Q.
      Parameters:
      probability1 - The first probability.
      probability2 - The second probability.
      Returns:
      The logical conjunction of the two probabilities.
    • sans

      public static Probability sans(Probability probability1, Probability probability2)
      This function returns the material nonimplication of the specified probabilities. The value of the material nonimplication of two probabilities is P and not(Q).
      Parameters:
      probability1 - The first probability.
      probability2 - The second probability.
      Returns:
      The material nonimplication of the two probabilities.
    • or

      public static Probability or(Probability probability1, Probability probability2)
      This function returns the logical disjunction of the specified probabilities. The value of the logical disjunction of two probabilities is P + Q - and(P, Q).
      Parameters:
      probability1 - The first probability.
      probability2 - The second probability.
      Returns:
      The logical disjunction of the two probabilities.
    • xor

      public static Probability xor(Probability probability1, Probability probability2)
      This function returns the logical exclusive disjunction of the specified probabilities. The value of the logical exclusive disjunction of two probabilities is sans(P, Q) + sans(Q, P).
      Parameters:
      probability1 - The first probability.
      probability2 - The second probability.
      Returns:
      The logical exclusive disjunction of the two probabilities.