ForwardingRandomGenerator.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF 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.  *      https://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. /*
  18.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */
  21. package org.hipparchus.random;

  22. /**
  23.  * A random generator which forwards all its method calls to another random generator.
  24.  * <p>
  25.  * Subclasses should override one or more methods to modify the behavior of the backing
  26.  * random generator as desired per the decorator pattern.
  27.  */
  28. abstract class ForwardingRandomGenerator implements RandomGenerator {

  29.     /**
  30.      * Returns the backing delegate instance that methods are forwarded to.
  31.      * <p>
  32.      * Concrete subclasses override this method to supply the instance being decorated.
  33.      *
  34.      * @return the delegate instance
  35.      */
  36.     protected abstract RandomGenerator delegate();

  37.     /** {@inheritDoc} */
  38.     @Override
  39.     public void setSeed(int seed) {
  40.         delegate().setSeed(seed);
  41.     }

  42.     /** {@inheritDoc} */
  43.     @Override
  44.     public void setSeed(int[] seed) {
  45.         delegate().setSeed(seed);
  46.     }

  47.     /** {@inheritDoc} */
  48.     @Override
  49.     public void setSeed(long seed) {
  50.         delegate().setSeed(seed);
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     public void nextBytes(byte[] bytes) {
  55.         delegate().nextBytes(bytes);
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     public void nextBytes(byte[] bytes, int offset, int length) {
  60.         delegate().nextBytes(bytes, offset, length);
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public int nextInt() {
  65.         return delegate().nextInt();
  66.     }

  67.     /** {@inheritDoc} */
  68.     @Override
  69.     public int nextInt(int n) {
  70.         return delegate().nextInt(n);
  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     public long nextLong() {
  75.         return delegate().nextLong();
  76.     }

  77.     /** {@inheritDoc} */
  78.     @Override
  79.     public long nextLong(long n) {
  80.         return delegate().nextLong(n);
  81.     }

  82.     /** {@inheritDoc} */
  83.     @Override
  84.     public boolean nextBoolean() {
  85.         return delegate().nextBoolean();
  86.     }

  87.     /** {@inheritDoc} */
  88.     @Override
  89.     public float nextFloat() {
  90.         return delegate().nextFloat();
  91.     }

  92.     /** {@inheritDoc} */
  93.     @Override
  94.     public double nextDouble() {
  95.         return delegate().nextDouble();
  96.     }

  97.     /** {@inheritDoc} */
  98.     @Override
  99.     public double nextGaussian() {
  100.         return delegate().nextGaussian();
  101.     }
  102. }