source: src/main/java/agents/anac/y2019/harddealer/math3/random/SynchronizedRandomGenerator.java

Last change on this file was 200, checked in by Katsuhide Fujita, 5 years ago

Add ANAC 2019 agents

  • Property svn:executable set to *
File size: 3.1 KB
Line 
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 * 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 */
17package agents.anac.y2019.harddealer.math3.random;
18
19/**
20 * Any {@link RandomGenerator} implementation can be thread-safe if it
21 * is used through an instance of this class.
22 * This is achieved by enclosing calls to the methods of the actual
23 * generator inside the overridden {@code synchronized} methods of this
24 * class.
25 *
26 * @since 3.1
27 */
28public class SynchronizedRandomGenerator implements RandomGenerator {
29 /** Object to which all calls will be delegated. */
30 private final RandomGenerator wrapped;
31
32 /**
33 * Creates a synchronized wrapper for the given {@code RandomGenerator}
34 * instance.
35 *
36 * @param rng Generator whose methods will be called through
37 * their corresponding overridden synchronized version.
38 * To ensure thread-safety, the wrapped generator <em>must</em>
39 * not be used directly.
40 */
41 public SynchronizedRandomGenerator(RandomGenerator rng) {
42 wrapped = rng;
43 }
44
45 /**
46 * {@inheritDoc}
47 */
48 public synchronized void setSeed(int seed) {
49 wrapped.setSeed(seed);
50 }
51
52 /**
53 * {@inheritDoc}
54 */
55 public synchronized void setSeed(int[] seed) {
56 wrapped.setSeed(seed);
57 }
58
59 /**
60 * {@inheritDoc}
61 */
62 public synchronized void setSeed(long seed) {
63 wrapped.setSeed(seed);
64 }
65
66 /**
67 * {@inheritDoc}
68 */
69 public synchronized void nextBytes(byte[] bytes) {
70 wrapped.nextBytes(bytes);
71 }
72
73 /**
74 * {@inheritDoc}
75 */
76 public synchronized int nextInt() {
77 return wrapped.nextInt();
78 }
79
80 /**
81 * {@inheritDoc}
82 */
83 public synchronized int nextInt(int n) {
84 return wrapped.nextInt(n);
85 }
86
87 /**
88 * {@inheritDoc}
89 */
90 public synchronized long nextLong() {
91 return wrapped.nextLong();
92 }
93
94 /**
95 * {@inheritDoc}
96 */
97 public synchronized boolean nextBoolean() {
98 return wrapped.nextBoolean();
99 }
100
101 /**
102 * {@inheritDoc}
103 */
104 public synchronized float nextFloat() {
105 return wrapped.nextFloat();
106 }
107
108 /**
109 * {@inheritDoc}
110 */
111 public synchronized double nextDouble() {
112 return wrapped.nextDouble();
113 }
114
115 /**
116 * {@inheritDoc}
117 */
118 public synchronized double nextGaussian() {
119 return wrapped.nextGaussian();
120 }
121}
Note: See TracBrowser for help on using the repository browser.