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
Write a generic method that removes duplicate items from the supplied List.
For example:
List
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.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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started