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

gov.sandia.cognition.text.convert.SingleToMultiTextualConverterAdapter Maven / Gradle / Ivy

/*
 * File:                SingleToMultiTextualConverterAdapter.java
 * Authors:             Justin Basilico
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry Text Core
 * 
 * Copyright February 01, 2011, 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. 
 */

package gov.sandia.cognition.text.convert;

import gov.sandia.cognition.text.Textual;
import java.util.Collections;

/**
 * Adapts a {@code SingleTextualConverter} to work within the interface of an
 * {@code MultiTextualConverter}.
 *
 * @param   
 *      The type of input that can be converted to a textual form.
 * @param   
 *      The type of textual output of the converter. Must implement the
 *      {@code Textual} interface.
 * @author  Justin Basilico
 * @since   3.1
 */
public class SingleToMultiTextualConverterAdapter
    extends AbstractMultiTextualConverter
{

    /** The single text converter being wrapped. */
    protected SingleTextualConverter converter;

    /**
     * Creates a new {@code SingleToMultiTextualConverterAdapter} with no
     * internal converter.
     */
    public SingleToMultiTextualConverterAdapter()
    {
        this(null);
    }

    /**
     * Creates a new {@code SingleToMultiTextualConverterAdapter} with the given
     * internal converter.
     *
     * @param   converter
     *      The internal converter.
     */
    public SingleToMultiTextualConverterAdapter(
        final SingleTextualConverter converter)
    {
        super();

        this.setConverter(converter);
    }

    @Override
    public Iterable evaluate(
        final InputType input)
    {
        // Wrap the output as a singleton list.
        return Collections.singletonList(this.getConverter().evaluate(input));
    }

    /**
     * Gets the internal single textual converter being wrapped.
     *
     * @return
     *      The internal single textual converter.
     */
    public SingleTextualConverter getConverter()
    {
        return this.converter;
    }

    /**
     * Sets the internal single textual converter being wrapped.
     *
     * @param   converter
     *      The internal single textual converter.
     */
    public void setConverter(
        final SingleTextualConverter converter)
    {
        this.converter = converter;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy