@Test public void buildMostlyOnes() { final byte[] result = IDBuilder.build(new Blueprint(Blueprint.MAX_TIMESTAMP, Blueprint.MAX_SEQUENCE_COUNTER, Blueprint.MAX_GENERATOR_ID, Blueprint.MAX_CLUSTER_ID)); final String expected = "ffffffffffff0fff"; assertThat(Hex.encodeHexString(result), CoreMatchers.is(expected)); }
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);  }