AbstractGenericCountingHandler.java

  1. /* Copyright 2022-2025 Romain Serra
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.propagation.events.handlers;

  18. import org.hipparchus.ode.events.Action;

  19. /**
  20.  * Abstract, Orekit-internal class for standard and fielded handlers counting event occurrences.
  21.  * The {@link Action} can be modified according to the count.
  22.  * @author Romain Serra
  23.  * @since 13.0
  24.  */
  25. abstract class AbstractGenericCountingHandler {

  26.     /** Action to return. */
  27.     private Action action;

  28.     /** Number of event occurrences. */
  29.     private int count;

  30.     /** Constructor.
  31.      * @param startingCount value to initialize count
  32.      * @param action Action to initialize attribute
  33.      */
  34.     protected AbstractGenericCountingHandler(final int startingCount, final Action action) {
  35.         this.count = startingCount;
  36.         this.action = action;
  37.     }

  38.     /**
  39.      * Getter for count.
  40.      * @return count
  41.      */
  42.     public int getCount() {
  43.         return count;
  44.     }

  45.     /**
  46.      * Protected getter for the action to return.
  47.      * @return action
  48.      */
  49.     protected Action getAction() {
  50.         return action;
  51.     }

  52.     /**
  53.      * Protected setter for action.
  54.      * @param action new action
  55.      */
  56.     protected void setAction(final Action action) {
  57.         this.action = action;
  58.     }

  59.     /**
  60.      * Reset count.
  61.      */
  62.     public void reset() {
  63.         count = 0;
  64.     }

  65.     /**
  66.      * Increment count.
  67.      */
  68.     protected void increment() {
  69.         count++;
  70.     }
  71. }