forked from mitchfry/SpellChecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestList.java
More file actions
45 lines (38 loc) · 908 Bytes
/
TestList.java
File metadata and controls
45 lines (38 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.ArrayList;
/**
* This class is simply a ADT/Container wrapper that is setup to behave the way
* that student written containers should work.
*
* @author Mitch Fry
*
* @param <T>
* Parameterized type for the container
*/
@SuppressWarnings("serial")
public class TestList<T> extends ArrayList<T> implements CompareCount {
// ...Fields...
private int lastCompareCount = 0;
// ...Methods...
@Override
public int getLastCompareCount() {
return lastCompareCount;
}
// Override the contains to implement comparison counting
/*
* (non-Javadoc)
*
* @see java.util.ArrayList#contains(java.lang.Object)
*/
@Override
public boolean contains(Object obj) {
lastCompareCount = 0;
// Check each element in the list for a match
for (T element : this) {
lastCompareCount++;
if (element.equals(obj)) {
return true;
}
}
return false;
}
}