DummyStepHandler.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.apache.commons.math4.legacy.ode.sampling;

  18. /**
  19.  * This class is a step handler that does nothing.

  20.  * <p>This class is provided as a convenience for users who are only
  21.  * interested in the final state of an integration and not in the
  22.  * intermediate steps. Its handleStep method does nothing.</p>
  23.  *
  24.  * <p>Since this class has no internal state, it is implemented using
  25.  * the Singleton design pattern. This means that only one instance is
  26.  * ever created, which can be retrieved using the getInstance
  27.  * method. This explains why there is no public constructor.</p>
  28.  *
  29.  * @see StepHandler
  30.  * @since 1.2
  31.  */

  32. public final class DummyStepHandler implements StepHandler {

  33.     /** Private constructor.
  34.      * The constructor is private to prevent users from creating
  35.      * instances (Singleton design-pattern).
  36.      */
  37.     private DummyStepHandler() {
  38.     }

  39.     /** Get the only instance.
  40.      * @return the only instance
  41.      */
  42.     public static DummyStepHandler getInstance() {
  43.         return LazyHolder.INSTANCE;
  44.     }

  45.     /** {@inheritDoc} */
  46.     @Override
  47.     public void init(double t0, double[] y0, double t) {
  48.     }

  49.     /**
  50.      * Handle the last accepted step.
  51.      * This method does nothing in this class.
  52.      * @param interpolator interpolator for the last accepted step. For
  53.      * efficiency purposes, the various integrators reuse the same
  54.      * object on each call, so if the instance wants to keep it across
  55.      * all calls (for example to provide at the end of the integration a
  56.      * continuous model valid throughout the integration range), it
  57.      * should build a local copy using the clone method and store this
  58.      * copy.
  59.      * @param isLast true if the step is the last one
  60.      */
  61.     @Override
  62.     public void handleStep(final StepInterpolator interpolator, final boolean isLast) {
  63.     }

  64.     // CHECKSTYLE: stop HideUtilityClassConstructor
  65.     /** Holder for the instance.
  66.      * <p>We use here the Initialization On Demand Holder Idiom.</p>
  67.      */
  68.     private static final class LazyHolder {
  69.         /** Cached field instance. */
  70.         private static final DummyStepHandler INSTANCE = new DummyStepHandler();
  71.     }
  72.     // CHECKSTYLE: resume HideUtilityClassConstructor

  73.     /** Handle deserialization of the singleton.
  74.      * @return the singleton instance
  75.      */
  76.     private Object readResolve() {
  77.         // return the singleton instance
  78.         return LazyHolder.INSTANCE;
  79.     }
  80. }