Question: The Utilities class will contain two methods; removeDuplicates and linearSearch RemoveDuplicates public void removeDuplicates(final List items) Write a generic method that removes duplicate items from

The Utilities class will contain

two methods; removeDuplicates and linearSearch

RemoveDuplicates

public void removeDuplicates(final List items)

Write a generic method that removes duplicate items from the supplied List.

For example:

List strings = new ArrayList<>();

strings.add("one");

strings.add("two");

strings.add("one");

Utilities utilities = new Utilities();

utilities.removeDuplicates(strings);

The result is the list of strings contains two records; one and two.

List strings = new ArrayList<>();

strings.add("one");

strings.add("one");

strings.add("one");

Utilities utilities = new Utilities();

utilities.removeDuplicates(strings);

The result is the list of strings contains one record; one.

LinearSearch

Implement a generic method to do a linear search. Your linear search method should accept a

list containing a generic type, and a key record to search for in the generic list. Your search

should return the record associated with the supplied key or null if the key does not exist in the

supplied list.

public E linearSearch(List list, E key)

JUnit Tests

Write enough JUnit tests to achieve 100% test coverage and think carefully about your tests.

Along with showing that your generic methods work for different types of objects, i.e.

ArrayLists of Integers, Strings, FacebookUsers, etc., you should also test any unusual cases you

can think of:

What if the ArrayList is empty?

What if it contains only one item?

What if your removeDuplicates method is passed an ArrayList in which every item is

identical?

What if the arguments to the two methods are null?

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 Databases Questions!