net.aequologica.neo.shakuntala.UUIDProducerImpl Maven / Gradle / Ivy
package net.aequologica.neo.shakuntala;
import java.util.Map;
import java.util.UUID;
import javax.inject.Named;
import javax.inject.Singleton;
@Singleton
@Named(value = "uuid")
public class UUIDProducerImpl implements UUIDProducer {
final private UUID uuid;
public UUIDProducerImpl() {
UUID localuuid = UUID.randomUUID();
try {
Map env = System.getenv();
String uuidEnv = env.get("shakuntala.uuid");
if (uuidEnv != null) {
localuuid = UUID.fromString(uuidEnv);
} else {
String uuidproperty = System.getProperty("shakuntala.uuid");
if (uuidproperty != null) {
localuuid = UUID.fromString(uuidproperty);
}
}
} catch (IllegalArgumentException e) {
localuuid = UUID.randomUUID();
} finally {
uuid = localuuid;
}
}
@Override
public UUID getUUID() {
return this.uuid;
}
@Override
public UUID getRandomUUID() {
return UUID.randomUUID();
}
@Override
public String toString() {
return this.uuid.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy