Question: Problem description: You are developing a simple software for sorting different lists consisting of a sequence of strings. You would like to abstract the lists
Problem description: You are developing a simple software for sorting different lists consisting of a sequence of strings. You would like to abstract the lists via a ListProvider Interface. In other words all string lists must be contained in a class that implements a ListProvider interface. Your software must include a Singleton class that maintains a repository of ListProviders. In other words your Singleton class must have an attribute implemented as a List of ListProvider interface and must have a method that returns this repository. Your customer wants to be able to apply different sorting methods to these lists. Therefore, you decide to implement an extensible framework that uses the Strategy Design Pattern. As such, your software will include various sorting algorithms implemented as sort strategies. These sort strategies will also be added to your Singleton repository as a list of sorting methods. In other words your Singleton class must have an attribute implemented as a List of SortStrategy interface and must have a method that returns this method list. ArrayList
You are given Java definitions for SortStrategy and ListProvider interfaces below in the frame next page You are also given Java implementation for two different list containers: FileListProvider and BuiltInListProvider. The first one reads a list of strings from a text file a sample is provided with the name FileListProvider strings.txt in the relevant Teams folder and exposes it to its client via its getStringList method. This class is compatible with the standard list provider behaviour since it implements the ListProvider interface, so you can directly add any instance of it to your Singleton repository. However, the second class ie BuiltInListProvider is not compatible. So your first task is to implement an Adapter call it BuiltInListProviderAdapter to make it compatible to the ListProvider interface.
Your second task is to implement the Singleton repository for holding a list of ListProviders.
Your third task is to implement two separate classes for sorting any string list returned by a ListProvider. One of these classes name it DescendingSortStrategy will sort a given list of string in descending order. The second class name it LengthBasedSortStrategy will sort a given list of strings considering the length of strings in ascending order ie the string with the shortest length will be first, and the longest string will be the last
HINTS:
For descending sort you can use the Collections.sortarray Collections.reverseOrder method of java.util.Collections package.
For lengthbased sort you can use the Collections.sortarray Comparator.comparingIntString::length method of java.util.Collections package.
Your fourth task is to implement a main class your main test client which should include the sortLists function given below. In your main function you should create the necessary objects for list providers and sort strategies and add them to your Singleton repository. Then as the last step you should call the sortLists function given below to display sorted lists. The output should be something similar to the screenshot in Figure below.
public static void sortListsListProviderRepoSingleton repository
forListProvider lp : repository.getRepository
for SortStrategy sm : repository.getSortMethods
ArrayList strList lpgetStringList;
smSortstrList;
System.out.printstrList
;
Figure Sample screen shot of the output
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
