jdk/test/java/util/UUID/UUIDTest.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 4347 ab0a9f495844
child 12690 a2d28a91f9b7
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
     2
 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 4173528 5068772
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary Unit tests for java.util.UUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
public class UUIDTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    static Random generator = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
        containsTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        randomUUIDTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        nameUUIDFromBytesTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        stringTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        versionTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        variantTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        timestampTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        clockSequenceTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        nodeTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        hashCodeEqualsTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        compareTo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    // Verify that list.contains detects UUID collisons
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static void containsTest() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        List list = new LinkedList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        list.add(new UUID(4,4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        if (!list.contains(new UUID(4,4)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            throw new Exception("contains test did not work as expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static void randomUUIDTest() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        List list = new LinkedList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            UUID u1 = UUID.randomUUID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            if (list.contains(u1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                throw new Exception("random UUID collision very unlikely");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            list.add(u1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static void nameUUIDFromBytesTest() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        Random byteSource = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        byte[] someBytes = new byte[12];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        List list = new LinkedList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            byteSource.nextBytes(someBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            UUID test = UUID.nameUUIDFromBytes(someBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            if (list.contains(test))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                throw new Exception("byte UUID collision very unlikely");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            list.add(test);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static void stringTest() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            UUID u1 = UUID.randomUUID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            UUID u2 = UUID.fromString(u1.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            if (!u1.equals(u2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                throw new Exception("UUID -> string -> UUID failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static void versionTest() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        UUID test = UUID.randomUUID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (test.version() != 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            throw new Exception("randomUUID not type 4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        Random byteSource = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        byte[] someBytes = new byte[12];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        byteSource.nextBytes(someBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        test = UUID.nameUUIDFromBytes(someBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (test.version() != 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            throw new Exception("nameUUIDFromBytes not type 3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        test = UUID.fromString("9835451d-e2e0-1e41-8a5a-be785f17dcda");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (test.version() != 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            throw new Exception("wrong version fromString 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        test = UUID.fromString("9835451d-e2e0-2e41-8a5a-be785f17dcda");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (test.version() != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            throw new Exception("wrong version fromString 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        test = UUID.fromString("9835451d-e2e0-3e41-8a5a-be785f17dcda");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (test.version() != 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            throw new Exception("wrong version fromString 3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        test = UUID.fromString("9835451d-e2e0-4e41-8a5a-be785f17dcda");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (test.version() != 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            throw new Exception("wrong version fromString 4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        test = new UUID(0x0000000000001000L, 55L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (test.version() != 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            throw new Exception("wrong version from bit set to 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        test = new UUID(0x0000000000002000L, 55L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (test.version() != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throw new Exception("wrong version from bit set to 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        test = new UUID(0x0000000000003000L, 55L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (test.version() != 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            throw new Exception("wrong version from bit set to 3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        test = new UUID(0x0000000000004000L, 55L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (test.version() != 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            throw new Exception("wrong version from bit set to 4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private static void variantTest() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        UUID test = UUID.randomUUID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (test.variant() != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            throw new Exception("randomUUID not variant 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Random byteSource = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        byte[] someBytes = new byte[12];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        byteSource.nextBytes(someBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        test = UUID.nameUUIDFromBytes(someBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (test.variant() != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            throw new Exception("nameUUIDFromBytes not variant 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        test = new UUID(55L, 0x0000000000001000L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (test.variant() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            throw new Exception("wrong variant from bit set to 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        test = new UUID(55L, 0x8000000000001000L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (test.variant() != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            throw new Exception("wrong variant from bit set to 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
       test = new UUID(55L, 0xc000000000001000L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (test.variant() != 6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            throw new Exception("wrong variant from bit set to 6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
       test = new UUID(55L, 0xe000000000001000L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (test.variant() != 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            throw new Exception("wrong variant from bit set to 7");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    private static void timestampTest() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        UUID test = UUID.randomUUID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            test.timestamp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            throw new Exception("Expected exception not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        } catch (UnsupportedOperationException uoe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            // Correct result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        test = UUID.fromString("00000001-0000-1000-8a5a-be785f17dcda");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (test.timestamp() != 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            throw new Exception("Incorrect timestamp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        test = UUID.fromString("00000400-0000-1000-8a5a-be785f17dcda");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (test.timestamp() != 1024)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            throw new Exception("Incorrect timestamp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        test = UUID.fromString("FFFFFFFF-FFFF-1FFF-8a5a-be785f17dcda");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (test.timestamp() != Long.MAX_VALUE>>3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            throw new Exception("Incorrect timestamp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private static void clockSequenceTest() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        UUID test = UUID.randomUUID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            test.clockSequence();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            throw new Exception("Expected exception not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        } catch (UnsupportedOperationException uoe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            // Correct result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        test = UUID.fromString("00000001-0000-1000-8001-be785f17dcda");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (test.clockSequence() != 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            throw new Exception("Incorrect sequence");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        test = UUID.fromString("00000001-0000-1000-8002-be785f17dcda");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (test.clockSequence() != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            throw new Exception("Incorrect sequence");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        test = UUID.fromString("00000001-0000-1000-8010-be785f17dcda");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (test.clockSequence() != 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            throw new Exception("Incorrect sequence");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        test = UUID.fromString("00000001-0000-1000-bFFF-be785f17dcda");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (test.clockSequence() != ((2L<<13)-1)) // 2^14 - 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            throw new Exception("Incorrect sequence");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private static void nodeTest() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        UUID test = UUID.randomUUID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            test.node();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new Exception("Expected exception not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        } catch (UnsupportedOperationException uoe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            // Correct result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        test = UUID.fromString("00000001-0000-1000-8001-000000000001");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (test.node() != 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            throw new Exception("Incorrect node");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        test = UUID.fromString("00000001-0000-1000-8002-FFFFFFFFFFFF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (test.node() != ((2L<<47)-1)) // 2^48 - 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            throw new Exception("Incorrect node");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    private static void hashCodeEqualsTest() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        // If two UUIDs are equal they must have the same hashCode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            UUID u1 = UUID.randomUUID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            UUID u2 = UUID.fromString(u1.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            if (u1.hashCode() != u2.hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                throw new Exception("Equal UUIDs with different hashcodes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // Test equality of UUIDs with tampered bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        for (int i=0; i<1000; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            long l = generator.nextLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            long l2 = generator.nextLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            int position = generator.nextInt(64);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            UUID u1 = new UUID(l, l2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            l = l ^ (1L << position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            UUID u2 = new UUID(l, l2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (u1.equals(u2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                throw new Exception("UUIDs with different bits equal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    private static void compareTo() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        UUID id = new UUID(33L, 63L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        UUID id2 = new UUID(34L, 62L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        UUID id3 = new UUID(34L, 63L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        UUID id4 = new UUID(34L, 64L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        UUID id5 = new UUID(35L, 63L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if ((id.compareTo(id2) >= 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            (id2.compareTo(id3) >= 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            (id3.compareTo(id4) >= 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            (id4.compareTo(id5) >= 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            throw new RuntimeException("compareTo failure");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if ((id5.compareTo(id4) <= 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            (id4.compareTo(id3) <= 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            (id3.compareTo(id2) <= 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            (id2.compareTo(id) <= 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            throw new RuntimeException("compareTo failure");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (id.compareTo(id) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            throw new RuntimeException("compareTo failure");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
}