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

io.polaris.core.guid.Guids Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package io.polaris.core.guid;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Qt
 * @since 1.8
 */
public class Guids {
	private static final Map guidCache = new ConcurrentHashMap<>();
	private static LocalNodeStrategy defaultStrategy = LocalNodeStrategy.getInstance("java");
	private static final Guid defaultInstance = new Guid(defaultStrategy);

	public static void setDefaultStrategy(LocalNodeStrategy defaultStrategy) {
		Guids.defaultStrategy = defaultStrategy;
	}

	public static Guid getInstance() {
		return defaultInstance;
	}

	public static Guid getInstance(String name) {
		if (name == null) {
			return defaultInstance;
		}
		Guid guid = guidCache.get(name);
		if (guid == null) {
			synchronized (guidCache) {
				guid = guidCache.get(name);
				if (guid == null) {
					guid = new Guid(defaultStrategy);
					guidCache.put(name, guid);
				}
			}
		}
		return guid;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy