/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
interface ISort<String>
{
public void sort();
}
interface ISortIterator<String>
{
boolean hasNext();
ISort<String> getNext();
}
class ConcreteIterator<String> implements ISortIterator<String>
{
private List<ISort<String>> aList;
private int cursor;
ConcreteIterator(List<ISort<String>> al)
{
this.aList = al;
}
public boolean hasNext()
{
return this.cursor < this.aList.size() - 1;
}
public ISort<String> getNext()
{
cursor++;
return this.aList.get(cursor-1);
}
}
interface ITypeSort<String> extends ISort<String>
{
List<ISort<String>> getSortAlgorithms();
void sort();
void addSortAlgorithm(final ISort<String> aSortAlgorithm);
ISortIterator<String> getSortIterator();
}
abstract class AbstractSort<String> implements ISort<String>
{
public abstract void sort();
}
class TypeSort<String> extends AbstractSort<String> implements ITypeSort<String>
{
private final List<ISort<String>> listOfSortAlgorithms;
private final String typeName
;
public TypeSort
(final String aTypeName
) {
this.listOfSortAlgorithms = new ArrayList<ISort<String>>();
this.typeName = aTypeName;
}
public void addSortAlgorithm(final ISort<String> aSortAlgorithm)
{
this.listOfSortAlgorithms.add(aSortAlgorithm);
}
{
return this.typeName;
}
public void sort()
{
Iterator<ISort<String>> iterator = this.listOfSortAlgorithms.iterator();
List<String> sortedList = null;
while(iterator.hasNext())
{
final ISort<String> sortAlgorithm = (ISort<String>) iterator.next();
sortAlgorithm.sort();
}
}
public List<ISort<String>> getSortAlgorithms()
{
return this.listOfSortAlgorithms;
}
public ISortIterator<String> getSortIterator()
{
return new ConcreteIterator<String>(this.getSortAlgorithms());
}
}
class InsertionSort<String> extends AbstractSort<String> implements ISort<String>
{
public void sort()
{
System.
out.
println("Insertion Sort"); }
}
class BubbleSort<String> extends AbstractSort<String> implements ISort<String>
{
public void sort()
{
System.
out.
println("Bubble Sort"); }
}
class MergeSort<String> extends AbstractSort<String> implements ISort<String>
{
public void sort()
{
System.
out.
println("Merge Sort"); }
}
class Factory
{
private static Factory factory;
private Factory()
{
}
public static Factory getInstance()
{
if(factory == null)
{
System.
out.
println("----Factory Started----"); factory = new Factory();
}
return factory;
}
public ISort<String> getInsertionSortAlgorithm()
{
return new InsertionSort<String>();
}
public ISort<String> getBubbleSortAlgorithm()
{
return new BubbleSort<String>();
}
public ISort<String> getMergeSortAlgorithm()
{
return new MergeSort<String>();
}
public ISort<String> getInternalSortAlgorithm()
{
final ITypeSort<String> internalSorts = new TypeSort<String>("Internal Sorts");
internalSorts.addSortAlgorithm(this.getBubbleSortAlgorithm());
internalSorts.addSortAlgorithm(this.getInsertionSortAlgorithm());
internalSorts.addSortAlgorithm(this.getMergeSortAlgorithm());
return internalSorts;
}
}
class Ideone
{
{
ISort<String> isort = Factory.getInstance().getInsertionSortAlgorithm();
isort.sort();
ISort<String> isort1 = Factory.getInstance().getInternalSortAlgorithm();
isort1.sort();
final ITypeSort<String> ITS = (ITypeSort<String>) isort1;
ISortIterator<String> iterator = ITS.getSortIterator();
System.
out.
println(iterator.
hasNext()); }
}