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

io.github.pirocks.util.UUIDUtil.kt Maven / Gradle / Ivy

Go to download

A simple library for working with first order logic and natural deduction proofs

The newest version!
package io.github.pirocks.util

import java.util.*
import java.util.logging.Logger

object UUIDUtil {
    val logger = Logger.getLogger(UUIDUtil.javaClass.name)

    val usedUUIDS: MutableSet = mutableSetOf()//todo don't forget to serialize
    //    var uuidCount = 0;
    fun generateUUID(): UUID {
        val randomUUID = UUID.randomUUID()
        if (randomUUID in usedUUIDS) {
            logger.warning("A uuid collision would have occurred if a set of previous uuids hadn't been created")
            return generateUUID()
        }
        usedUUIDS.add(randomUUID)
        return randomUUID
    }

    fun toPrettyString(uuid: UUID): String = "VariableNumber" + Math.abs((uuid.mostSignificantBits + uuid.leastSignificantBits).toInt()).toShort().toString(16).replace('-','0')

    fun toMathML2(uuid: UUID): String = "" + toPrettyString(uuid) + ""

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy