-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacterComparator.java
44 lines (40 loc) · 1.12 KB
/
CharacterComparator.java
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
import java.util.Comparator;
/**
* Comparator that allows for comparison of characters and
* counting said comparisons.
*
* This MUST BE USED for character comparisons. Using any other form of
* comparison for characters will result in test failures.
*
* DO NOT CREATE INSTANCES OF THIS CLASS
*
* DO NOT MODIFY THIS FILE!!
*
* @author CS 1332 TAs
* @version 1.0
*/
public class CharacterComparator implements Comparator<Character> {
private int comparisonCount;
/**
* To be used when comparing characters. Keeps count of
* how many times this method has been called.
*
* @param a First character to be compared.
* @param b Second character to be compared.
* @return Negative value if a is less than b, positive
* if a is greater than b, and 0 otherwise.
*/
@Override
public int compare(Character a, Character b) {
comparisonCount++;
return a - b;
}
/**
* Gets the number of times compare has been used.
*
* @return The comparison count.
*/
public int getComparisonCount() {
return comparisonCount;
}
}