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

com.evrythng.commons.RefTS Maven / Gradle / Ivy

There is a newer version: 1.33
Show newest version
/*
 * (c) Copyright 2012 EVRYTHNG Ltd London / Zurich
 * www.evrythng.com
 */
package com.evrythng.commons;

/**
 * Thread-safe version of {@link Ref}.
 * 
 * @author Michel Yerly (my)
 **/
public final class RefTS {

	private volatile T obj = null;

	/**
	 * Creates an instance that holds the null value.
	 */
	public RefTS() {
	}

	/**
	 * Creates an instance that holds the specified value.
	 */
	public RefTS(final T obj) {
		this.obj = obj;
	}

	/**
	 * Gets the value held.
	 */
	public final T get() {
		return obj;
	}

	/**
	 * Sets the value to hold.
	 */
	public final synchronized void set(final T obj) {
		this.obj = obj;
	}

	/**
	 * Null-safe setter.
	 */
	public static  void set(RefTS ref, T obj) {
		if (ref != null) {
			ref.set(obj);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy