package org.alfresco.repo.domain; import java.io.UnsupportedEncodingException; import java.util.zip.CRC32; import org.alfresco.util.Pair; /** * Helper class to calculate CRC values for string persistence. * * @author Derek Hulley * @since 3.2 */ public class CrcHelper { public static final String EMPTY_STRING = ".empty"; /** * Calculate a persistable, unique pair of values that can be persisted in a database unique * key and guarantee correct case-sensitivity. *
* While the short-string version of the value is always lowercase, the CRC is * calculated from the virgin string if case-sensitivity is enforced; in the case-insensitive * case, the CRC is calculated from a lowercase version of the string. *
* If the value is an empty string, then {@link #EMPTY_STRING} is used instead. This ensures
* that persisted values don't fall foul of the Oracle empty string comparison "behaviour" i.e
* you should never persist an empty string in Oracle as it equates to a SQL NULL.
*
* @param value the raw value that will be persisted
* @param dataLength the maximum number of characters that can be persisted
* @param useCharsFromStart true if the shortened string value must be made from
* the first characters of the string or false to use
* characters from the end of the string.
* @param caseSensitive true if the resulting pair must be case-sensitive or
* false if the pair must be case-insensitive.
* @return Return the persistable pair. The result will never be null,
* but the individual pair values will be null if the
* value given is null
*/
public static Pair