Class SeedGeneratorPreferenceList
- java.lang.Object
-
- java.util.concurrent.CopyOnWriteArrayList<SeedGenerator>
-
- io.github.pr0methean.betterrandom.seed.SeedGeneratorPreferenceList
-
- All Implemented Interfaces:
SeedGenerator,Serializable,Cloneable,Iterable<SeedGenerator>,Collection<SeedGenerator>,List<SeedGenerator>,RandomAccess
public class SeedGeneratorPreferenceList extends CopyOnWriteArrayList<SeedGenerator> implements SeedGenerator
ASeedGeneratorimplementation that iterates over multiple delegates until one succeeds.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface io.github.pr0methean.betterrandom.seed.SeedGenerator
EMPTY_SEED
-
-
Constructor Summary
Constructors Constructor Description SeedGeneratorPreferenceList(boolean isAlwaysWorthTrying, SeedGenerator... contents)Creates an instance.SeedGeneratorPreferenceList(Collection<? extends SeedGenerator> contents, boolean isAlwaysWorthTrying)Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidgenerateSeed(byte[] output)Generates a seed value for a random number generator in an existing array.byte[]generateSeed(int length)Generates and returns a seed value for a random number generator as a new array.booleanisWorthTrying()Returns true if we cannot determine quickly (i.e.-
Methods inherited from class java.util.concurrent.CopyOnWriteArrayList
add, add, addAll, addAll, addAllAbsent, addIfAbsent, clear, clone, contains, containsAll, equals, forEach, get, hashCode, indexOf, indexOf, isEmpty, iterator, lastIndexOf, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
-
-
-
-
Constructor Detail
-
SeedGeneratorPreferenceList
public SeedGeneratorPreferenceList(Collection<? extends SeedGenerator> contents, boolean isAlwaysWorthTrying)
Creates an instance.- Parameters:
contents- the initial list of delegates, in the order they will be tried until one succeedsisAlwaysWorthTrying- true ifisWorthTrying()should always return true rather than delegating
-
SeedGeneratorPreferenceList
public SeedGeneratorPreferenceList(boolean isAlwaysWorthTrying, SeedGenerator... contents)Creates an instance.- Parameters:
contents- the initial delegates, in the order they will be tried until one succeedsisAlwaysWorthTrying- true ifisWorthTrying()should always return true rather than delegating
-
-
Method Detail
-
generateSeed
public void generateSeed(byte[] output) throws SeedExceptionDescription copied from interface:SeedGeneratorGenerates a seed value for a random number generator in an existing array.- Specified by:
generateSeedin interfaceSeedGenerator- Parameters:
output- The array that is to be populated with the seed.- Throws:
SeedException- If a seed cannot be generated for any reason.
-
generateSeed
public byte[] generateSeed(int length) throws SeedExceptionDescription copied from interface:SeedGeneratorGenerates and returns a seed value for a random number generator as a new array.- Specified by:
generateSeedin interfaceSeedGenerator- Parameters:
length- The length of the seed to generate (in bytes).- Returns:
- A byte array containing the seed data.
- Throws:
SeedException- If a seed cannot be generated for any reason.
-
isWorthTrying
public boolean isWorthTrying()
Description copied from interface:SeedGeneratorReturns true if we cannot determine quickly (i.e. without I/O calls) that this SeedGenerator would throw aSeedExceptionifSeedGenerator.generateSeed(int)orSeedGenerator.generateSeed(byte[])were being called right now.- Specified by:
isWorthTryingin interfaceSeedGenerator- Returns:
- true if this SeedGenerator will get as far as an I/O call or other slow operation in attempting to generate a seed immediately.
-
-