All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.devskiller.friendly_id.Url62 Maven / Gradle / Ivy

The newest version!
package com.devskiller.friendly_id;

import java.math.BigInteger;
import java.util.UUID;

/**
 * Class to convert UUID to Url62 IDs
 */
class Url62 {


	/**
	 * Create url62 id
	 *
	 * @return url62 encoded id
	 */
	static String create() {
		return encode(UUID.randomUUID());
	}

	/**
	 * Encode UUID to Url62 id
	 *
	 * @param uuid UUID to be encoded
	 * @return url62 encoded UUID
	 */
	static String encode(UUID uuid) {
		BigInteger pair = UuidConverter.convertToBigInteger(uuid);
		return Base62.encode(pair);
	}

	/**
	 * Decode url62 id to UUID
	 *
	 * @param id url62 encoded id
	 * @return decoded UUID
	 */
	static UUID decode(String id) {
		BigInteger decoded = Base62.decode(id);
		return UuidConverter.convertFromBigInteger(decoded);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy