/*::.
==================================================================================================================================
=================================================¦ Copyright © 2014 Allen Baker ¦=================================================
                                                 +------------------------------+
File:       TypeConverter.java
Originator: Allen Baker (2014.06.12 08:55)
LayoutRev:  5
================================================================================================================================== */



/*.
==========================================================================================
Package
------------------------------------------------------------------------------------------ */
package cosmicabyss.com.lib;



/*.
==========================================================================================
Imports
------------------------------------------------------------------------------------------ */
import java.io.*;
import java.util.*;
import java.net.*;



/*::
======================================================================================================================== *//**
Instances of classes that implement this interface can convert an Object from one type (or class) to another. This
interface is used to create delegate objects in support of implementing the delegation pattern.
   <BLOCKQUOTE>
      A delegate object encapsulates a reference to a method. The delegate object can then be passed to code which can
      call the referenced method, without having to know at compile time which method will be invoked.<P>

      Delegation is a design pattern where an object, instead of performing one of its stated tasks, delegates that task
      to an associated helper object. There is an inversion of responsibility in which a helper object, known as a
      delegate, is given the responsibility to execute a task for the delegator.
   </BLOCKQUOTE>

<P>
   <DL>
      <DT>
         <B>
            Example usage:
         </B>
         <DD>
            <BLOCKQUOTE>
               In this example, an ArrayList containing Strings is converted to an ArrayList containing XStrings.
                  <BLOCKQUOTE>
                     <PRE id="unindent">
                        =========================================================================================
                        A class with a method that needs to convert ArrayLists of Strings to ArrayLists of
                        XStrings.
                        -----------------------------------------------------------------------------------------
                        public class XString
                           {
                           public ArrayList<XString> makeXStringArrayList(ArrayList<String> pStringArrayList)
                              {
                              return ArrayListUtils.convertElements(pStringArrayList, new StringToStringConverter());
                              }
                           }
                        =========================================================================================
                        A class that implements the TypeConverter interface with a method that converts a String
                        to an XString.
                        -----------------------------------------------------------------------------------------
                        public class StringToXStringConverter implements TypeConverter<String, XString>
                           {
                           public XString convert(String pFrom)
                              {
                              return new XString(pFrom);
                              }
                           }
                        =========================================================================================
                        A class with a method to convert ArrayLists of one type to ArrayLists of another type and
                        delegates the task of converting the individual ArrayList elements to a TypeConverter.
                        -----------------------------------------------------------------------------------------
                        public class ArrayListUtils
                           {
                           public static <Type1, Type2> ArrayList<Type2> convertElements(ArrayList<Type1> pListOfType1, TypeConverter<Type1, Type2> pConverter)
                              {
                              ArrayList<Type2>  listOfType2 = new ArrayList<Type2>();
                              for (Type1  valueOfType1 : pListOfType1)
                                 {
                                 Type2  valueOfType2 = pConverter.convert(valueOfType1);
                                 listOfType2.add(valueOfType2);
                                 }
                              return listOfType2;
                              }
                           }
                     </PRE>
                  </BLOCKQUOTE>
            </BLOCKQUOTE>
         </DD>
      </DT>
      <DT>
         <B>
            View Source:
         </B>
         <DD>
            <A href="TypeConverter.java.html">
               TypeConverter.java
            </A>
         </DD>
      </DT>
      <DT>
         <B>
            Author:
         </B>
         <DD>
            <A href="mailto:sourcecode.v01@cosmicabyss.com">
               Allen Baker
            </A>
         </DD>
      </DT>
   </DL>
*//*
======================================================================================================================== */
public interface TypeConverter<Type1, Type2>
   {
   public Type2 convert(Type1 pFrom);
   }