import re
import itertools


def _java_hex(uuid):
    """Java Mongo Driver transfers byte representation of UUIDs in little endian format.
    See also https://jira.mongodb.org/browse/JAVA-403
    :param uuid:
    :return: reordered hex sequence
    """
    _hex = re.sub(r'[{}-]', '', uuid)
    bytes = list(zip(_hex[0::2], _hex[1::2]))
    msb = "".join(itertools.chain(*bytes[0:8][::-1]))
    lsb = "".join(itertools.chain(*bytes[8:16][::-1]))
    _hex = msb + lsb
    return _hex