-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from HubSpot/non-random-random
Add configurable random number generator
- Loading branch information
Showing
7 changed files
with
193 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/main/java/com/hubspot/jinjava/random/ConstantZeroRandomNumberGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.hubspot.jinjava.random; | ||
|
||
import java.util.Random; | ||
import java.util.stream.DoubleStream; | ||
import java.util.stream.IntStream; | ||
import java.util.stream.LongStream; | ||
|
||
/** | ||
* A random number generator that always returns 0. Useful for testing code when you want the output to be constant. | ||
*/ | ||
public class ConstantZeroRandomNumberGenerator extends Random { | ||
|
||
@Override | ||
protected int next(int bits) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int nextInt() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int nextInt(int bound) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long nextLong() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean nextBoolean() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public float nextFloat() { | ||
return 0f; | ||
} | ||
|
||
@Override | ||
public double nextDouble() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public synchronized double nextGaussian() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void nextBytes(byte[] bytes) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public IntStream ints(long streamSize) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public IntStream ints() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public IntStream ints(int randomNumberOrigin, int randomNumberBound) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public LongStream longs(long streamSize) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public LongStream longs() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public LongStream longs(long streamSize, long randomNumberOrigin, long randomNumberBound) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public LongStream longs(long randomNumberOrigin, long randomNumberBound) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public DoubleStream doubles(long streamSize) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public DoubleStream doubles() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/hubspot/jinjava/random/RandomNumberGeneratorStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.hubspot.jinjava.random; | ||
|
||
public enum RandomNumberGeneratorStrategy { | ||
THREAD_LOCAL, | ||
CONSTANT_ZERO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters