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.math3.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 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    public void init(double t0, double[] y0, double t) {
054    }
055
056    /**
057     * Handle the last accepted step.
058     * This method does nothing in this class.
059     * @param interpolator interpolator for the last accepted step. For
060     * efficiency purposes, the various integrators reuse the same
061     * object on each call, so if the instance wants to keep it across
062     * all calls (for example to provide at the end of the integration a
063     * continuous model valid throughout the integration range), it
064     * should build a local copy using the clone method and store this
065     * copy.
066     * @param isLast true if the step is the last one
067     */
068    public void handleStep(final StepInterpolator interpolator, final boolean isLast) {
069    }
070
071    // CHECKSTYLE: stop HideUtilityClassConstructor
072    /** Holder for the instance.
073     * <p>We use here the Initialization On Demand Holder Idiom.</p>
074     */
075    private static class LazyHolder {
076        /** Cached field instance. */
077        private static final DummyStepHandler INSTANCE = new DummyStepHandler();
078    }
079    // CHECKSTYLE: resume HideUtilityClassConstructor
080
081    /** Handle deserialization of the singleton.
082     * @return the singleton instance
083     */
084    private Object readResolve() {
085        // return the singleton instance
086        return LazyHolder.INSTANCE;
087    }
088
089}