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.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 * @version $Id: DummyStepHandler.java 1416643 2012-12-03 19:37:14Z tn $ 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 /** {@inheritDoc} */ 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 public void handleStep(final StepInterpolator interpolator, final boolean isLast) { 070 } 071 072 // CHECKSTYLE: stop HideUtilityClassConstructor 073 /** Holder for the instance. 074 * <p>We use here the Initialization On Demand Holder Idiom.</p> 075 */ 076 private static class LazyHolder { 077 /** Cached field instance. */ 078 private static final DummyStepHandler INSTANCE = new DummyStepHandler(); 079 } 080 // CHECKSTYLE: resume HideUtilityClassConstructor 081 082 /** Handle deserialization of the singleton. 083 * @return the singleton instance 084 */ 085 private Object readResolve() { 086 // return the singleton instance 087 return LazyHolder.INSTANCE; 088 } 089 090 }