1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.id.uuid; 18 19 /** 20 * <p>Constant values commonly needed in the uuid classes.</p> 21 * 22 * @author Commons-Id Team 23 * @version $Revision: 480488 $ $Date: 2006-11-29 08:57:26 +0000 (Wed, 29 Nov 2006) $ 24 * 25 */ 26 public interface Constants { 27 28 //** Magic number constants 29 /** Bits in a UUID. */ 30 int UUID_BIT_LENGTH = 128; 31 32 /** Number of bytes in a UUID. */ 33 int UUID_BYTE_LENGTH = 16; 34 35 36 //** Formatting and validation constants 37 /** Chars in a UUID String. */ 38 int UUID_UNFORMATTED_LENGTH = 32; 39 40 /** Chars in a UUID String. */ 41 int UUID_FORMATTED_LENGTH = 36; 42 43 /** Token length of '-' separated tokens. */ 44 int TOKENS_IN_UUID = 5; 45 46 /** Array to check tokenized UUID's segment lengths */ 47 int[] TOKEN_LENGTHS = {8, 4, 4, 4, 12}; 48 49 /** Insertion point 1 for dashes in the string format */ 50 int FORMAT_POSITION1 = 8; 51 52 /** Insertion point 2 for dashes in the string format */ 53 int FORMAT_POSITION2 = 13; 54 55 /** Insertion point 3 for dashes in the string format */ 56 int FORMAT_POSITION3 = 18; 57 58 /** Insertion point 4 for dashes in the string format */ 59 int FORMAT_POSITION4 = 23; 60 61 /** The string prefix for a urn UUID identifier. */ 62 String URN_PREFIX = "urn:uuid:"; 63 64 65 //** UUID Variant Constants 66 /** UUID variant bits described in the IETF Draft MSB order, 67 * this is the "Reserved, NCS backward compatibility field" 0 x x with unknown bits as 0*/ 68 int VARIANT_NCS_COMPAT = 0; 69 70 /** UUID variant bits described in the IETF Draft MSB order, 71 * this is the IETF Draft memo variant field 1 0 x with unknown bits as 0*/ 72 int VARIANT_IETF_DRAFT = 2; 73 74 /** UUID variant bits described in the IETF Draft MSB order, 75 * this is the IETF Draft "Microsoft Corporation" field variant 1 1 0 x with unknown bits as 0*/ 76 int VARIANT_MS = (byte) 6; 77 78 /** UUID variant bits described in the IETF Draft MSB order, 79 * this is the "Future Reserved variant 1 1 1 x with unknown bits as 0*/ 80 int VARIANT_FUTURE = 7; 81 82 83 //** UUID Version Constants 84 /** Version one constant for UUID version one of four */ 85 int VERSION_ONE = 1; 86 87 /** Version two constant for UUID version two of four */ 88 int VERSION_TWO = 2; 89 90 /** Version three constant for UUID version three of four */ 91 int VERSION_THREE = 3; 92 93 /** Version four constant for UUID version four of four */ 94 int VERSION_FOUR = 4; 95 96 /** Version five constant for UUID version five - identical to version 3 */ 97 int VERSION_FIVE = 3; 98 99 /** Constants that correspond to the encoding being used, a la 100 * http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-04.txt. 101 * Current legal values are "MD5" and "SHA1" 102 */ 103 String MD5_ENCODING = "MD5"; 104 String SHA1_ENCODING = "SHA1"; 105 106 //** Exception message constants 107 /** Message indicating this is not a version one UUID */ 108 String WRONG_VAR_VER_MSG = "Not a ietf variant 2 or version 1 (time-based UUID)"; 109 110 // ** Array positions and lengths of UUID fields ** // 111 /** Byte length of time low field */ 112 int TIME_LOW_BYTE_LEN = 4; 113 /** Byte length of time low field */ 114 int TIME_MID_BYTE_LEN = 2; 115 /** Byte length of time low field */ 116 int TIME_HI_BYTE_LEN = 2; 117 /** Timestamp byte[] position of time low field */ 118 int TIME_LOW_TS_POS = 4; 119 /** Timestamp byte[] position mid field */ 120 int TIME_MID_TS_POS = 2; 121 /** Timestamp byte[] position hi field */ 122 int TIME_HI_TS_POS = 0; 123 /** uuid array position start of time low field */ 124 int TIME_LOW_START_POS = 0; 125 /** uuid array position start of mid field */ 126 int TIME_MID_START_POS = 4; 127 /** uuid array position start of hi field */ 128 int TIME_HI_START_POS = 6; 129 /** Byte position of the clock sequence and reserved field */ 130 short TIME_HI_AND_VERSION_BYTE_6 = 6; 131 /** Byte position of the clock sequence and reserved field */ 132 short CLOCK_SEQ_HI_AND_RESERVED_BYTE_8 = 8; 133 }