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 protectedAbstractHashProvider(java.lang.Class<P> parametersClass)Constructs a newAbstractHashProviderwith the given base parameters class.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected StatelessHashcreateCacheable(P params, java.util.EnumSet<HashSupport> required)Called bygetCacheable(P, java.util.EnumSet<com.scurrilous.circe.HashSupport>)to create new cacheable stateless hash functions.StatefulHashcreateStateful(HashParameters params)Creates a stateful hash function using the given parameters.protected abstract Hashget(P params, java.util.EnumSet<HashSupport> required)Requests a hash function using the given parameters and support flags.protected HashgetCacheable(P params, java.util.EnumSet<HashSupport> required)Called by implementations that support caching of stateless hash functions when a cached instance is desired.IncrementalIntHashgetIncrementalInt(HashParameters params)Requests an incremental, stateless, int-width hash function with the given parameters.IncrementalLongHashgetIncrementalLong(HashParameters params)Requests an incremental, stateless, long-width hash function with the given parameters.StatelessIntHashgetStatelessInt(HashParameters params)Requests a stateless, int-width hash function with the given parameters.StatelessLongHashgetStatelessLong(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 newAbstractHashProviderwith 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:HashProviderReturns information about the available implementations corresponding to the given hash algorithm parameters.- Specified by:
querySupportin 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:HashProviderCreates a stateful hash function using the given parameters.- Specified by:
createStatefulin interfaceHashProvider- Parameters:
params- the hash algorithm parameters- Returns:
- a stateful hash function
-
getStatelessInt
public StatelessIntHash getStatelessInt(HashParameters params)
Description copied from interface:HashProviderRequests 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:
getStatelessIntin interfaceHashProvider- Parameters:
params- the hash algorithm parameters- Returns:
- a stateless int-width hash function
-
getStatelessLong
public StatelessLongHash getStatelessLong(HashParameters params)
Description copied from interface:HashProviderRequests 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:
getStatelessLongin interfaceHashProvider- Parameters:
params- the hash algorithm parameters- Returns:
- a stateless long-width hash function
-
getIncrementalInt
public IncrementalIntHash getIncrementalInt(HashParameters params)
Description copied from interface:HashProviderRequests 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:
getIncrementalIntin interfaceHashProvider- Parameters:
params- the hash algorithm parameters- Returns:
- a stateful int-width hash function
-
getIncrementalLong
public IncrementalLongHash getIncrementalLong(HashParameters params)
Description copied from interface:HashProviderRequests 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:
getIncrementalLongin interfaceHashProvider- Parameters:
params- the hash algorithm parameters- Returns:
- a stateful long-width hash function
-
-