Class DualBound<T extends java.lang.Number>

java.lang.Object
org.opentrafficsim.base.parameters.constraint.SingleBound<T>
org.opentrafficsim.base.parameters.constraint.DualBound<T>
Type Parameters:
T - value type
All Implemented Interfaces:
Constraint<T>

public final class DualBound<T extends java.lang.Number>
extends SingleBound<T>
Continuous constraints with a dual bound. To allow both Double and AbstractDoubleScalar<?, ?> constraints, the generic type is restricted to Number. However, that also allows other subclasses of Number, e.g. Integer. Due to rounding and value limits from the type (e.g. Integer.MAX_VALEU), bounds may not function correctly after a call to Number.doubleValue(). To restrict the usage, the constructor is private and static factory methods for Double and AbstractDoubleScalar<?, ?> are supplied.

Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Version:
$Revision$, $LastChangedDate$, by $Author$, initial version 8 sep. 2017
Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static DualBound<java.lang.Number> UNITINTERVAL
    Standard dual bound on the unit interval [0...1].
  • Method Summary

    Modifier and Type Method Description
    boolean accept​(T value)
    Checks whether the value complies with constraints.
    static DualBound<java.lang.Double> closed​(double lowerBound, double upperBound)
    Creates a dual bound including the bounds; lowerBound <= value <= upperBound.
    static <T extends AbstractDoubleScalar<?,​ ?>>
    DualBound<T>
    closed​(T lowerBound, T upperBound)
    Creates a dual bound including the bounds; lowerBound <= value <= upperBound.
    static DualBound<java.lang.Double> leftClosedRightOpen​(double lowerBound, double upperBound)
    Creates a dual bound including the lower bound and excluding the upper bound; lowerBound <= value < upperBound.
    static <T extends AbstractDoubleScalar<?,​ ?>>
    DualBound<T>
    leftClosedRightOpen​(T lowerBound, T upperBound)
    Creates a dual bound including the lower bound and excluding the upper bound; lowerBound <= value < upperBound.
    static DualBound<java.lang.Double> leftOpenRightClosed​(double lowerBound, double upperBound)
    Creates a dual bound excluding the lower bound and including the upper bound; lowerBound < value <= upperBound.
    static <T extends AbstractDoubleScalar<?,​ ?>>
    DualBound<T>
    leftOpenRightClosed​(T lowerBound, T upperBound)
    Creates a dual bound excluding the lower bound and including the upper bound; lowerBound < value <= upperBound.
    static DualBound<java.lang.Double> open​(double lowerBound, double upperBound)
    Creates a dual bound excluding the bounds; lowerBound < value < upperBound.
    static <T extends AbstractDoubleScalar<?,​ ?>>
    DualBound<T>
    open​(T lowerBound, T upperBound)
    Creates a dual bound excluding the bounds; lowerBound < value < upperBound.
    java.lang.String toString()

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • UNITINTERVAL

      public static final DualBound<java.lang.Number> UNITINTERVAL
      Standard dual bound on the unit interval [0...1]. This can be used for both Double and AbstractDoubleScalar<?, ?> parameters.
  • Method Details

    • closed

      public static DualBound<java.lang.Double> closed​(double lowerBound, double upperBound)
      Creates a dual bound including the bounds; lowerBound <= value <= upperBound. Bounds may be equal.
      Parameters:
      lowerBound - double; lower bound value
      upperBound - double; upper bound value
      Returns:
      closed dual bound
    • closed

      public static <T extends AbstractDoubleScalar<?,​ ?>> DualBound<T> closed​(T lowerBound, T upperBound)
      Creates a dual bound including the bounds; lowerBound <= value <= upperBound.
      Type Parameters:
      T - value type
      Parameters:
      lowerBound - T; lower bound value
      upperBound - T; upper bound value
      Returns:
      closed dual bound
    • open

      public static DualBound<java.lang.Double> open​(double lowerBound, double upperBound)
      Creates a dual bound excluding the bounds; lowerBound < value < upperBound.
      Parameters:
      lowerBound - double; lower bound value
      upperBound - double; upper bound value
      Returns:
      open dual bound
    • open

      public static <T extends AbstractDoubleScalar<?,​ ?>> DualBound<T> open​(T lowerBound, T upperBound)
      Creates a dual bound excluding the bounds; lowerBound < value < upperBound.
      Type Parameters:
      T - value type
      Parameters:
      lowerBound - T; lower bound value
      upperBound - T; upper bound value
      Returns:
      open dual bound
    • leftOpenRightClosed

      public static DualBound<java.lang.Double> leftOpenRightClosed​(double lowerBound, double upperBound)
      Creates a dual bound excluding the lower bound and including the upper bound; lowerBound < value <= upperBound.
      Parameters:
      lowerBound - double; lower bound value
      upperBound - double; upper bound value
      Returns:
      dual bound; excluding the lower bound and including the upper bound
    • leftOpenRightClosed

      public static <T extends AbstractDoubleScalar<?,​ ?>> DualBound<T> leftOpenRightClosed​(T lowerBound, T upperBound)
      Creates a dual bound excluding the lower bound and including the upper bound; lowerBound < value <= upperBound.
      Type Parameters:
      T - value type
      Parameters:
      lowerBound - T; lower bound value
      upperBound - T; upper bound value
      Returns:
      dual bound; excluding the lower bound and including the upper bound
    • leftClosedRightOpen

      public static DualBound<java.lang.Double> leftClosedRightOpen​(double lowerBound, double upperBound)
      Creates a dual bound including the lower bound and excluding the upper bound; lowerBound <= value < upperBound.
      Parameters:
      lowerBound - double; lower bound value
      upperBound - double; upper bound value
      Returns:
      dual bound; including the lower bound and excluding the upper bound
    • leftClosedRightOpen

      public static <T extends AbstractDoubleScalar<?,​ ?>> DualBound<T> leftClosedRightOpen​(T lowerBound, T upperBound)
      Creates a dual bound including the lower bound and excluding the upper bound; lowerBound <= value < upperBound.
      Type Parameters:
      T - value type
      Parameters:
      lowerBound - T; lower bound value
      upperBound - T; upper bound value
      Returns:
      dual bound; including the lower bound and excluding the upper bound
    • accept

      public boolean accept​(T value)
      Checks whether the value complies with constraints.
      Specified by:
      accept in interface Constraint<T extends java.lang.Number>
      Overrides:
      accept in class SingleBound<T extends java.lang.Number>
      Parameters:
      value - T; Value to check.
      Returns:
      Whether the value complies with constraints.
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class SingleBound<T extends java.lang.Number>