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

microsoft.exchange.webservices.data.LazyMember Maven / Gradle / Ivy

Go to download

The source came from http://archive.msdn.microsoft.com/ewsjavaapi Support for Maven has been added.

There is a newer version: 1.1.5.2
Show newest version
/**************************************************************************
 * copyright file="LazyMember.java" company="Microsoft"
 *     Copyright (c) Microsoft Corporation.  All rights reserved.
 * 
 * Defines the LazyMember.java.
 **************************************************************************/
package microsoft.exchange.webservices.data;

/**
 * Wrapper class for lazy members. Does lazy initialization of member on first
 * access.
 * 
 * @param 
 *            Type of the lazy member
 * 
 *            If we find ourselves creating a whole bunch of these in our code,
 *            we need to rethink this. Each lazy member holds the actual member,
 *            a lock object, a boolean flag and a delegate. That can turn into a
 *            whole lot of overhead
 */
class LazyMember {

	/** The lazy member. */
	private T lazyMember;

	/** The initialized. */
	private boolean initialized = false;

	/** The lazy implementation. */
	private ILazyMember lazyImplementation;

	/**
	 * Public accessor for the lazy member. Lazy initializes the member on first
	 * access
	 * 
	 * @return the member
	 */
	public T getMember() {
		if (!this.initialized) {
			synchronized (this) {
				if (!this.initialized) {
					this.lazyMember = lazyImplementation.createInstance();
				}
				this.initialized = true;
			}
		}
		return lazyMember;
	}

	/**
	 * Constructor.
	 * 
	 * @param lazyImplementation
	 *            The initialization delegate to call for the item on first
	 *            access
	 */
	public LazyMember(ILazyMember lazyImplementation) {
		this.lazyImplementation = lazyImplementation;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy