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

com.softicar.platform.common.core.clock.CurrentClock Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.core.clock;

import com.softicar.platform.common.core.singleton.Singleton;
import java.time.Clock;
import java.util.Objects;

/**
 * Provides a {@link ThreadLocal} to define the default {@link Clock} to use.
 *
 * @author Oliver Richers
 */
public class CurrentClock {

	private static final Singleton CURRENT_CLOCK = new Singleton<>(Clock::systemDefaultZone);

	/**
	 * Returns the default {@link Clock} for the current {@link Thread}.
	 * 

* If no clock has been defined explicitly, * {@link Clock#systemDefaultZone()} will be returned. * * @return the default clock (never null) */ public static Clock get() { return CURRENT_CLOCK.get(); } /** * Defines the {@link Clock} to be returned by {@link #get()}. * * @param clock * the clock to use (never null) */ public static void set(Clock clock) { CURRENT_CLOCK.set(Objects.requireNonNull(clock)); } /** * Resets this to the default {@link Clock}. */ public static void reset() { CURRENT_CLOCK.set(null); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy