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
1. 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 (i.e. BuiltInListProvider) is not compatible. So your first task is to implement an Adapter (call it BuiltInListProviderAdapter) to make it compatible to the ListProvider interface.
2. Your second task is to implement the Singleton repository for holding a list of ListProviders.
3. 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 (i.e. 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.sort(array, Collections.reverseOrder()) method of java.util.Collections package.
- For length-based sort you can use the Collections.sort(array, Comparator.comparingInt(String::length)) method of java.util.Collections package.
4. 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 4 sorted lists. The output should be something similar to the screenshot in Figure 1 below.
public static void sortLists(ListProviderRepoSingleton repository){
for(ListProvider lp : repository.getRepository())
for (SortStrategy sm : repository.getSortMethods()){
ArrayList str_List = lp.getStringList();
sm.Sort(str_List);
System.out.print(str_List +"
");
}
}
Figure 1 Sample screen shot of the output
Problem description: You are developing a simple

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!