@Test public void buildTimestampOnly() { final long TEST_TS_A = 143062936275L; final String TEST_A_REVERSED = "cb54ecf284000000"; final byte[] result_a = IDBuilder.build(new Blueprint(TEST_TS_A, 0, 0, 0)); assertThat(Hex.encodeHexString(result_a).toLowerCase(), CoreMatchers.is(TEST_A_REVERSED)); final long TEST_TS_B = 0x3FFFFFFFDL; final String TEST_B_REVERSED = "bfffffffc0000000"; final byte[] result_b = IDBuilder.build(new Blueprint(TEST_TS_B, 0, 0, 0)); assertThat(Hex.encodeHexString(result_b).toLowerCase(), CoreMatchers.is(TEST_B_REVERSED)); }
public static byte[] build(Blueprint blueprint) { long reverseTimestamp = Long.reverse(blueprint.getTimestamp()); ByteBuffer bb = ByteBuffer.allocate(8); byte[] tsBytes = bb.putLong(reverseTimestamp).array(); int or = tsBytes[5] | (byte) blueprint.getSequence(); tsBytes[5] = (byte) or; int generatorAndCluster = blueprint.getGeneratorId() << 4; generatorAndCluster += blueprint.getClusterId(); tsBytes[7] = (byte) generatorAndCluster; generatorAndCluster >>>= 8; tsBytes[6] = (byte) generatorAndCluster; return tsBytes; }
IDBuilder { public static byte[] build(Blueprint blueprint) { long reverseTimestamp = Long.reverse(blueprint.getTimestamp()); ByteBuffer bb = ByteBuffer.allocate(8); byte[] tsBytes = bb.putLong(reverseTimestamp).array(); int or = tsBytes[5] | (byte) blueprint.getSequence(); tsBytes[5] = (byte) or; int generatorAndCluster = blueprint.getGeneratorId() << 4; generatorAndCluster += blueprint.getClusterId(); tsBytes[7] = (byte) generatorAndCluster; generatorAndCluster >>>= 8; tsBytes[6] = (byte) generatorAndCluster; return tsBytes; } }
IDBuilder { public static byte[] build(Blueprint blueprint) { long reverseTimestamp = Long.reverse(blueprint.getTimestamp()); ByteBuffer bb = ByteBuffer.allocate(8); byte[] tsBytes = bb.putLong(reverseTimestamp).array(); int or = tsBytes[5] | (byte) blueprint.getSequence(); tsBytes[5] = (byte) or; int generatorAndCluster = blueprint.getGeneratorId() << 4; generatorAndCluster += blueprint.getClusterId(); tsBytes[7] = (byte) generatorAndCluster; generatorAndCluster >>>= 8; tsBytes[6] = (byte) generatorAndCluster; return tsBytes; }  }
IDBuilder { public static byte[] build(Blueprint blueprint) { long reverseTimestamp = Long.reverse(blueprint.getTimestamp()); ByteBuffer bb = ByteBuffer.allocate(8); byte[] tsBytes = bb.putLong(reverseTimestamp).array(); int or = tsBytes[5] | (byte) blueprint.getSequence(); tsBytes[5] = (byte) or; int generatorAndCluster = blueprint.getGeneratorId() << 4; generatorAndCluster += blueprint.getClusterId(); tsBytes[7] = (byte) generatorAndCluster; generatorAndCluster >>>= 8; tsBytes[6] = (byte) generatorAndCluster; return tsBytes; }  static byte[] build(Blueprint blueprint); static Blueprint parse(byte[] id); static int parseSequenceId(byte[] id); static int parseGeneratorId(byte[] id); static int parseClusterId(byte[] id); static long parseTimestamp(byte[] id); }
IDBuilder { public static byte[] build(Blueprint blueprint) { long reverseTimestamp = Long.reverse(blueprint.getTimestamp()); ByteBuffer bb = ByteBuffer.allocate(8); byte[] tsBytes = bb.putLong(reverseTimestamp).array(); int or = tsBytes[5] | (byte) blueprint.getSequence(); tsBytes[5] = (byte) or; int generatorAndCluster = blueprint.getGeneratorId() << 4; generatorAndCluster += blueprint.getClusterId(); tsBytes[7] = (byte) generatorAndCluster; generatorAndCluster >>>= 8; tsBytes[6] = (byte) generatorAndCluster; return tsBytes; }  static byte[] build(Blueprint blueprint); static Blueprint parse(byte[] id); static int parseSequenceId(byte[] id); static int parseGeneratorId(byte[] id); static int parseClusterId(byte[] id); static long parseTimestamp(byte[] id);  }