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    
018    package org.apache.commons.math.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     * @version $Id: DummyStepHandler.java 1139831 2011-06-26 16:26:48Z luc $
034     * @since 1.2
035     */
036    
037    public class DummyStepHandler implements StepHandler {
038    
039        /** Private constructor.
040         * The constructor is private to prevent users from creating
041         * instances (Singleton design-pattern).
042         */
043        private DummyStepHandler() {
044        }
045    
046        /** Get the only instance.
047         * @return the only instance
048         */
049        public static DummyStepHandler getInstance() {
050            return LazyHolder.INSTANCE;
051        }
052    
053        /** Reset the step handler.
054         * Initialize the internal data as required before the first step is
055         * handled.
056         */
057        public void reset() {
058        }
059    
060        /**
061         * Handle the last accepted step.
062         * This method does nothing in this class.
063         * @param interpolator interpolator for the last accepted step. For
064         * efficiency purposes, the various integrators reuse the same
065         * object on each call, so if the instance wants to keep it across
066         * all calls (for example to provide at the end of the integration a
067         * continuous model valid throughout the integration range), it
068         * should build a local copy using the clone method and store this
069         * copy.
070         * @param isLast true if the step is the last one
071         */
072        public void handleStep(final StepInterpolator interpolator, final boolean isLast) {
073        }
074    
075        // CHECKSTYLE: stop HideUtilityClassConstructor
076        /** Holder for the instance.
077         * <p>We use here the Initialization On Demand Holder Idiom.</p>
078         */
079        private static class LazyHolder {
080            /** Cached field instance. */
081            private static final DummyStepHandler INSTANCE = new DummyStepHandler();
082        }
083        // CHECKSTYLE: resume HideUtilityClassConstructor
084    
085        /** Handle deserialization of the singleton.
086         * @return the singleton instance
087         */
088        private Object readResolve() {
089            // return the singleton instance
090            return LazyHolder.INSTANCE;
091        }
092    
093    }