Module javafx.base

Interface NumberExpression

All Superinterfaces:
Observable, ObservableNumberValue, ObservableValue<Number>
All Known Subinterfaces:
NumberBinding
All Known Implementing Classes:
DoubleBinding, DoubleExpression, DoubleProperty, DoublePropertyBase, FloatBinding, FloatExpression, FloatProperty, FloatPropertyBase, IntegerBinding, IntegerExpression, IntegerProperty, IntegerPropertyBase, JavaBeanDoubleProperty, JavaBeanFloatProperty, JavaBeanIntegerProperty, JavaBeanLongProperty, LongBinding, LongExpression, LongProperty, LongPropertyBase, NumberExpressionBase, ReadOnlyDoubleProperty, ReadOnlyDoublePropertyBase, ReadOnlyDoubleWrapper, ReadOnlyFloatProperty, ReadOnlyFloatPropertyBase, ReadOnlyFloatWrapper, ReadOnlyIntegerProperty, ReadOnlyIntegerPropertyBase, ReadOnlyIntegerWrapper, ReadOnlyJavaBeanDoubleProperty, ReadOnlyJavaBeanFloatProperty, ReadOnlyJavaBeanIntegerProperty, ReadOnlyJavaBeanLongProperty, ReadOnlyLongProperty, ReadOnlyLongPropertyBase, ReadOnlyLongWrapper, SimpleDoubleProperty, SimpleFloatProperty, SimpleIntegerProperty, SimpleLongProperty, SimpleStyleableDoubleProperty, SimpleStyleableFloatProperty, SimpleStyleableIntegerProperty, SimpleStyleableLongProperty, StyleableDoubleProperty, StyleableFloatProperty, StyleableIntegerProperty, StyleableLongProperty

public interface NumberExpression extends ObservableNumberValue
NumberExpression is an ObservableNumberValue plus additional convenience methods to generate bindings in a fluent style.

This API allows to mix types when defining arithmetic operations. The type of the result is defined by the same rules as in the Java Language.

  1. If one of the operands is a double, the result is a double.
  2. If not and one of the operands is a float, the result is a float.
  3. If not and one of the operands is a long, the result is a long.
  4. The result is an integer otherwise.

To be able to deal with an unspecified return type, two interfaces NumberExpression and its counterpart NumberBinding were introduced. That means if the return type is specified as NumberBinding, the method will either return a DoubleBinding, FloatBinding, LongBinding or IntegerBinding, depending on the types of the operands.

The API tries to do its best in determining the correct return type, e.g. combining a ObservableNumberValue with a primitive double will always result in a DoubleBinding. In cases where the return type is not known by the API, it is the responsibility of the developer to call the correct getter (ObservableNumberValue.intValue() etc.). If the internal representation does not match the type of the getter, a standard cast is done.

Since:
JavaFX 2.0
  • Method Details

    • negate

      NumberBinding negate()
      Creates a new NumberBinding that calculates the negation of NumberExpression.
      Returns:
      the new NumberBinding
    • add

      Creates a new NumberBinding that calculates the sum of this NumberExpression and another ObservableNumberValue.
      Parameters:
      other - the second ObservableNumberValue
      Returns:
      the new NumberBinding
      Throws:
      NullPointerException - if the other ObservableNumberValue is null
    • add

      NumberBinding add(double other)
      Creates a new NumberBinding that calculates the sum of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • add

      NumberBinding add(float other)
      Creates a new NumberBinding that calculates the sum of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • add

      NumberBinding add(long other)
      Creates a new NumberBinding that calculates the sum of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • add

      NumberBinding add(int other)
      Creates a new NumberBinding that calculates the sum of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • subtract

      Creates a new NumberBinding that calculates the difference of this NumberExpression and another ObservableNumberValue.
      Parameters:
      other - the second ObservableNumberValue
      Returns:
      the new NumberBinding
      Throws:
      NullPointerException - if the other ObservableNumberValue is null
    • subtract

      NumberBinding subtract(double other)
      Creates a new NumberBinding that calculates the difference of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • subtract

      NumberBinding subtract(float other)
      Creates a new NumberBinding that calculates the difference of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • subtract

      NumberBinding subtract(long other)
      Creates a new NumberBinding that calculates the difference of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • subtract

      NumberBinding subtract(int other)
      Creates a new NumberBinding that calculates the difference of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • multiply

      Creates a new NumberBinding that calculates the product of this NumberExpression and another ObservableNumberValue.
      Parameters:
      other - the second ObservableNumberValue
      Returns:
      the new NumberBinding
      Throws:
      NullPointerException - if the other ObservableNumberValue is null
    • multiply

      NumberBinding multiply(double other)
      Creates a new NumberBinding that calculates the product of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • multiply

      NumberBinding multiply(float other)
      Creates a new NumberBinding that calculates the product of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • multiply

      NumberBinding multiply(long other)
      Creates a new NumberBinding that calculates the product of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • multiply

      NumberBinding multiply(int other)
      Creates a new NumberBinding that calculates the product of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • divide

      Creates a new NumberBinding that calculates the division of this NumberExpression and another ObservableNumberValue.
      Parameters:
      other - the second ObservableNumberValue
      Returns:
      the new NumberBinding
      Throws:
      NullPointerException - if the other ObservableNumberValue is null
    • divide

      NumberBinding divide(double other)
      Creates a new NumberBinding that calculates the division of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • divide

      NumberBinding divide(float other)
      Creates a new NumberBinding that calculates the division of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • divide

      NumberBinding divide(long other)
      Creates a new NumberBinding that calculates the division of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • divide

      NumberBinding divide(int other)
      Creates a new NumberBinding that calculates the division of this NumberExpression and a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new NumberBinding
    • isEqualTo

      Creates a new BooleanBinding that holds true if this and another ObservableNumberValue are equal.

      When comparing floating-point numbers it is recommended to use the isEqualTo() method that allows a small tolerance.

      Parameters:
      other - the second ObservableNumberValue
      Returns:
      the new BooleanBinding
      Throws:
      NullPointerException - if the other ObservableNumberValue is null
    • isEqualTo

      BooleanBinding isEqualTo(ObservableNumberValue other, double epsilon)
      Creates a new BooleanBinding that holds true if this and another ObservableNumberValue are equal (with a tolerance).

      Two operands a and b are considered equal if Math.abs(a-b) <= epsilon.

      Allowing a small tolerance is recommended when comparing floating-point numbers because of rounding-errors.

      Parameters:
      other - the second ObservableNumberValue
      epsilon - the tolerance
      Returns:
      the new BooleanBinding
      Throws:
      NullPointerException - if the other ObservableNumberValue is null
    • isEqualTo

      BooleanBinding isEqualTo(double other, double epsilon)
      Creates a new BooleanBinding that holds true if this NumberExpression is equal to a constant value (with a tolerance).

      Two operands a and b are considered equal if Math.abs(a-b) <= epsilon.

      Allowing a small tolerance is recommended when comparing floating-point numbers because of rounding-errors.

      Parameters:
      other - the constant value
      epsilon - the permitted tolerance
      Returns:
      the new BooleanBinding
    • isEqualTo

      BooleanBinding isEqualTo(float other, double epsilon)
      Creates a new BooleanBinding that holds true if this NumberExpression is equal to a constant value (with a tolerance).

      Two operands a and b are considered equal if Math.abs(a-b) <= epsilon.

      Allowing a small tolerance is recommended when comparing floating-point numbers because of rounding-errors.

      Parameters:
      other - the constant value
      epsilon - the permitted tolerance
      Returns:
      the new BooleanBinding
    • isEqualTo

      BooleanBinding isEqualTo(long other)
      Creates a new BooleanBinding that holds true if this NumberExpression is equal to a constant value.

      When comparing floating-point numbers it is recommended to use the isEqualTo() method that allows a small tolerance.

      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • isEqualTo

      BooleanBinding isEqualTo(long other, double epsilon)
      Creates a new BooleanBinding that holds true if this NumberExpression is equal to a constant value (with a tolerance).

      Two operands a and b are considered equal if Math.abs(a-b) <= epsilon.

      Allowing a small tolerance is recommended when comparing floating-point numbers because of rounding-errors.

      Parameters:
      other - the constant value
      epsilon - the permitted tolerance
      Returns:
      the new BooleanBinding
    • isEqualTo

      BooleanBinding isEqualTo(int other)
      Creates a new BooleanBinding that holds true if this NumberExpression is equal to a constant value.

      When comparing floating-point numbers it is recommended to use the isEqualTo() method that allows a small tolerance.

      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • isEqualTo

      BooleanBinding isEqualTo(int other, double epsilon)
      Creates a new BooleanBinding that holds true if this NumberExpression is equal to a constant value (with a tolerance).

      Two operands a and b are considered equal if Math.abs(a-b) <= epsilon.

      Allowing a small tolerance is recommended when comparing floating-point numbers.

      Parameters:
      other - the constant value
      epsilon - the permitted tolerance
      Returns:
      the new BooleanBinding
    • isNotEqualTo

      Creates a new BooleanBinding that holds true if this and another ObservableNumberValue are not equal.

      When comparing floating-point numbers it is recommended to use the isNotEqualTo() method that allows a small tolerance.

      Parameters:
      other - the second ObservableNumberValue
      Returns:
      the new BooleanBinding
      Throws:
      NullPointerException - if the other ObservableNumberValue is null
    • isNotEqualTo

      BooleanBinding isNotEqualTo(ObservableNumberValue other, double epsilon)
      Creates a new BooleanBinding that holds true if this and another ObservableNumberValue are not equal (with a tolerance).

      Two operands a and b are considered not equal if Math.abs(a-b) > epsilon.

      Allowing a small tolerance is recommended when comparing floating-point numbers because of rounding-errors.

      Parameters:
      other - the second ObservableNumberValue
      epsilon - the permitted tolerance
      Returns:
      the new BooleanBinding
      Throws:
      NullPointerException - if the other ObservableNumberValue is null
    • isNotEqualTo

      BooleanBinding isNotEqualTo(double other, double epsilon)
      Creates a new BooleanBinding that holds true if this NumberExpression is not equal to a constant value (with a tolerance).

      Two operands a and b are considered not equal if Math.abs(a-b) > epsilon.

      Allowing a small tolerance is recommended when comparing floating-point numbers.

      Parameters:
      other - the constant value
      epsilon - the permitted tolerance
      Returns:
      the new BooleanBinding
    • isNotEqualTo

      BooleanBinding isNotEqualTo(float other, double epsilon)
      Creates a new BooleanBinding that holds true if this NumberExpression is not equal to a constant value (with a tolerance).

      Two operands a and b are considered not equal if Math.abs(a-b) > epsilon.

      Allowing a small tolerance is recommended when comparing floating-point numbers.

      Parameters:
      other - the constant value
      epsilon - the permitted tolerance
      Returns:
      the new BooleanBinding
    • isNotEqualTo

      BooleanBinding isNotEqualTo(long other)
      Creates a new BooleanBinding that holds true if this NumberExpression is not equal to a constant value.

      When comparing floating-point numbers it is recommended to use the isNotEqualTo() method that allows a small tolerance.

      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • isNotEqualTo

      BooleanBinding isNotEqualTo(long other, double epsilon)
      Creates a new BooleanBinding that holds true if this NumberExpression is not equal to a constant value (with a tolerance).

      Two operands a and b are considered not equal if Math.abs(a-b) > epsilon.

      Allowing a small tolerance is recommended when comparing floating-point numbers.

      Parameters:
      other - the constant value
      epsilon - the permitted tolerance
      Returns:
      the new BooleanBinding
    • isNotEqualTo

      BooleanBinding isNotEqualTo(int other)
      Creates a new BooleanBinding that holds true if this NumberExpression is not equal to a constant value.

      When comparing floating-point numbers it is recommended to use the isNotEqualTo() method that allows a small tolerance.

      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • isNotEqualTo

      BooleanBinding isNotEqualTo(int other, double epsilon)
      Creates a new BooleanBinding that holds true if this NumberExpression is not equal to a constant value (with a tolerance).

      Two operands a and b are considered not equal if Math.abs(a-b) > epsilon.

      Allowing a small tolerance is recommended when comparing floating-point numbers.

      Parameters:
      other - the constant value
      epsilon - the permitted tolerance
      Returns:
      the new BooleanBinding
    • greaterThan

      Creates a new BooleanBinding that holds true if this NumberExpression is greater than another ObservableNumberValue.
      Parameters:
      other - the second ObservableNumberValue
      Returns:
      the new BooleanBinding
      Throws:
      NullPointerException - if the other ObservableNumberValue is null
    • greaterThan

      BooleanBinding greaterThan(double other)
      Creates a new BooleanBinding that holds true if this NumberExpression is greater than a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • greaterThan

      BooleanBinding greaterThan(float other)
      Creates a new BooleanBinding that holds true if this NumberExpression is greater than a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • greaterThan

      BooleanBinding greaterThan(long other)
      Creates a new BooleanBinding that holds true if this NumberExpression is greater than a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • greaterThan

      BooleanBinding greaterThan(int other)
      Creates a new BooleanBinding that holds true if this NumberExpression is greater than a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • lessThan

      Creates a new BooleanBinding that holds true if this NumberExpression is lesser than another ObservableNumberValue.
      Parameters:
      other - the second ObservableNumberValue
      Returns:
      the new BooleanBinding
      Throws:
      NullPointerException - if the other ObservableNumberValue is null
    • lessThan

      BooleanBinding lessThan(double other)
      Creates a new BooleanBinding that holds true if this NumberExpression is lesser than a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • lessThan

      BooleanBinding lessThan(float other)
      Creates a new BooleanBinding that holds true if this NumberExpression is lesser than a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • lessThan

      BooleanBinding lessThan(long other)
      Creates a new BooleanBinding that holds true if this NumberExpression is lesser than a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • lessThan

      BooleanBinding lessThan(int other)
      Creates a new BooleanBinding that holds true if this NumberExpression is lesser than a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • greaterThanOrEqualTo

      BooleanBinding greaterThanOrEqualTo(ObservableNumberValue other)
      Creates a new BooleanBinding that holds true if this NumberExpression is greater than or equal to another ObservableNumberValue.
      Parameters:
      other - the second ObservableNumberValue
      Returns:
      the new BooleanBinding
      Throws:
      NullPointerException - if the other ObservableNumberValue is null
    • greaterThanOrEqualTo

      BooleanBinding greaterThanOrEqualTo(double other)
      Creates a new BooleanBinding that holds true if this NumberExpression is greater than or equal to a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • greaterThanOrEqualTo

      BooleanBinding greaterThanOrEqualTo(float other)
      Creates a new BooleanBinding that holds true if this NumberExpression is greater than or equal to a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • greaterThanOrEqualTo

      BooleanBinding greaterThanOrEqualTo(long other)
      Creates a new BooleanBinding that holds true if this NumberExpression is greater than or equal to a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • greaterThanOrEqualTo

      BooleanBinding greaterThanOrEqualTo(int other)
      Creates a new BooleanBinding that holds true if this NumberExpression is greater than or equal to a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • lessThanOrEqualTo

      BooleanBinding lessThanOrEqualTo(ObservableNumberValue other)
      Creates a new BooleanBinding that holds true if this NumberExpression is less than or equal to another ObservableNumberValue.
      Parameters:
      other - the second ObservableNumberValue
      Returns:
      the new BooleanBinding
      Throws:
      NullPointerException - if the other ObservableNumberValue is null
    • lessThanOrEqualTo

      BooleanBinding lessThanOrEqualTo(double other)
      Creates a new BooleanBinding that holds true if this NumberExpression is less than or equal to a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • lessThanOrEqualTo

      BooleanBinding lessThanOrEqualTo(float other)
      Creates a new BooleanBinding that holds true if this NumberExpression is less than or equal to a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • lessThanOrEqualTo

      BooleanBinding lessThanOrEqualTo(long other)
      Creates a new BooleanBinding that holds true if this NumberExpression is less than or equal to a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • lessThanOrEqualTo

      BooleanBinding lessThanOrEqualTo(int other)
      Creates a new BooleanBinding that holds true if this NumberExpression is less than or equal to a constant value.
      Parameters:
      other - the constant value
      Returns:
      the new BooleanBinding
    • asString

      StringBinding asString()
      Creates a StringBinding that holds the value of the NumberExpression turned into a String. If the value of this NumberExpression changes, the value of the StringBinding will be updated automatically.

      The conversion is done without any formatting applied.

      Returns:
      the new StringBinding
    • asString

      StringBinding asString(String format)
      Creates a StringBinding that holds the value of the NumberExpression turned into a String. If the value of this NumberExpression changes, the value of the StringBinding will be updated automatically.

      The result is formatted according to the formatting String. See java.util.Formatter for formatting rules.

      Parameters:
      format - the formatting String
      Returns:
      the new StringBinding
    • asString

      StringBinding asString(Locale locale, String format)
      Creates a StringBinding that holds the value of the NumberExpression turned into a String. If the value of this NumberExpression changes, the value of the StringBinding will be updated automatically.

      The result is formatted according to the formatting String and the passed in Locale. See java.util.Formatter for formatting rules. See java.util.Locale for details on Locale.

      Parameters:
      locale - the Locale to be used
      format - the formatting String
      Returns:
      the new StringBinding