001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.commons.math4.legacy.ode.sampling;
019
020/**
021 * This class is a step handler that does nothing.
022
023 * <p>This class is provided as a convenience for users who are only
024 * interested in the final state of an integration and not in the
025 * intermediate steps. Its handleStep method does nothing.</p>
026 *
027 * <p>Since this class has no internal state, it is implemented using
028 * the Singleton design pattern. This means that only one instance is
029 * ever created, which can be retrieved using the getInstance
030 * method. This explains why there is no public constructor.</p>
031 *
032 * @see StepHandler
033 * @since 1.2
034 */
035
036public final class DummyStepHandler implements StepHandler {
037
038    /** Private constructor.
039     * The constructor is private to prevent users from creating
040     * instances (Singleton design-pattern).
041     */
042    private DummyStepHandler() {
043    }
044
045    /** Get the only instance.
046     * @return the only instance
047     */
048    public static DummyStepHandler getInstance() {
049        return LazyHolder.INSTANCE;
050    }
051
052    /** {@inheritDoc} */
053    @Override
054    public void init(double t0, double[] y0, double t) {
055    }
056
057    /**
058     * Handle the last accepted step.
059     * This method does nothing in this class.
060     * @param interpolator interpolator for the last accepted step. For
061     * efficiency purposes, the various integrators reuse the same
062     * object on each call, so if the instance wants to keep it across
063     * all calls (for example to provide at the end of the integration a
064     * continuous model valid throughout the integration range), it
065     * should build a local copy using the clone method and store this
066     * copy.
067     * @param isLast true if the step is the last one
068     */
069    @Override
070    public void handleStep(final StepInterpolator interpolator, final boolean isLast) {
071    }
072
073    // CHECKSTYLE: stop HideUtilityClassConstructor
074    /** Holder for the instance.
075     * <p>We use here the Initialization On Demand Holder Idiom.</p>
076     */
077    private static class LazyHolder {
078        /** Cached field instance. */
079        private static final DummyStepHandler INSTANCE = new DummyStepHandler();
080    }
081    // CHECKSTYLE: resume HideUtilityClassConstructor
082
083    /** Handle deserialization of the singleton.
084     * @return the singleton instance
085     */
086    private Object readResolve() {
087        // return the singleton instance
088        return LazyHolder.INSTANCE;
089    }
090}