class SnippetUtils {

    private String generateId(final String currentId, final String seed, boolean isCopy) {
        long msb = UUID.fromString(currentId).getMostSignificantBits();

        UUID uuid;
        if (StringUtils.isBlank(seed)) {
            long lsb = randomGenerator.nextLong();
            if (isCopy) {
                uuid = ComponentIdGenerator.generateId(msb, lsb, true); // will increment msb if necessary
            } else {
                // since msb is extracted from type-one UUID, the type-one semantics will be preserved
                uuid = new UUID(msb, lsb);
            }
        } else {
            UUID seedId = UUID.nameUUIDFromBytes((currentId + seed).getBytes(StandardCharsets.UTF_8));
            if (isCopy) {
                // will ensure the type-one semantics for new UUID generated from msb extracted from seedId
                uuid = ComponentIdGenerator.generateId(seedId.getMostSignificantBits(), seedId.getLeastSignificantBits(), false);
            } else {
                uuid = new UUID(msb, seedId.getLeastSignificantBits());
            }
        }
        logger.debug("Generating UUID {} from currentId={}, seed={}, isCopy={}", uuid, currentId, seed, isCopy);
        return uuid.toString();
    }

}