Package tenapull.data.persistence
Class Hash
java.lang.Object
tenapull.data.persistence.Hash
- All Implemented Interfaces:
java.lang.Comparable<Hash>
public class Hash extends java.lang.Object implements java.lang.Comparable<Hash>
Represents a "lazy" or "dirty" SHA-512 hash of a string lookup or object lookup.
This is referred to as "lazy/drity" because if the string being hashed is less than 64
bytes, then the string itself is used in place of the hash. This still guarantees
the uniqueness of the hash, while saving the need to calculate the SHA-512 hash
when it would be unnecessary
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Hash.Converter
Converts Hash instances back and forth between the database varbinary datatype and the hash fields in the ORM. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description static int
compareTo(byte[] mine, byte[] theirs)
Returns a comparison of two byte arraysint
compareTo(Hash other)
static boolean
equals(byte[] mine, byte[] theirs)
Determines if two byte arrays are equivalentboolean
equals(java.lang.Object o)
int
hashCode()
static int
hashCode(byte[] bytes)
Generates a unique java hashCode from the provided bytes array by applying a cumulative bitwise XOR operation on each sequential set of 4 bytesstatic int
hashCode(java.lang.String str)
Generates a unique java hashCode from the bytes array in the provided stringstatic java.lang.String
hexString(byte[] bytes)
Converts an array of bytes into a hexadecimal encoded stringstatic java.lang.String
hexString(java.lang.String str)
Lazily hashes the provided string and returns the resulting hash as a hexadecimal encodedstatic byte[]
lazyHash(java.lang.String str)
Lazily hashes the provided string into an array bytesjava.lang.String
toString()
-
Field Details
-
ALGORITHM
public static final java.lang.String ALGORITHMThe algorithm which we are using -- SHA-512- See Also:
- Constant Field Values
-
HASH_SIZE
public static final int HASH_SIZEThe size of a SHA-512 hash -- 64 bytes.- See Also:
- Constant Field Values
-
-
Constructor Details
-
Method Details
-
lazyHash
public static byte[] lazyHash(java.lang.String str)Lazily hashes the provided string into an array bytes- Parameters:
str
- the str- Returns:
- the byte [ ]
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
hexString
public static java.lang.String hexString(byte[] bytes)Converts an array of bytes into a hexadecimal encoded string- Parameters:
bytes
- the bytes- Returns:
- the string
-
hexString
public static java.lang.String hexString(java.lang.String str)Lazily hashes the provided string and returns the resulting hash as a hexadecimal encoded- Parameters:
str
- the str- Returns:
- the string
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
hashCode
public static int hashCode(java.lang.String str)Generates a unique java hashCode from the bytes array in the provided string- Parameters:
str
- the str- Returns:
- the int
-
hashCode
public static int hashCode(byte[] bytes)Generates a unique java hashCode from the provided bytes array by applying a cumulative bitwise XOR operation on each sequential set of 4 bytes- Parameters:
bytes
- the bytes- Returns:
- the int
-
equals
public static boolean equals(byte[] mine, byte[] theirs)Determines if two byte arrays are equivalent- Parameters:
mine
- byte array1theirs
- byte array2- Returns:
- the boolean
-
compareTo
- Specified by:
compareTo
in interfacejava.lang.Comparable<Hash>
-
compareTo
public static int compareTo(byte[] mine, byte[] theirs)Returns a comparison of two byte arrays- Parameters:
mine
- the comparable whose compare method was calledtheirs
- the comparable being compared against- Returns:
- the int
-