net.lshift.diffa.participant.scanning.DigestBuilder Maven / Gradle / Ivy
/**
* Copyright (C) 2010-2011 LShift Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.lshift.diffa.participant.scanning;
import net.jcip.annotations.NotThreadSafe;
import org.apache.commons.codec.binary.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
/**
* Utility for building digests based on a series of entities.
*
* This caches each id that is added to it, in order to ensure that id re-ordering is detected.
* The downside of the current implementation is that the id cache is not thread safe.
*
* The 2-argument constructor is present to support non-codepoint ordered
* collations--eg: most locale-specific orderings will group upper-and lower
* case letters together, eg:
* [a b A B].sortBy(unicodeOrdering) -> [A a B b]
* [a b A B].sortBy(asciiOrdering) -> [A B a b]
*
*/
@NotThreadSafe
public class DigestBuilder {
private final static Logger log = LoggerFactory.getLogger(DigestBuilder.class);
private final Map digestBuckets;
private final List aggregations;
// this should be a Comparator, but both ICU and the JDK's Collators
// implement Comparator