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 $Revision: 811827 $ $Date: 2009-09-06 17:32:50 +0200 (dim. 06 sept. 2009) $ 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 /** Determines whether this handler needs dense output. 054 * Since this handler does nothing, it does not require dense output. 055 * @return always false 056 */ 057 public boolean requiresDenseOutput() { 058 return false; 059 } 060 061 /** Reset the step handler. 062 * Initialize the internal data as required before the first step is 063 * handled. 064 */ 065 public void reset() { 066 } 067 068 /** 069 * Handle the last accepted step. 070 * This method does nothing in this class. 071 * @param interpolator interpolator for the last accepted step. For 072 * efficiency purposes, the various integrators reuse the same 073 * object on each call, so if the instance wants to keep it across 074 * all calls (for example to provide at the end of the integration a 075 * continuous model valid throughout the integration range), it 076 * should build a local copy using the clone method and store this 077 * copy. 078 * @param isLast true if the step is the last one 079 */ 080 public void handleStep(final StepInterpolator interpolator, final boolean isLast) { 081 } 082 083 // CHECKSTYLE: stop HideUtilityClassConstructor 084 /** Holder for the instance. 085 * <p>We use here the Initialization On Demand Holder Idiom.</p> 086 */ 087 private static class LazyHolder { 088 /** Cached field instance. */ 089 private static final DummyStepHandler INSTANCE = new DummyStepHandler(); 090 } 091 // CHECKSTYLE: resume HideUtilityClassConstructor 092 093 /** Handle deserialization of the singleton. 094 * @return the singleton instance 095 */ 096 private Object readResolve() { 097 // return the singleton instance 098 return LazyHolder.INSTANCE; 099 } 100 101 }