I have a set class shown below that extends to my setinterface class which just has some basic methods(add, remove, contains, etc). In my set class, i use HashSet library to create my type T parameters.
Using a Junit test on my setclass, i immediately run into a problem with my add method. I realized that my set add method doesn't at all add the object into my hashset when called upon. So my question is how do i call on the add method in hashset in my set add method so i can add an object to my hashset?
When i run a debugger, it shows that 100 is not being added to my set object. My set object does not contain 100 and is still null.
public class Set<T> implements SetInterface<T>{
/*
* i used hashset library because one, it does not
* allow for duplicates, and 2 it allows my class to use
* iterator
*/
private HashSet<T> genericType;
public Set() {
}
public Set(HashSet<T> genericType) {
super();
this.genericType = genericType;
}
/**
* Add an item of type T to the interface Duplicate items will not be
* added to the set.
* @param itemToAdd - what to add.
*/
@Override
public void add(T itemToAdd) {
genericType.add(itemToAdd);
}
heres my junit test if anyone wants to see it
public class SetTest {
@Test
public void testSet() {
fail("Not yet implemented");
}
@Test
public void testAdd() {
Set<Integer> test = new Set<Integer>();
test.add(100);
assertTrue(test.contains(100));
}