gov.sandia.cognition.data.convert.AbstractReverseCachedDataConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gov-sandia-cognition-common-data Show documentation
Show all versions of gov-sandia-cognition-common-data Show documentation
General utility classes for processing data in the Cognitive Foundry.
/*
* File: AbstractReverseCachedDataConverter.java
* Authors: Justin Basilico
* Company: Sandia National Laboratories
* Project: Cognitive Foundry
*
* Copyright June 16, 2008, Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the U.S. Government. Export
* of this program may require a license from the United States Government.
* See CopyrightHistory.txt for complete details.
*
*/
package gov.sandia.cognition.data.convert;
/**
* Abstract implementation of {@code ReversibleDataConverter} that caches the
* reverse converter.
*
* @param
* The input type to convert from.
* @param
* The output type to convert to.
* @param
* The type of the reverse converter.
* @author Justin Basilico
* @since 3.0
*/
public abstract class AbstractReverseCachedDataConverter>
extends AbstractReversibleDataConverter
{
/** A cached value of the reverse converter. */
protected transient ReverseConverterType reverse;
/**
* Creates a new {@code AbstractReverseCachedDataConverter}.
*/
public AbstractReverseCachedDataConverter()
{
super();
// The cached reverse starts out as null.
this.reverse = null;
}
/**
* {@inheritDoc}
*
* @return {@inheritDoc}
*/
public ReverseConverterType reverse()
{
if (this.reverse == null)
{
// We have not cached the reverse converter, so cache it.
this.reverse = this.createReverse();
}
return this.reverse;
}
/**
* Creates a new reverse converter. Should only be called when there is a
* cache miss for this converter.
*
* @return The reverse converter.
*/
protected abstract ReverseConverterType createReverse();
}