Package org.incenp.obofoundry.sssom
Class MappingHasher
- java.lang.Object
-
- org.incenp.obofoundry.sssom.MappingHasher
-
public class MappingHasher extends Object
Creates deterministic hash values from mappings.
-
-
Constructor Summary
Constructors Constructor Description MappingHasher()Creates a new instance that will produce the standard hash defined by the SSSOM specification.MappingHasher(HashType type)Creates a new instance that will produce the requested type of hash.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static byte[]fnv64(byte[] input)Generates a FNV64 hash.Stringhash(Mapping mapping)Hashes the given mapping.static StringtoHexadecimal(byte[] digest)Encodes a buffer into its hexadecimal representation.static StringtoHexadecimal(byte[] digest, boolean lower)Encodes a buffer into its hexadecimal representation, optional in lowercase.static StringtoZBase32(byte[] digest)Encodes a buffer into its Z-Base32 string representation.
-
-
-
Constructor Detail
-
MappingHasher
public MappingHasher()
Creates a new instance that will produce the standard hash defined by the SSSOM specification.
-
MappingHasher
public MappingHasher(HashType type)
Creates a new instance that will produce the requested type of hash.- Parameters:
type- The type of hash to produce.
-
-
Method Detail
-
hash
public String hash(Mapping mapping)
Hashes the given mapping.- Parameters:
mapping- The mapping to hash.- Returns:
- The unique hash for the mapping.
-
fnv64
public static byte[] fnv64(byte[] input)
Generates a FNV64 hash.This method implements the 64-bit variant of the FNV-1a hash function as defined in RFC 9923.
- Parameters:
input- The data to hash.- Returns:
- The resulting hash value, as an array of bytes in little endian order.
-
toZBase32
public static String toZBase32(byte[] digest)
Encodes a buffer into its Z-Base32 string representation.This method implements the Z-Base32 encoding as defined in RFC 6189 ยง5.1.6 and human-oriented base32 encoding.
- Parameters:
digest- The input buffer to encode.- Returns:
- The Z-Base32-encoded string representation of the input buffer.
-
toHexadecimal
public static String toHexadecimal(byte[] digest)
Encodes a buffer into its hexadecimal representation.This method implements the Base16 encoding as defined in RFC 4648.
- Parameters:
digest- The input buffer to encode.- Returns:
- The hexadecimal representation of the input buffer.
-
toHexadecimal
public static String toHexadecimal(byte[] digest, boolean lower)
Encodes a buffer into its hexadecimal representation, optional in lowercase.- Parameters:
digest- The input buffer to encode.lower- Iftrue, lowercase characters are used.- Returns:
- The hexadecimal representation of the input buffer.
-
-