View Javadoc
1   /*******************************************************************************
2    * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
3    * Thomschke.
4    * 
5    * All Rights Reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    * http://www.eclipse.org/legal/epl-v10.html
9    * 
10   * Contributors:
11   *     Sebastian Thomschke - initial implementation.
12   *******************************************************************************/
13  package net.sf.oval.internal.util;
14  
15  /**
16   * @author Sebastian Thomschke
17   */
18  public final class ThreadLocalObjectCache<K, V> extends ThreadLocal<ObjectCache<K, V>>
19  {
20  	private final int maxElementsToKeep;
21  
22  	public ThreadLocalObjectCache()
23  	{
24  		this.maxElementsToKeep = -1;
25  	}
26  
27  	public ThreadLocalObjectCache(final int maxElementsToKeep)
28  	{
29  		this.maxElementsToKeep = maxElementsToKeep;
30  	}
31  
32  	/**
33  	 * {@inheritDoc}
34  	 */
35  	@Override
36  	public ObjectCache<K, V> initialValue()
37  	{
38  		return new ObjectCache<K, V>(maxElementsToKeep);
39  	}
40  }