/*******************************************************************************
 * This file is part of TERMINAL RECALL
 * Copyright (c) 2012-2014 Chuck Ritola
 * Part of the jTRFP.org project
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     chuck - initial API and implementation
 ******************************************************************************/

package org.jtrfp.trcl.pool;

import java.util.Map;

import com.ochafik.util.Adapter;

/**
 * Not related to the JNDI, but likely to be replaced by it in the future.
 * @author Chuck Ritola
 *
 * @param <K>
 * @param <V>
 */
public class ObjectFactory<K,V> {
    private final Map    <K,V> mapToUse;
    private final Adapter<K,V> keyValueAdapter;
    
    public ObjectFactory(Map<K,V> mapToUse, Adapter<K,V> keyValueAdapter){
	this.mapToUse        = mapToUse;
	this.keyValueAdapter = keyValueAdapter;
    }
    
    public V get(K key){
	V result = mapToUse.get(key);
	if(result==null)
	    mapToUse.put(key, result=keyValueAdapter.adapt(key));
	return result;
    }//end public(key)
}//end CachedObjectFactory

@@ -739,16 +739,77 @@
 future.%0A
+ * Creates and caches objects of type V from keys of type K.%0A
  * @auth
@@ -1156,175 +1156,931 @@
     
-public V get(K key)%7B%0A%09V result = mapToUse.get(key);%0A%09if(result==null)%0A%09    mapToUse.put(key, result=keyValueAdapter.adapt(key));%0A%09return result;%0A    %7D//end public(key)
+/**%0A     * Obtain an instance of V based on the key K, creating one if its key isn't present in the currently-used map.%0A     * @param key%0A     * @return Instance of V created with the supplied adapter from K%0A     * @since Mar 27, 2015%0A     */%0A    public V get(K key)%7B%0A%09V result = mapToUse.get(key);%0A%09if(result==null)%0A%09    mapToUse.put(key, result=keyValueAdapter.adapt(key));%0A%09return result;%0A    %7D//end get(key)%0A    %0A    /**%0A     * Query the currently-used map for already-created object matching the given key.%0A     * @param key%0A     * @return Teh pre-created object, if any, or null if none exists.%0A     * @since Mar 27, 2015%0A     */%0A    public V peek(K key)%7B%0A%09return mapToUse.get(key);%0A    %7D//end peek(key)%0A    %0A    /**%0A     * Query the map being used to back this ObjectFactory's caching of already-created objects.%0A     * @return%0A     * @since Mar 27, 2015%0A     */%0A    public Map%3CK,V%3E getMap()%7B%0A%09return mapToUse;%0A    %7D
 %0A%7D//

Add peek() and javadocs to ObjectFactory.