// 
// Decompiled by Procyon v0.6.0
// 

package io.sentry.util;

import java.util.Arrays;
import java.util.UUID;

public final class UUIDStringUtils
{
    private static final int SENTRY_UUID_STRING_LENGTH = 32;
    private static final int SENTRY_SPAN_UUID_STRING_LENGTH = 16;
    private static final char[] HEX_DIGITS;
    private static final long[] HEX_VALUES;
    
    public static String toSentryIdString(final UUID uuid) {
        final long mostSignificantBits = uuid.getMostSignificantBits();
        final long leastSignificantBits = uuid.getLeastSignificantBits();
        return toSentryIdString(mostSignificantBits, leastSignificantBits);
    }
    
    public static String toSentryIdString(final long mostSignificantBits, final long leastSignificantBits) {
        final char[] uuidChars = new char[32];
        fillMostSignificantBits(uuidChars, mostSignificantBits);
        uuidChars[16] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF000000000000000L) >>> 60)];
        uuidChars[17] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF00000000000000L) >>> 56)];
        uuidChars[18] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF0000000000000L) >>> 52)];
        uuidChars[19] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF000000000000L) >>> 48)];
        uuidChars[20] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF00000000000L) >>> 44)];
        uuidChars[21] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF0000000000L) >>> 40)];
        uuidChars[22] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF000000000L) >>> 36)];
        uuidChars[23] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF00000000L) >>> 32)];
        uuidChars[24] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF0000000L) >>> 28)];
        uuidChars[25] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF000000L) >>> 24)];
        uuidChars[26] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF00000L) >>> 20)];
        uuidChars[27] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF0000L) >>> 16)];
        uuidChars[28] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF000L) >>> 12)];
        uuidChars[29] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF00L) >>> 8)];
        uuidChars[30] = UUIDStringUtils.HEX_DIGITS[(int)((leastSignificantBits & 0xF0L) >>> 4)];
        uuidChars[31] = UUIDStringUtils.HEX_DIGITS[(int)(leastSignificantBits & 0xFL)];
        return new String(uuidChars);
    }
    
    public static String toSentrySpanIdString(final UUID uuid) {
        final long mostSignificantBits = uuid.getMostSignificantBits();
        return toSentrySpanIdString(mostSignificantBits);
    }
    
    public static String toSentrySpanIdString(final long mostSignificantBits) {
        final char[] uuidChars = new char[16];
        fillMostSignificantBits(uuidChars, mostSignificantBits);
        return new String(uuidChars);
    }
    
    private static void fillMostSignificantBits(final char[] uuidChars, final long mostSignificantBits) {
        uuidChars[0] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF000000000000000L) >>> 60)];
        uuidChars[1] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF00000000000000L) >>> 56)];
        uuidChars[2] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF0000000000000L) >>> 52)];
        uuidChars[3] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF000000000000L) >>> 48)];
        uuidChars[4] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF00000000000L) >>> 44)];
        uuidChars[5] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF0000000000L) >>> 40)];
        uuidChars[6] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF000000000L) >>> 36)];
        uuidChars[7] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF00000000L) >>> 32)];
        uuidChars[8] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF0000000L) >>> 28)];
        uuidChars[9] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF000000L) >>> 24)];
        uuidChars[10] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF00000L) >>> 20)];
        uuidChars[11] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF0000L) >>> 16)];
        uuidChars[12] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF000L) >>> 12)];
        uuidChars[13] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF00L) >>> 8)];
        uuidChars[14] = UUIDStringUtils.HEX_DIGITS[(int)((mostSignificantBits & 0xF0L) >>> 4)];
        uuidChars[15] = UUIDStringUtils.HEX_DIGITS[(int)(mostSignificantBits & 0xFL)];
    }
    
    static {
        HEX_DIGITS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        Arrays.fill(HEX_VALUES = new long[128], -1L);
        UUIDStringUtils.HEX_VALUES[48] = 0L;
        UUIDStringUtils.HEX_VALUES[49] = 1L;
        UUIDStringUtils.HEX_VALUES[50] = 2L;
        UUIDStringUtils.HEX_VALUES[51] = 3L;
        UUIDStringUtils.HEX_VALUES[52] = 4L;
        UUIDStringUtils.HEX_VALUES[53] = 5L;
        UUIDStringUtils.HEX_VALUES[54] = 6L;
        UUIDStringUtils.HEX_VALUES[55] = 7L;
        UUIDStringUtils.HEX_VALUES[56] = 8L;
        UUIDStringUtils.HEX_VALUES[57] = 9L;
        UUIDStringUtils.HEX_VALUES[97] = 10L;
        UUIDStringUtils.HEX_VALUES[98] = 11L;
        UUIDStringUtils.HEX_VALUES[99] = 12L;
        UUIDStringUtils.HEX_VALUES[100] = 13L;
        UUIDStringUtils.HEX_VALUES[101] = 14L;
        UUIDStringUtils.HEX_VALUES[102] = 15L;
        UUIDStringUtils.HEX_VALUES[65] = 10L;
        UUIDStringUtils.HEX_VALUES[66] = 11L;
        UUIDStringUtils.HEX_VALUES[67] = 12L;
        UUIDStringUtils.HEX_VALUES[68] = 13L;
        UUIDStringUtils.HEX_VALUES[69] = 14L;
        UUIDStringUtils.HEX_VALUES[70] = 15L;
    }
}
