@Test public void buildZero() { final byte[] result = IDBuilder.build(new Blueprint(0, 0, 0, 0)); final byte[] zero = new byte[8]; assertThat(result, is(zero)); }
public static byte[] build(Blueprint blueprint) { ByteBuffer bb = ByteBuffer.allocate(8); switch (blueprint.getMode()) { case SPREAD: long reverseTimestamp = Long.reverse(blueprint.getTimestamp()); bb.putLong(reverseTimestamp); break; case TIME_SEQUENTIAL: long timestamp = blueprint.getTimestamp(); bb.putLong(timestamp << 22); break; } byte[] tsBytes = bb.array(); int or = tsBytes[5] | (byte) blueprint.getSequence(); tsBytes[5] = (byte) or; int flagGeneratorCluster = blueprint.getGeneratorId() << 4; flagGeneratorCluster += blueprint.getClusterId(); flagGeneratorCluster += blueprint.getMode().getModeMask() << 12; tsBytes[7] = (byte) flagGeneratorCluster; flagGeneratorCluster >>>= 8; tsBytes[6] = (byte) flagGeneratorCluster; return tsBytes; }
IDBuilder { public static byte[] build(Blueprint blueprint) { ByteBuffer bb = ByteBuffer.allocate(8); switch (blueprint.getMode()) { case SPREAD: long reverseTimestamp = Long.reverse(blueprint.getTimestamp()); bb.putLong(reverseTimestamp); break; case TIME_SEQUENTIAL: long timestamp = blueprint.getTimestamp(); bb.putLong(timestamp << 22); break; } byte[] tsBytes = bb.array(); int or = tsBytes[5] | (byte) blueprint.getSequence(); tsBytes[5] = (byte) or; int flagGeneratorCluster = blueprint.getGeneratorId() << 4; flagGeneratorCluster += blueprint.getClusterId(); flagGeneratorCluster += blueprint.getMode().getModeMask() << 12; tsBytes[7] = (byte) flagGeneratorCluster; flagGeneratorCluster >>>= 8; tsBytes[6] = (byte) flagGeneratorCluster; return tsBytes; } }
IDBuilder { public static byte[] build(Blueprint blueprint) { ByteBuffer bb = ByteBuffer.allocate(8); switch (blueprint.getMode()) { case SPREAD: long reverseTimestamp = Long.reverse(blueprint.getTimestamp()); bb.putLong(reverseTimestamp); break; case TIME_SEQUENTIAL: long timestamp = blueprint.getTimestamp(); bb.putLong(timestamp << 22); break; } byte[] tsBytes = bb.array(); int or = tsBytes[5] | (byte) blueprint.getSequence(); tsBytes[5] = (byte) or; int flagGeneratorCluster = blueprint.getGeneratorId() << 4; flagGeneratorCluster += blueprint.getClusterId(); flagGeneratorCluster += blueprint.getMode().getModeMask() << 12; tsBytes[7] = (byte) flagGeneratorCluster; flagGeneratorCluster >>>= 8; tsBytes[6] = (byte) flagGeneratorCluster; return tsBytes; }  }
IDBuilder { public static byte[] build(Blueprint blueprint) { ByteBuffer bb = ByteBuffer.allocate(8); switch (blueprint.getMode()) { case SPREAD: long reverseTimestamp = Long.reverse(blueprint.getTimestamp()); bb.putLong(reverseTimestamp); break; case TIME_SEQUENTIAL: long timestamp = blueprint.getTimestamp(); bb.putLong(timestamp << 22); break; } byte[] tsBytes = bb.array(); int or = tsBytes[5] | (byte) blueprint.getSequence(); tsBytes[5] = (byte) or; int flagGeneratorCluster = blueprint.getGeneratorId() << 4; flagGeneratorCluster += blueprint.getClusterId(); flagGeneratorCluster += blueprint.getMode().getModeMask() << 12; tsBytes[7] = (byte) flagGeneratorCluster; flagGeneratorCluster >>>= 8; tsBytes[6] = (byte) flagGeneratorCluster; 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); static Mode parseMode(byte[] id); }
IDBuilder { public static byte[] build(Blueprint blueprint) { ByteBuffer bb = ByteBuffer.allocate(8); switch (blueprint.getMode()) { case SPREAD: long reverseTimestamp = Long.reverse(blueprint.getTimestamp()); bb.putLong(reverseTimestamp); break; case TIME_SEQUENTIAL: long timestamp = blueprint.getTimestamp(); bb.putLong(timestamp << 22); break; } byte[] tsBytes = bb.array(); int or = tsBytes[5] | (byte) blueprint.getSequence(); tsBytes[5] = (byte) or; int flagGeneratorCluster = blueprint.getGeneratorId() << 4; flagGeneratorCluster += blueprint.getClusterId(); flagGeneratorCluster += blueprint.getMode().getModeMask() << 12; tsBytes[7] = (byte) flagGeneratorCluster; flagGeneratorCluster >>>= 8; tsBytes[6] = (byte) flagGeneratorCluster; 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); static Mode parseMode(byte[] id);  }