Enum NativeSeedType
- java.lang.Object
-
- java.lang.Enum<NativeSeedType>
-
- org.apache.commons.rng.simple.internal.NativeSeedType
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<NativeSeedType>
public enum NativeSeedType extends java.lang.Enum<NativeSeedType>
The native seed type. Contains values for all native seed types and methods to convert supported seed types to the native seed type.Valid native seed types are:
IntegerLongint[]long[]
Valid types for seed conversion are:
Integer(orint)Long(orlong)int[]long[]byte[]
- Since:
- 1.3
-
-
Enum Constant Summary
Enum Constants Enum Constant Description INTThe seed type isInteger.INT_ARRAYThe seed type isint[].LONGThe seed type isLong.LONG_ARRAYThe seed type islong[].
-
Field Summary
Fields Modifier and Type Field Description private intbytesDefine the number of bytes required to represent the native seed.private static intRANDOM_SEED_ARRAY_SIZEMaximum length of the seed array (for creating array seeds).private java.lang.Class<?>typeDefine the class type of the native seed.private static java.lang.StringUNRECOGNISED_SEEDError message for unrecognized seed types.
-
Constructor Summary
Constructors Modifier Constructor Description privateNativeSeedType(java.lang.Class<?> type, int bytes)Instantiates a new native seed type.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract java.lang.Objectconvert(byte[] seed, int size)Convert the inputbyte[]seed to the native seed type.protected abstract java.lang.Objectconvert(int[] seed, int size)Convert the inputint[]seed to the native seed type.protected abstract java.lang.Objectconvert(long[] seed, int size)Convert the inputlong[]seed to the native seed type.protected abstract java.lang.Objectconvert(java.lang.Integer seed, int size)Convert the inputIntegerseed to the native seed type.protected abstract java.lang.Objectconvert(java.lang.Long seed, int size)Convert the inputLongseed to the native seed type.java.lang.ObjectconvertSeed(java.lang.Object seed, int size)Converts the input seed from any of the supported seed types to the native seed type.static byte[]convertSeedToBytes(java.lang.Object seed)Converts the input seed from any of the supported seed types to bytes.java.lang.ObjectcreateSeed(int size)Creates the seed.abstract java.lang.ObjectcreateSeed(int size, int from, int to)Creates the seed.intgetBytes()Gets the number of bytes required to represent the native seed type.java.lang.Class<?>getType()Gets the class type of the native seed.private static java.lang.StringunrecognizedSeedMessage(java.lang.Object seed)Create an unrecognized seed message.static NativeSeedTypevalueOf(java.lang.String name)Returns the enum constant of this type with the specified name.static NativeSeedType[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
INT
public static final NativeSeedType INT
The seed type isInteger.
-
LONG
public static final NativeSeedType LONG
The seed type isLong.
-
INT_ARRAY
public static final NativeSeedType INT_ARRAY
The seed type isint[].
-
LONG_ARRAY
public static final NativeSeedType LONG_ARRAY
The seed type islong[].
-
-
Field Detail
-
UNRECOGNISED_SEED
private static final java.lang.String UNRECOGNISED_SEED
Error message for unrecognized seed types.- See Also:
- Constant Field Values
-
RANDOM_SEED_ARRAY_SIZE
private static final int RANDOM_SEED_ARRAY_SIZE
Maximum length of the seed array (for creating array seeds).- See Also:
- Constant Field Values
-
type
private final java.lang.Class<?> type
Define the class type of the native seed.
-
bytes
private final int bytes
Define the number of bytes required to represent the native seed. If the type is an array then this represents the size of a single value of the type.
-
-
Method Detail
-
values
public static NativeSeedType[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (NativeSeedType c : NativeSeedType.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static NativeSeedType valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException- if this enum type has no constant with the specified namejava.lang.NullPointerException- if the argument is null
-
getType
public java.lang.Class<?> getType()
Gets the class type of the native seed.- Returns:
- the type
-
getBytes
public int getBytes()
Gets the number of bytes required to represent the native seed type. If the type is an array then this represents the size of a single value of the type.- Returns:
- the number of bytes
-
createSeed
public java.lang.Object createSeed(int size)
Creates the seed. The output seed type is determined by the native seed type. If the output is an array the required size of the array can be specified.- Parameters:
size- The size of the seed (array types only).- Returns:
- the seed
-
createSeed
public abstract java.lang.Object createSeed(int size, int from, int to)Creates the seed. The output seed type is determined by the native seed type. If the output is an array the required size of the array can be specified and a sub-range that must not be all-zero.- Parameters:
size- The size of the seed (array types only).from- The start of the not all-zero sub-range (inclusive; array types only).to- The end of the not all-zero sub-range (exclusive; array types only).- Returns:
- the seed
- Throws:
java.lang.IndexOutOfBoundsException- if the sub-range is out of bounds- Since:
- 1.5
-
convertSeed
public java.lang.Object convertSeed(java.lang.Object seed, int size)Converts the input seed from any of the supported seed types to the native seed type. If the output is an array the required size of the array can be specified.- Parameters:
seed- Input seed.size- The size of the output seed (array types only).- Returns:
- the native seed.
- Throws:
java.lang.UnsupportedOperationException- if theseedtype is invalid.
-
convert
protected abstract java.lang.Object convert(java.lang.Integer seed, int size)Convert the inputIntegerseed to the native seed type.- Parameters:
seed- Input seed.size- The size of the output seed (array types only).- Returns:
- the native seed.
-
convert
protected abstract java.lang.Object convert(java.lang.Long seed, int size)Convert the inputLongseed to the native seed type.- Parameters:
seed- Input seed.size- The size of the output seed (array types only).- Returns:
- the native seed.
-
convert
protected abstract java.lang.Object convert(int[] seed, int size)Convert the inputint[]seed to the native seed type.- Parameters:
seed- Input seed.size- The size of the output seed (array types only).- Returns:
- the native seed.
-
convert
protected abstract java.lang.Object convert(long[] seed, int size)Convert the inputlong[]seed to the native seed type.- Parameters:
seed- Input seed.size- The size of the output seed (array types only).- Returns:
- the native seed.
-
convert
protected abstract java.lang.Object convert(byte[] seed, int size)Convert the inputbyte[]seed to the native seed type.- Parameters:
seed- Input seed.size- The size of the output seed (array types only).- Returns:
- the native seed.
-
convertSeedToBytes
public static byte[] convertSeedToBytes(java.lang.Object seed)
Converts the input seed from any of the supported seed types to bytes.- Parameters:
seed- Input seed.- Returns:
- the seed bytes.
- Throws:
java.lang.UnsupportedOperationException- if theseedtype is invalid.
-
unrecognizedSeedMessage
private static java.lang.String unrecognizedSeedMessage(java.lang.Object seed)
Create an unrecognized seed message. This will add the class type of the seed.- Parameters:
seed- the seed- Returns:
- the message
-
-