View Javadoc
1   package org.djutils.math.functions;
2   
3   /**
4    * Knowledge about knots (discontinuities) of a MathFunction in some interval.
5    * <p>
6    * Copyright (c) 2024-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
7    * for project information <a href="https://djutils.org" target="_blank"> https://djutils.org</a>. The DJUTILS project is
8    * distributed under a three-clause BSD-style license, which can be found at
9    * <a href="https://djutils.org/docs/license.html" target="_blank"> https://djutils.org/docs/license.html</a>.
10   * </p>
11   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
12   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
13   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
14   */
15  public enum KnotReport
16  {
17      /** It is certain that there are no knots in the interval. */
18      NONE,
19      /** There are a limited number of knots in the interval. */
20      KNOWN_FINITE,
21      /** There are infinitely many knots in the interval. */
22      KNOWN_INFINITE,
23      /** The presence, or number of knots in the interval is not known. */
24      UNKNOWN;
25  
26      /**
27       * Report if the number of knots is finite.
28       * @return <code>true</code> for <code>NONE</code>, or <code>KNOWN_FINITE</code>; <code>false</code> for
29       *         <code>KNOWN_INFINITE</code>, or <code>UNKNOWN</code>
30       */
31      public boolean isFinite()
32      {
33          switch (this)
34          {
35              case KNOWN_FINITE:
36                  return true;
37              case KNOWN_INFINITE:
38                  return false;
39              case NONE:
40                  return true;
41              case UNKNOWN:
42                  return false;
43              default:
44                  throw new IllegalStateException("Cannot happen");
45          }
46      }
47      
48      /**
49       * Combine two <code>KnotReport</code>s and return the combined knowledge.
50       * @param other the other <code>KnotReport</code>
51       * @return the combined <code>KnotReport</code> knowledge
52       */
53      public KnotReport combineWith(final KnotReport other)
54      {
55          if (this == UNKNOWN || other == UNKNOWN)
56          {
57              return UNKNOWN;
58          }
59          if (this == KNOWN_INFINITE || other == KNOWN_INFINITE)
60          {
61              return KNOWN_INFINITE;
62          }
63          if (this == KNOWN_FINITE || other == KNOWN_FINITE)
64          {
65              return KNOWN_FINITE; 
66          }
67          return NONE;
68      }
69  }