Package com.scurrilous.circe.impl
Class AbstractHashProvider<P extends HashParameters>
- java.lang.Object
-
- com.scurrilous.circe.impl.AbstractHashProvider<P>
-
- Type Parameters:
P
- base supported hash parameters type
- All Implemented Interfaces:
HashProvider
- Direct Known Subclasses:
Crc32cSse42Provider
,StandardCrcProvider
public abstract class AbstractHashProvider<P extends HashParameters> extends java.lang.Object implements HashProvider
Base implementation for hash function providers.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractHashProvider(java.lang.Class<P> parametersClass)
Constructs a newAbstractHashProvider
with the given base parameters class.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected StatelessHash
createCacheable(P params, java.util.EnumSet<HashSupport> required)
Called bygetCacheable(P, java.util.EnumSet<com.scurrilous.circe.HashSupport>)
to create new cacheable stateless hash functions.StatefulHash
createStateful(HashParameters params)
Creates a stateful hash function using the given parameters.protected abstract Hash
get(P params, java.util.EnumSet<HashSupport> required)
Requests a hash function using the given parameters and support flags.protected Hash
getCacheable(P params, java.util.EnumSet<HashSupport> required)
Called by implementations that support caching of stateless hash functions when a cached instance is desired.IncrementalIntHash
getIncrementalInt(HashParameters params)
Requests an incremental, stateless, int-width hash function with the given parameters.IncrementalLongHash
getIncrementalLong(HashParameters params)
Requests an incremental, stateless, long-width hash function with the given parameters.StatelessIntHash
getStatelessInt(HashParameters params)
Requests a stateless, int-width hash function with the given parameters.StatelessLongHash
getStatelessLong(HashParameters params)
Requests a stateless, long-width hash function with the given parameters.java.util.EnumSet<HashSupport>
querySupport(HashParameters params)
Returns information about the available implementations corresponding to the given hash algorithm parameters.protected abstract java.util.EnumSet<HashSupport>
querySupportTyped(P params)
Implemented by subclasses to provide information about the available implementations corresponding to the given hash algorithm parameters.
-
-
-
Constructor Detail
-
AbstractHashProvider
protected AbstractHashProvider(java.lang.Class<P> parametersClass)
Constructs a newAbstractHashProvider
with the given base parameters class.- Parameters:
parametersClass
- the base hash parameters class supported
-
-
Method Detail
-
querySupport
public final java.util.EnumSet<HashSupport> querySupport(HashParameters params)
Description copied from interface:HashProvider
Returns information about the available implementations corresponding to the given hash algorithm parameters.- Specified by:
querySupport
in interfaceHashProvider
- Parameters:
params
- the hash algorithm parameters- Returns:
- a set of flags indicating the level of support
-
querySupportTyped
protected abstract java.util.EnumSet<HashSupport> querySupportTyped(P params)
Implemented by subclasses to provide information about the available implementations corresponding to the given hash algorithm parameters. Called byquerySupport(com.scurrilous.circe.HashParameters)
if the hash parameters match the base type supported by this provider.- Parameters:
params
- the hash algorithm parameters- Returns:
- a set of flags indicating the level of support
-
get
protected abstract Hash get(P params, java.util.EnumSet<HashSupport> required)
Requests a hash function using the given parameters and support flags. This method is only responsible for checking support flags returned byquerySupportTyped(P)
.To support caching of stateless hash functions, call
getCacheable(P, java.util.EnumSet<com.scurrilous.circe.HashSupport>)
from this method and implementcreateCacheable(P, java.util.EnumSet<com.scurrilous.circe.HashSupport>)
.- Parameters:
params
- the hash algorithm parametersrequired
- the required hash support flags- Returns:
- a hash function
- Throws:
java.lang.UnsupportedOperationException
- if this provider cannot support the given parameters
-
getCacheable
protected final Hash getCacheable(P params, java.util.EnumSet<HashSupport> required)
Called by implementations that support caching of stateless hash functions when a cached instance is desired. If a cached instance is not available, this method callscreateCacheable(P, java.util.EnumSet<com.scurrilous.circe.HashSupport>)
to create one, which is then cached (if caching is available).- Parameters:
params
- the hash algorithm parametersrequired
- the required hash support flags- Returns:
- a hash function
- Throws:
java.lang.UnsupportedOperationException
- if this provider cannot support the given parameters
-
createCacheable
protected StatelessHash createCacheable(P params, java.util.EnumSet<HashSupport> required)
Called bygetCacheable(P, java.util.EnumSet<com.scurrilous.circe.HashSupport>)
to create new cacheable stateless hash functions. The default implementation simply throwsUnsupportedOperationException
.- Parameters:
params
- the hash algorithm parametersrequired
- the required hash support flags- Returns:
- a stateless hash function
- Throws:
java.lang.UnsupportedOperationException
- if this provider cannot support the given parameters
-
createStateful
public StatefulHash createStateful(HashParameters params)
Description copied from interface:HashProvider
Creates a stateful hash function using the given parameters.- Specified by:
createStateful
in interfaceHashProvider
- Parameters:
params
- the hash algorithm parameters- Returns:
- a stateful hash function
-
getStatelessInt
public StatelessIntHash getStatelessInt(HashParameters params)
Description copied from interface:HashProvider
Requests a stateless, int-width hash function with the given parameters. Because not all stateless hash functions are incremental, this method may be able to return implementations not supported by or more optimized thanHashProvider.getIncrementalInt(com.scurrilous.circe.HashParameters)
.- Specified by:
getStatelessInt
in interfaceHashProvider
- Parameters:
params
- the hash algorithm parameters- Returns:
- a stateless int-width hash function
-
getStatelessLong
public StatelessLongHash getStatelessLong(HashParameters params)
Description copied from interface:HashProvider
Requests a stateless, long-width hash function with the given parameters. Because not all stateless hash functions are incremental, this method may be able to return implementations not supported by or more optimized thanHashProvider.getIncrementalLong(com.scurrilous.circe.HashParameters)
.Note that this method may return a less efficient hash function than
HashProvider.getStatelessInt(com.scurrilous.circe.HashParameters)
for hashes of 32 bits or less.- Specified by:
getStatelessLong
in interfaceHashProvider
- Parameters:
params
- the hash algorithm parameters- Returns:
- a stateless long-width hash function
-
getIncrementalInt
public IncrementalIntHash getIncrementalInt(HashParameters params)
Description copied from interface:HashProvider
Requests an incremental, stateless, int-width hash function with the given parameters. Note that although an algorithm may be available in incremental form, some potentially more optimized implementations may not support that form, and therefore cannot be provided be this method.- Specified by:
getIncrementalInt
in interfaceHashProvider
- Parameters:
params
- the hash algorithm parameters- Returns:
- a stateful int-width hash function
-
getIncrementalLong
public IncrementalLongHash getIncrementalLong(HashParameters params)
Description copied from interface:HashProvider
Requests an incremental, stateless, long-width hash function with the given parameters. Note that although an algorithm may be available in incremental form, some potentially more optimized implementations may not support that form, and therefore cannot be provided be this method.Also note that this method may return a less efficient hash function than
HashProvider.getIncrementalInt(com.scurrilous.circe.HashParameters)
for hashes of 32 bits or less.- Specified by:
getIncrementalLong
in interfaceHashProvider
- Parameters:
params
- the hash algorithm parameters- Returns:
- a stateful long-width hash function
-
-